# different labels for the same equation for choosing the appropriate one in different references

Suppose that I have an equation

a = b + c   (1.5)


in the chapter 2. Within the chapter 2 I would like to refer it as "equation (1.5)". But from other chapters I want to refer this equation differently, like "equation (2;1.5)".

Usually I write equations in the form

$$\label{1.5} a = b + c.$$


and at the point of reference write "\eqref{1.5}". But I cannot mark the same equation with two labels in order to choose the appropriate one in different references. How can I achieve that?

• I would rather suggest a) a better labeling scheme (other than 1.5) and b) using something that keeps the chapter information as well! – user31729 Feb 10 '17 at 17:25
• welcome to tex.sx. does this answer your question: Smartly omit chapter number in equation numbering? – barbara beeton Feb 10 '17 at 17:33
• it is best to never use numbers in \label as it is confusing for anyone looking at the source when those numbers are different from the printed number. – David Carlisle Feb 10 '17 at 17:34
• @Christian Hupfer, @David Carlisle, Yes, using numbers in \label is not a good solution, and I need time to time to perform a context replacement in order to keep those numbers equal to the printed ones. But when there are too many equations it becomes impossible to invent name for each one, and the only identity that I'm capable to remember about an equation is its number in specific section inside specific chapter. – Ilia Feb 10 '17 at 19:19
• Well then, use section and chapter names in the label as well. – Johannes_B Feb 11 '17 at 16:37

Don't use such label names like 1.5 they are error-prone because the equation number changes (this is exactly the point of having easy to remember names instead of numbers)

I am using zref to store the chapter as well and extract it afterwards with \moreref (as a wrapper to \zref@extract)

\eqref does not work with zref-labels, so either redefine \eqref or provide a wrapper as well.

\documentclass{book}

\usepackage{amsmath}

\numberwithin{equation}{section}
\renewcommand{\theequation}{\arabic{section}.\arabic{equation}}
\usepackage[user]{zref}

\makeatletter
\zref@newprop{chapter}{\thechapter}

\newcommand{\moreref}[1]{%
\zref@ifrefundefined{#1}{%
}{%
(equation \zref@extract{#1}{chapter},\zref{#1})%
}%
}

\newcommand{\zeqref}[1]{%
equation \zref{#1}%
}

\makeatother
\begin{document}

\chapter{Number One}
\chapter{Number Two}

\section{A section}
$$\zlabel{someequation} a = b + c.$$

In \moreref{someequation} or \zeqref{someequation}

\end{document}


Update with an ugly hack

Explanation: The \morelabel command sets two labels, a fake one and the real one.

Since equation (or rather: amsmath does not allow two labels inside of equation and redefines \label I used the outside label definition for the fake label, which is stored in \@currentlabel.

The \longref command extracts the more::#1 label then.

\documentclass{book}

\usepackage{amsmath}

\numberwithin{equation}{section}

\renewcommand{\theequation}{\arabic{section}.\arabic{equation}}

\makeatletter
\let\latex@@label\label

\newcommand{\morelabelformat}{%
(equation \thechapter,\theequation)%
}
\newcommand{\morelabel}[1]{%
\let\@oldcurrentlabel\@currentlabel%
\edef\@currentlabel{\morelabelformat}
\latex@@label{more::#1}%
\let\@currentlabel\@oldcurrentlabel
\label{#1}%
}

\newcommand{\longref}[1]{%
\@ifundefined{r@more::#1}{%
% Do nothing!
}{%
\ref{more::#1}%
}%
}
\makeatother

\begin{document}
\chapter{Number One}
\chapter{Number Two}

\section{A section}
$$\morelabel{someequation} a = b + c.$$

In \longref{someequation} or \eqref{someequation}

\end{document}


• It is a working solution for a complicated request. Otherwise you have to change your strategy – user31729 Feb 10 '17 at 18:54
• @Ilia - You seem to be under the impression that there must be simple solutions to not-so-simple requests. Why is that? – Mico Feb 10 '17 at 19:17
• @ilia - While on the subject of car-related figures of speech: Christian has handed you a key to a shiny new Porsche (or maybe a Mercedes -- both are made in the state he lives in...) Why not just say "thank you" and drive off into the sunset? :-) – Mico Feb 10 '17 at 21:06
• @Mico: :D :D :D Don't forget Audi ;-) – user31729 Feb 10 '17 at 21:10
• @Ilia Your question is not How to drive a car, your question is of an engineering type. You want a serious and complicated modification to the way your car works. In real live, you pay an engineer money to develop the modification and a mechanic money to install the modification. Here, you get help completely free of charge. The helpers pay your charge by investing their time. Remember, time is money ;-) – Johannes_B Feb 11 '17 at 16:50

I am sorry to say it, but the simplest solution for the situation as depicted in the question is: Do not just the labels by hand, do it for the references as well. In other words: Do not use the label-ref-mechanism at all.

Knuth has numbered stuff by hand as well.