Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I have some big equations that I wanted to separate out of the text of my document to make the source code easier to read. The idea was to declare a command for each equation in a separate file, include the file in the preamble of my document, and then just call the command for that equation in the appropriate place in the text. Here's a single-file example:

\documentclass{article}

\newcommand{\testCommand}{
    \begin{equation} \label{eq1}
        a = b + c
    \end{equation}
}

\begin{document}
    \testCommand
    \cite{eq1}
\end{document}

The problem with this is that I get undefined reference errors when I try to cite the equation. I'm assuming that the compiler must go through and find labels before it expands commands or something. Anyway, I was just wondering if there is a way to make this work. I would also appreciate some insight on what's going on under the hood that causes this to happen.

share|improve this question
    
Don't do this; say \newcommand{\myweirdeq}{a=b+c} and use \begin{equation}\label{eq1}\myweirdeq\end{equation}, so your document will be correctly marked up. –  egreg Jul 6 '12 at 7:56
add comment

1 Answer

up vote 3 down vote accepted

The way to cite a \label is with \ref; \cite is for bibliographies.

share|improve this answer
    
Wow, duh. Don't know why my mind randomly got set on \cite. I guess that's what happens when you haven't used LaTeX much for a while. Now I feel sheepish. =) Also, what's the appropriate thing to do with the question in this case? Should it be closed, deleted, or just left as it is? –  Brandon Jul 6 '12 at 3:19
    
@Brandon: No upside in deleting it. I am sure you are not the only one who will make this mistake. I have had a few embarrassing questions myself, so don't worry about it. –  Peter Grill Jul 6 '12 at 4:33
    
@Brandon: As further evidence that this question should stay: I have done this myself. A lot. –  Ryan Reich Jul 6 '12 at 5:54
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.