5

I would like to give one equation two separate labels; can I do this? The purpose of this is to have a long section in which I give a long list of equations, explaining them as I go along. I then de-dimentionalise them for which I will need to say something like 'de-dimentionalising equations (1) to (20) yields...'. Thus I need to be able to refer to label equation (1) twice, once as the first equation in the list and secondly as the equation I want to discuss. Of course I could give it only one label, but it would be convenient to give it two labels such that if I reorder/add in equations I can move the 'first equation' label, and then everything will still make sense.

As a concise example, what I want to do is

\begin{equation}
\label{first_equation} \label{special_equation}
a=b
\end{equation}

Edit: The above code does compile, but the inclusion of the amsmath package prevents it from doing so. Is there any way to use the features in this package and have the ability to multi-label?

  • 1
    Have you tried the code you posted? – Torbjørn T. Dec 5 '13 at 21:36
  • 1
    You can't have multiple \labels in an equation environment. Just use one. Alternatively, use a gather environment to typeset multiple equations in one fell swoop (you can use as many \labels as lines in that type of environment). If you're concerned about maintainabilty of your code (rearranging the order of your equations, etc.), I suggest you come up with some consistent naming scheme for your labels. For instance, a pair of related equations could be labelled continuity_eq and continuity_eq_nodim or something like that. No risk of getting the cross-references mixed-up then. – jub0bs Dec 5 '13 at 22:12
  • 2
    @Jubobs - One can in fact have more than one label per equation; try out the OP's example code (and create cross-references using the two labels) to verify this claim. It's just that all labels associated with a given equation will have the exact same number; hence it makes no real sense to provide more than one label per equation. By the way, I fully agree with your recommendation to develop a consistent naming system for the labels in one's document! – Mico Dec 5 '13 at 22:18
  • 1
    @Eddy -- Please post the equation that does give you problems with its labels. The equation that's up now doesn't throw problems. – Mico Dec 5 '13 at 22:20
  • 1
    @Mico You're right. I should have been more specific about having multiple labels in an equation. I should have written: it will do you no good to have more than one. – jub0bs Dec 5 '13 at 22:21
6

Yes. Putting several \labels on the same object just gives you different names for referring to it:

Sample output

\documentclass{article}

\begin{document}

\begin{equation}
  \label{eq:ab}\label{eq:equality}
  a = b.
\end{equation}
The relation between \( a \) and \( b \) is given by~(\ref{eq:ab}).
Using the equality~(\ref{eq:equality}), we see\dots

\end{document}

amsmath

As Mico correctly points out, this does not work if you load the amsmath package. His answer (https://tex.stackexchange.com/a/40185/15925) gives a way to define a new command \ltxlabel that will work fine in AmSmath equation environments. However, it fails in gather and friends. Here is one work around define a \clonelabel command that can be used outside the environment. Now updated to work with hyperref and further updated to work with cleveref:

Sample clone output

\documentclass{article}

\usepackage{amsmath}

\makeatletter
\newcommand{\clonelabel}[2]{\@bsphack
  \expandafter\ifx\csname r@#2\endcsname\relax
  \else\protected@write\@auxout{}{\string\newlabel{#1}%
    {\csname r@#2\endcsname}}%
  \fi
  \expandafter\ifx\csname r@#2@cref\endcsname\relax
  \else\protected@write\@auxout{}{\string\newlabel{#1@cref}%
    {\csname r@#2@cref\endcsname}}%
  \fi
  \@esphack}
\makeatother

\usepackage{hyperref}
\usepackage{cleveref}

\begin{document}

\begin{equation}
  \label{eq:equality}
  a = b.
\end{equation}\clonelabel{eq:ab}{eq:equality}
The relation between \( a \) and \( b \) is given by~\eqref{eq:ab}.
Using the equality~\eqref{eq:equality}, we see\dots

\begin{gather}
  \label{eq:inequality}
  p \ge q\\
  \label{eq:ratio}
  r/s = 20
\end{gather}
\clonelabel{eq:pq}{eq:inequality}
\clonelabel{eq:rs}{eq:ratio}
We refer to \eqref{eq:pq}, \eqref{eq:inequality}, \eqref{eq:rs} and
\eqref{eq:ratio}. 

We think \cref{eq:pq} is as interesting as \cref{eq:inequality}.

\end{document}
  • This works as long as the amsmath package isn't loaded. :-) – Mico Dec 6 '13 at 14:12
  • @Mico Ouch - that surprised me. Your work around at tex.stackexchange.com/a/40185/15925 is fine in this example, but fails in gather and friends when doing this on multiple lines. – Andrew Swann Dec 6 '13 at 14:26
  • Thanks for alerting me to this issue. Let me see how I may need to redo that answer. – Mico Dec 6 '13 at 14:47
  • @Mico See my update above. – Andrew Swann Dec 6 '13 at 15:05
  • Your \clonelabel macro is great! – Mico Dec 6 '13 at 15:15

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.