# Vertical spacing in mathtools

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}
$$\label{eq} a=b$$
This is an equation %\refeq{eq}
\end{document}


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

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}

• good point! That is reason, why in my document I usually use gather instead equation. – Zarko Jul 30 '15 at 19:40

The autonum package seems to be better at it:

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

\usepackage{lipsum} % for mock text

\begin{document}

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

\end{document}


use align instead of equation

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