# Ignoring redefined label

How can I make LaTeX ignore a \label that is re-used? That is, if I define a label twice, and then cross-reference it, I would like the reference to indicate the first definition of the label.

For example, in this MWE:

\begin{document}
$$x^2=2 \label{l1}$$
$$x^2=3 \label{l1}$$
See the equation in \eqref{l1}
\end{document}


Then I would like the sentence to read '... in (1)' and not '... in (2)'.

• You get a warning about a duplicate label. Why would you want the same label in two places? – egreg Nov 29 '15 at 19:04
• Why don't change it to l2 or foo? You have two different (however very simple equations in that example), so they should be labelled differently. The use of labels is to be unique! – user31729 Nov 29 '15 at 19:04
• You are both right, but I have some piece of latex code that copies replicates my text (for documentation purposes), and I would like only the first time to 'count'. – yoki Nov 29 '15 at 19:06

I don't understand how you would label different equations with the same \label. However, you have to redefine the way the check is performed during the reading of the .aux file in order to remove both the warnings and the redefinition of an already-used \label:

\documentclass{article}

\usepackage{amsmath}

\makeatletter
\def\@newl@bel#1#2#3{%
\@ifundefined{#1@#2}
{\global\@namedef{#1@#2}{#3}}
{\gdef\@multiplelabels{}}%
}
\makeatother

\begin{document}
$$x^2=2 \label{l1}$$
$$x^2=3 \label{l1}$$
See the equation in \eqref{l1}.
\end{document}