# Single-spaced equations in double-spaced documents

My university guidelines (unfortunately) mandate double-spacing. However, nothing is said about double-spacing equations, so I'd like to print equations single-spaced. Easy enough:

\documentclass{article}

\usepackage{lipsum}
\usepackage{amsmath}
\usepackage{fontspec}
\usepackage[doublespacing,nodisplayskipstretch]{setspace}

\usepackage{etoolbox}
\BeforeBeginEnvironment{align*}{\begin{singlespace}}
\AfterEndEnvironment{align*}{\end{singlespace}\noindent\ignorespaces}

\begin{document}

\lipsum*[2]
\begin{align*}
Abc = DEF\\
DEF = Abc
\end{align*}
\lipsum[2]

\end{document}


This is inspired by @GonzaloMedina's answer on Equations and Double Spacing. Unfortunately, it doesn't work:

The problem is that the space before the equation is greater than the space after it. What gives?

singlespace starts a new \par. Add a negative \baselineskip:

\documentclass{article}

\usepackage{lipsum}
\usepackage{amsmath}
\usepackage{fontspec}
\usepackage[doublespacing,nodisplayskipstretch]{setspace}

\usepackage{etoolbox}
\BeforeBeginEnvironment{align*}{\begin{singlespace}\vspace*{-\baselineskip}}
\AfterEndEnvironment{align*}{\end{singlespace}\noindent\ignorespaces}

\begin{document}

\lipsum*[2]
\begin{align*}
Abc = DEF \\
DEF = Abc
\end{align*}
\lipsum[2]

\end{document}


• Thanks! Surprisingly, however, this breaks $ $... That is, if I add the same code for equation*, then the spacing above \[ is wrong. – Clément Aug 9 '16 at 22:24
• More precisely, the singlespace environment terminates the current paragraph, if any, and forces vertical mode. It is the displayed equation that, at this point, begins a new (partial) paragraph, consisting of a single line that contains only the indentation box. See The TeXbook, answer to Exercise 14.30, on p. 316, last three lines. – GuM Aug 9 '16 at 22:30

Here is a patch that works in the same way in align*, gather*, and equation*. For detailed explanations, see The TeXbook, pages 188–189; here suffice it to say that the different behavior doesn’t arise from the vertical backspace, but from the choice of \abovedisplayskip versus \abovedisplayshortskip. I apologize in advance for my inclination to prefer raw TeX primitives over higher level constructs…

\documentclass[a4paper]{article}

\usepackage{lipsum}
\usepackage{amsmath}
\usepackage[doublespacing,nodisplayskipstretch]{setspace}
\usepackage{etoolbox}

\makeatletter

\newcommand*\MySingleSpacePatch{%
\begin{singlespace}%
\vskip -\baselineskip
\noindent
\dimen@ \hsize
\hskip \dimen@ \@minus \tw@\p@ % 2pt and not 1pt because I am paranoid
\null
}
\newcommand*\EndMySingleSpacePatch{%
\end{singlespace}%
\noindent\ignorespaces
}

\makeatother

\BeforeBeginEnvironment{equation*}{\MySingleSpacePatch}
\AfterEndEnvironment{equation*}{\EndMySingleSpacePatch}
\BeforeBeginEnvironment{gather*}{\MySingleSpacePatch}
\AfterEndEnvironment{gather*}{\EndMySingleSpacePatch}
\BeforeBeginEnvironment{align*}{\MySingleSpacePatch}
\AfterEndEnvironment{align*}{\EndMySingleSpacePatch}

\begin{document}

\lipsum*[2]
\begin{align*}
x&=y+1 \\
a&=b
\end{align*}
\lipsum*[4]

\lipsum*[2]
\begin{gather*}
x=y \\
a=b
\end{gather*}
\lipsum*[4]

\lipsum*[2]
\begin{equation*}
DEF = Abc
\end{equation*}
\lipsum*[4]