I have theorems which LaTeX numbers and then some equations inside and outside theorems that LateX has numbered.

When I refer to an equation inside a theorem statement then LaTeX is referring to it by the theorem's number and not the equation's number.

Blah is 

From equation ~\ref{eq:Blah} we know blah blah blah.

Suppose the proposition number is 4.1 and the equation number is 12 then my text catches 4.1 and not 12. I don't particularly care which number is catches, so long as it is consistent. So that someone reading the text can find what I am referring to.

How can I fix this?

  • 2
    I think this comes down to where you are putting your \label; in your example the reference works as expected... Presumably this is a stripped-down version of the actual problem?
    – cmhughes
    Nov 23, 2012 at 21:43
  • By the way, if you put a real space in front of an unbreakable space ~, what you get is a regular breakable space.
    – T. Verron
    Nov 23, 2012 at 22:45
  • Please clarify if my comment is correct, and update your question with a MWE that demonstrates the problem
    – cmhughes
    Nov 24, 2012 at 0:36

1 Answer 1


Generating correct labels for referencing forms part of a two-step process:

  1. A counter is increased using \refstepcounter (a "referencable" form of counter incrementation). This typically happens when you call a macro (like \section) or environment. Here's a snapshot of \refstepcounter from latex.ltx:

           {\csname p@#1\endcsname\csname the#1\endcsname}%

    See that \refstepcounter is a "modified \stepcounter", since it also updates \@currentlabel.

  2. When inserting a \label, the default behaviour of LaTeX is to write the macro \@currentlabel and \thepage to the .aux file as arguments to \newlabel. Here's a snapshot of \label from latex.ltx:


    Generally speaking, \newlabel here is just a mechanism built in to check whether a label already exists/not and warn you thereof (in the form of "There were multiply-defined labels" or "Label `...' multiply defined").

So, whenever a \refstepcounter is performed, \@currentlabel is updated and therefore would change any reference created with a \label. The most commonly identified problem of this incorrect labelling is when users perform (say)

  % Image stuff here
  \caption{My caption}

and receive an incorrect reference to their figure. This is because \caption executes \refstepcounter and not the figure environment itself, resulting in an incorrect \@currentlabel to be written to the .aux file (whatever that may be). A practical example:

enter image description here

\section{A section}
See Figure~\ref{fig:ref} in section~\ref{sec:ref}.
\section{A section} Here is some text. \label{sec:ref}
  \label{fig:ref}\caption{A figure caption}

Note how the figure reference \ref{fig:ref} returns 2 instead of 1. That's because an issue of \label{fig:ref} write \@currentlabel which is still set to 2 by the preceding \section. Switching around \label and \caption would yield the desired result (however simplistic).

Bottom line is that there's an appropriate placement of \label with respect to counters, otherwise references might be incorrect. The emphasis here denotes the fact that some environments gather content a post-process them, possibly correcting for inappropriate placements of things like \label.

You must log in to answer this question.

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