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:




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


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


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


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

It is recommended to use


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:

\def\MT_extended_eqref:n #1{
  \textup{\let\df@label\@empty\MT_prev_tagform:n {\ref{#1}}}

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.