8

When using mathtools with the option showonlyrefs I find a spurious vertical spacing. I have found a similar question but the issue there was a long equation, which is not my case. Consider the MWE

\documentclass{minimal}
\usepackage{mathtools}
\mathtoolsset{showonlyrefs}
\begin{document}
\begin{equation}
\label{eq}
a=b
\end{equation}
This is an equation %\refeq{eq}
\end{document}

If one uncomments \refeq, the vertical space after the equation is reduced. Any ideas?

2
1

Until mathtools version 1.23 is released, here is a patch that fixes the issue

The tag needs to always have a non-zero width or else equation may add a blank line. But the processing branch for showonlyref did not cover all cases

\usepackage{xpatch}

\MHInternalSyntaxOn

\xpatchcmd{\MT_extended_tagform:n}{
  \@ifundefined{MT_r_\df@label}{}
}{%
 \@ifundefined{MT_r_\df@label}{\kern1sp}
}{}{\typeout{patch failed}}

\xpatchcmd{\MT_extended_tagform:n}{
\@ifundefined{MT_r_\df@label}{\global\MH_set_boolean_F:n {manual_tag}}
}{%
\@ifundefined{MT_r_\df@label}{\global\MH_set_boolean_F:n {manual_tag}\kern1sp}
}{}{\typeout{patch failed}}

\MHInternalSyntaxOff
2
  • Had to wait five years but it was worth it :-)
    – campa
    Jan 17 '20 at 10:11
  • @campa I don't think I ever saw your question
    – daleif
    Jan 17 '20 at 10:16
3

This is probably a `feature' of the problematic equation environment (see various posts on this site). It disappears in the following example.

\documentclass{minimal}
\usepackage{mathtools}
\mathtoolsset{showonlyrefs}
\begin{document}
\begin{gather}
\label{eq}
a=b
\end{gather}
This is an equation %\refeq{eq}
\end{document}
1
  • 1
    good point! That is reason, why in my document I usually use gather instead equation.
    – Zarko
    Jul 30 '15 at 19:40
3

The autonum package seems to be better at it:

\documentclass{article}
\usepackage{amsmath}
\usepackage{autonum}

\usepackage{lipsum} % for mock text

\begin{document}

\lipsum*[2]
\begin{equation}
\label{eq1}
a=b
\end{equation}
This is an equation \eqref{eq1}.
\lipsum*[2]
\begin{equation}
\label{eq2}
a=b
\end{equation}
\lipsum[2]

\end{document}

enter image description here

1

use align instead of equation

\begin{align}\label{eq}
    a &= b
\end{align}
This is an equation \refeq{eq}

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.