6

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?

Eddy
  • 291
  • Welcome to TeX.SX! A tip: If you indent lines by 4 spaces, they'll be marked as a code sample. You can also highlight the code and click the "code" button (with "{}" on it). – jub0bs Dec 05 '13 at 21:23
  • 1
    Have you tried the code you posted? – Torbjørn T. Dec 05 '13 at 21:36
  • @TorbjørnT. I have tried something very similar, it just throws up errors – Eddy Dec 05 '13 at 22:00
  • 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 05 '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 05 '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 05 '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 05 '13 at 22:21
  • 1
    @Jubobs - We're in full agreement then! :-) – Mico Dec 05 '13 at 22:22
  • 1
    @Mico The purpose of giving it two names is to be able to reference it for two different properties 1) the fact that the equation is the Darcy equation and 2) that it is the first in a long list to be put into dimensionless parameters. Thus one label will be for each purpose, and I wish to be able to move equations/labels around such that one label has one purpose and the other has the other. Thus giving them sensible names is EXACTLY my aim. If the amsmath package is used then multi-labels don't work, I'll update the question – Eddy Dec 06 '13 at 13:47
  • @Jubobs see above – Eddy Dec 06 '13 at 13:50
  • @Eddy - I must confess I still don't understand why you would want to assign more than one label per equation being cross-referenced. Some equation having two separate properties does not, AFAICT, create a need to assign two different labels. – Mico Dec 06 '13 at 14:14
  • If you want sequential numbering, I don't see multiple labels being of use, but I suspect there might be something along the lines of align that could work - the Wikibook is great: http://en.wikibooks.org/wiki/LaTeX/Advanced_Mathematics – DetlevCM Dec 06 '13 at 14:33

1 Answers1

7

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}
Moriambar
  • 11,466
Andrew Swann
  • 95,762