8

I'm using the stackrel command to indicate important steps in the transformation of formulas. E.g. I would write: A\stackrel{(!)}{=}B so that I can later explain in text why exactly A equals B.

I've written a command \refeq{foo} now that will do this for me. So that I can use \eqqref{foo} later in text and it will automatically show the right number for the right equals sing in text (same as using \label{foo} and ref{foo}).

I only have one problem: when I have an equation that I want to label; and within this equation is also an equals sign that I want to reference to, I get the error

Package amsmath Error: Multiple \label's: label 'rom' will be lost.

what should I do to overcome this? I want to be able to ref to an equation and to any equals sign inside this equation.

Here's my working copy:

\documentclass{article}

\usepackage{hyperref}
\usepackage{amsmath}

\def\clap#1{\hbox to 0pt{\hss#1\hss}}
\def\mathllap{\mathpalette\mathllapinternal} \def\mathrlap{\mathpalette\mathrlapinternal} \def\mathclap{\mathpalette\mathclapinternal}
\def\mathllapinternal#1#2{\llap{$\mathsurround=0pt#1{#2}$}}
\def\mathrlapinternal#1#2{\rlap{$\mathsurround=0pt#1{#2}$}}
\def\mathclapinternal#1#2{\clap{$\mathsurround=0pt#1{#2}$}}

\newcounter{qc}
\setcounter{qc}{2}
\usepackage{refcount,makerobust}

\newcommand{\refeq}[1]{%
 \refstepcounter{qc}\label{#1}%
 \stackrel{
  \stackrel{
   {\text{\tiny $\mathclap{\roman{qc}}$}}
  }{\text{$\downarrow$}}
 }{=}%
}


\newcounter{refeqc}
\setcounter{refeqc}{0}

\newcommand{\eqqref}[1]{%
 \setcounterref{refeqc}{#1}%
 $(\roman{refeqc})$
}


\begin{document}



\begin{equation}A\refeq{AB}B\label{romeo} \end{equation}
\begin{equation}R=B\refeq{BC} C\end{equation}

\eqqref{AB} in equation \ref{romeo} is the same as \eqqref{BC}

\end{document}

Any help on what to do would be great!

I've tried using protect and mbox, but nothing works!

8

I've tried using protect and mbox, but nothing works!

Neither will help because they have nothing to do with the references.

The mathmode \label in your document is defined in the following way (most likely by amsmath):

\ifx \df@label \@empty \else \@amsmath@err {Multiple \string \label 's: label
 '\df@label ' will be lost}\@eha \fi \gdef \df@label

i.e., it simply stores the label in \df@label but checks first if it is still empty. Then later, at the end of the equation, it is finally used.

What you need for your extra labels is IMHO the textmode \label. The following code seems to work. Note that I saved away the \label to \textlabel and use a group to keep the change to \@currentlabel local. (Do not use { } or \bgroup \egroup for this because they create a new math atom in mathmode.) Without the group both actually independent labels will interact which each other, i.e. in your example the romeo label will be also have the number 3, not 1.

\let\textlabel\label
\newcommand{\refeq}[1]{%
 \begingroup
 \refstepcounter{qc}\textlabel{#1}%
 \stackrel{
  \stackrel{
   {\text{\tiny $\mathclap{\roman{qc}}$}}
  }{\text{$\downarrow$}}
 }{=}%
 \endgroup
}

Just replace your definition of \refeq with this one. You might also have a look on \hyperlink and \hypertarget (IIRC) to manually add hyperlinks.

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.