8

I like very much the mathtools option showonlyrefs which allows that labels of an equation are displayed only, if there is a reference to the equation. The problem is, that references in an equation are supressed, if the equation has a label that is never referred. The following MWE is more understandable:

\documentclass{article}

\usepackage{mathtools}
\mathtoolsset{showonlyrefs}

\begin{document}

CASE A: equation with reference has no label
\begin{equation}
    1 = 1 \label{eq1a}
\end{equation}
\begin{equation} 
    1 = 1 \qquad \text{(see \eqref{eq1a})}
\end{equation}

\hrulefill

CASE B: equation with reference has label and is referenced itself \eqref{eq2b}
\begin{equation}
    1 = 1 \label{eq1b}
\end{equation}
\begin{equation} \label{eq2b}
    1 = 1 \qquad \text{(see \eqref{eq1b})}
\end{equation}

\hrulefill

CASE C: equation with reference has label but is not referenced itself
\begin{equation}
    1 = 1 \label{eq1c}
\end{equation}
\begin{equation} \label{eq2c}
    1 = 1 \qquad \text{(see \eqref{eq1c})}
\end{equation}

\end{document}

Which produces (after enough compilation runs)

output of mwe

Case A and B behave like expected, in case C however there is no reference (4).

While it is easy to find a workaround (just delete the label) if there is no reference to the equation, I would prefer to have a automatic solution.

  • Even though the name invites you to do so, don't use minimal for minimal examples. – Johannes_B Mar 31 '15 at 15:59
  • 1
    @Johannes_B Thanks for the hint, with article the problem is the same, I will update the MWE – crixstox Mar 31 '15 at 16:01
  • 1
    i tried it with amsart both with multiple equations and with gather. all with the same result. looks like a bug to me. – barbara beeton Mar 31 '15 at 16:46
  • @barbarabeeton OK, I will write a bug report to the maintainer of the mathtools package. – crixstox Mar 31 '15 at 17:20
  • @barbarabeeton, see my answer below. If interested the problem tracks down to \MT_extended_maketag:n. – daleif Apr 13 '15 at 10:53
6

It is recommended to use

\mathtoolsset{showonlyrefs,showmanualtags}

whenever you use showonlyrefs

I'm not quite sure what the best solution is to avoid having to add showmanualtags (the original author always recommended using both).


The problem here ends up in the internal logic. The showonlyrefs feature hooks into the typesetting of the equation number. This is used in two places:

  1. typesetting the equation number in the displayed math, and
  2. in \eqref

The problem here is that \eqref is actually being used inside a displayed math env, and thus ends up testing against the env label and not the given label.

Issuing showmanualtags circumvents this.


An even better solution might be to simply patch the \eqref version being used when showonlyrefs is active, using this:

\MHInternalSyntaxOn
\def\MT_extended_eqref:n #1{
  \protected@write\@auxout{}
  {\string\MT@newlabel{#1}}
  \textup{\let\df@label\@empty\MT_prev_tagform:n {\ref{#1}}}
}
\MHInternalSyntaxOff

The trick is the emptying of \df@label when ever the tagform is being used in a \eqref context.

I think I'll add this to the next mathtools release.

|improve this answer|||||

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.