1

I'd like to write something as

\begin{align}
f(x) & = x + 1 \nonumber \\
& =: \eqref{eq:foo} \label{eq:foo} \nonumber \\
g(x) & = x + 2 \nonumber \\
& =: \eqref{eq:bar} \label{eq:bar} \nonumber
\end{align}

but amsmath does not allow me to do it:

! Package amsmath Error: Multiple \label's: label 'eq:foo' will be lost.See the amsmath package documentation for explanation.Type H for immediate help....

So what shall I do to solve this problem?

Interestingly

\begin{align}
f(x) & = x + 1 \nonumber \\
& =: \eqref{eq:foo} \label{eq:foo} \nonumber
\end{align}

is accepted by LaTeX, but the reference always stays a (??), even if I run LaTeX multiple times.

4
  • Can you explain what you are trying to achieve here? As it stands, amsmath rejects your code because it doesn't make sense! Feb 27, 2015 at 9:42
  • If you have \label{...} you must either have \tag or not have \nonumber. What should \eqref{eq:foo} refer to, otherwise?
    – egreg
    Feb 27, 2015 at 9:42
  • @Ian Thompson What I want to achiveve here, should be clear: don't show an equation number (\nonumber), but assign one (\label) and show it at another place (\eqref).
    – Nubok
    Feb 27, 2015 at 9:48
  • 1
    It's always best to give an explanation; guessing the intended purpose of incorrect code is difficult at the best of times. Feb 27, 2015 at 20:02

1 Answer 1

2

I find doing this quite disputable. Anyway, here it is:

\documentclass{article}
\usepackage{amsmath}

\makeatletter
\let\latexlabel\ltx@label
\makeatother
\newcommand{\assignnumber}[1]{%
  \refstepcounter{equation}\latexlabel{#1}\eqref{#1}%
}

\begin{document}
Here's a normal equation
\begin{equation}
0=0
\end{equation}
and now the thing you want
\begin{align*}
f(x) & = x + 1 \\
& =: \assignnumber{eq:foo} \\
g(x) & = x + 2  \\
& =: \assignnumber{eq:bar}
\end{align*}
with another equation to check the assigned numbers are correct
\begin{equation}
1=1
\end{equation}
with references to \eqref{eq:foo} and \eqref{eq:bar}.

\end{document}

The bulk is to override the amsmath way of assigning numbers and labels.

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .