In my work as LaTeX typesetter I often deal with multiply defined labels warnings. Most of them are about equations.

My question is, do the \ref command "always" refer to the last labelled item? In my experience it is so, but I'd like to know if there are cases (e.g. settings o packages) in which this is not true.

E.g. if I have:




1 +1 =3
2 +2 =5


both refs refers to the last equation.

Note. We always ask the author(s) to check about the warning but my company policy is to remove the warning "before" sending the proofs. I'm searching for a "scripting" way to manage these cases, commenting all the multiply defined labels except for the last one, yet I need to know if this is a safe approach.

  • The \ref{somelabel} command refers to a counter labelled somelabel. So if you have this message, it means you have some equations with the same label. B.t.w., for equations, you should use \eqef if you want to have the parentheses around the equation number.
    – Bernard
    Jul 2, 2017 at 14:42
  • 2
    If one of the label is referenced you can't know which one the author meant. As a typesetter you really shouldn't delete one of the \labels. Make a clear note and let the author sort this out. Jul 2, 2017 at 15:15
  • I'm not the guy that makes the rules in my company and, yes, we always ask the authors to check. (See the comment to egreg answer). Jul 2, 2017 at 15:21

1 Answer 1


If you look at the .aux file, then you see

\@writefile{toc}{\contentsline {section}{\numberline {1}Introduction}{1}}

As part of \begin{document}, LaTeX reads the .aux file (as produced in the previous run) and the command \newlabel{eq1}{{1}{1}} essentially does


which is then overridden by the later


with the effect that \ref{eq1} will point to equation 2, because \ref{eq1} checks for the macro \r@eq1 (produced with \csname, so numbers are legal in it) to be defined and, in case, it uses the contents in the first brace pair from its replacement text (\pageref uses the second).

When \end{document} is processed, the .aux file produced in the current run is read in, but \newlabel does different things, among which checking whether the label has already appeared.

The solution is very simple: never duplicate labels. In case there are, you need to ask the author to fix them. Using the last one may not be the author’s intention.

  • I agree with you about "never duplicate labels", but I'm only a typesetter, not the author of the papers I work on. I know about the .aux file stuff but I need to know if some package or some sort of "break-command" within the document can change this behaviour. Jul 2, 2017 at 14:52
  • @GabrieleNicolardi In my experience, duplicate labels usually stem from authors using a “template” or editor macros that automatically provide a \label. If the argument to \newlabel is clearly a dummy (empty, a bullet or whatnot), you can safely ignore it. Otherwise you, as the typesetter, cannot guess.
    – egreg
    Jul 2, 2017 at 15:03
  • In my experience often this happens when authors copy and paste an equation. Let me explain. Of course we always ask a final check to the authors, but this is a "minor issue" and we can publish the paper in case we do not receive an answer. The guidelines tell me to refer to the received .pdf copy of the manuscript. I'm trying to understand if it is really necessary to look at this pdf or if I can safely keep the last \label command. Jul 2, 2017 at 15:17
  • 1
    @GabrieleNicolardi No, you can't, in my opinion.
    – egreg
    Jul 2, 2017 at 15:22
  • 1
    @GabrieleNicolardi There is code on the site attempting at allowing duplicate labels (with different references, of course), but in this case the warning should not appear.
    – egreg
    Jul 4, 2017 at 6:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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