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?

campa
  • 31,130

4 Answers4

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}
JPi
  • 13,595
  • 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

egreg
  • 1,121,712
1

use align instead of equation

\begin{align}\label{eq}
    a &= b
\end{align}
This is an equation \refeq{eq}
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
daleif
  • 54,450