7 Cross references

We often want something like ‘See Theorem~31’. But by-hand typing the 31 is poor practice. Instead you should write a label such as \label{eq:GreensThm} and then reference it, as with See equation~\ref{eq:GreensThm}. LaTeX will automatically work out the number, put it into the output, and will change that number later if needed.

We will see this with Theorem~\ref{th:GreensThm}. % forward reference
...
\begin{theorem} \label{th:GreensThm}
  ...
\end{theorem}
...
See Theorem~\ref{th:GreensThm} on page~\pageref{th:GreensThm}.

LaTeX tracks cross reference information in a file having the extension .aux and with the same base name as the file containing the \label. So if \label is in calculus.tex then the information is in calculus.aux. LaTeX puts the information in that file every time it runs across a \label.

The behavior described in the prior paragraph results in a quirk that happens when your document has a forward reference, a \ref that appears before the associated \label. If this is the first time that you are compiling the document then you will get ‘LaTeX Warning: Label(s) may have changed. Rerun to get cross references right’ and in the output the forward reference will appear as two question marks ‘??’, in boldface. A similar thing happens if you change some things so the references changes; you get the same warning and the output contains the old reference information. In both cases, resolve this by compiling the document a second time.

The cleveref package enhances LaTeX’s cross referencing features. You can arrange that if you enter \begin{thm}\label{th:Nerode}...\end{thm} then \cref{th:Nerode} will output ‘Theorem 3.21’, without you having to enter the “Theorem.”


Unofficial LaTeX2e reference manual