3

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.

1
  • 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, 2012 at 7:56

1 Answer 1

3

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

3
  • 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, 2012 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. Jul 6, 2012 at 4:33
  • @Brandon: As further evidence that this question should stay: I have done this myself. A lot.
    – Ryan Reich
    Jul 6, 2012 at 5:54

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .