# Reduce space between equations and text

I am writing some sentences which contain numbered displayed equations in the middle, like this one:

|  Consider the relationship:      |
|      EQUATION                 (1)|
|where x is ... and y is ...       |
|                                  |
|  This is a new paragraph which   |
|ends with the following:          |
|      EQUATION                 (2)|
|                                  |
|  And this is the last paragraph, |
|followed by some equations which  |
|are not part of it.               |
|                                  |
|      EQUATIONS                (3)|
|                                  |
|  The end.                        |


This is the code, with empty line between paragraphs:

Consider the relationship:
$$...$$
where x is$$...$$and y is ...

This is a new paragraph which ends with the following:
$$...$$

And this is the last paragraph, followed by some equations which are not part of it.

$$...$$

The end.


I'd like to reduce the space between the equation and the text, but only in those cases in which the equation is in the middle of the sentence (note the vertical spacing and the paragraph indentations in the example above). Is there any way to do that, whitout changing global spacing like here?

The ideal solution would be something that recognize whether the equation is part or a paragraph or not (i.e. based on the blank lines between two paragraphs, like the indentation). Alternatively, a command to insert before, inside or before+after the equation (and gathered, align, ...) environments, or a new environment like \begin{NoSpaceEquation} ... \end{NoSpaceEquation}, is fine too.

I'm not looking for solutions like a global space reduction, which would need to manually add space before and after isolated equations. The solution should affects only the equations inside a paragraph.

PS: I am using mathtools.

Thank you!

• Just remove spaces before and after . – Roboticist Apr 24 '18 at 16:58
• @Roboticist that's exaclty what I've done in the paragraph "Consider the relationship...", at it does not work (if it does, the difference is quite minimal and the space is still too large) – Taekwondavide Apr 24 '18 at 17:16
• never leave a blank line before equation (that is not vertical space it is a spurious empty line of text) – David Carlisle Apr 24 '18 at 17:22
• @DavidCarlisle isn't that like, semantically speaking, putting the equation in a separate paragraph? I mean, something like: Text: \\ Equation (no blank line) vs. Text. \par Eqation (blank line) – Taekwondavide Apr 24 '18 at 17:36
• never use either \\  or a blank line (or \par) before a math display, TeX simply does not support that. – David Carlisle Apr 24 '18 at 18:35

You can use the \useshortskip command from nccmath (just before the equation) or \SwapAboveDisplaySkip (at the very beginning of an amsmath environment):

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{mathtools, nccmath}

\begin{document}

In the first place, consider the relationship:
$$\textit{A first equation}$$
where x is ... and y is ...

This is a new paragraph which ends with the following equation:\useshortskip
$$\textit{Another equation}$$

This is another paragraph which ends with an AmSmath environment:
\begin{gather}\SwapAboveDisplaySkip$$\textit{Another equation}$$\end{gather}

And this is the last paragraph, followed by some equations which are not part of it.

$$\textit{Still another equation}.$$

The end.

\end{document}


To reduce the spacing above and below an equation, we can patch an internal command of nccmath, but the following text must not start a new paragraph:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{mathtools, nccmath}

\usepackage{xpatch}
\xpatchcmd{\NCC@ignorepar}{%
\abovedisplayskip\abovedisplayshortskip}
{%
\abovedisplayskip\abovedisplayshortskip%
\belowdisplayskip\belowdisplayshortskip}
{}{}

\begin{document}

In the first place, consider the relationship:
$$\textit{A first equation}$$
where x is ... and y is ...

This is a new paragraph which ends with the following equation:\useshortskip
$$\textit{Another equation}\text{(spacing with \texttt{\textbackslash useshortskips})}$$

And this is the last paragraph, followed by some equations which are not part of it.

$$\textit{Still another equation}.$$

The end of this very exhaustive test.

\end{document}


• Thank you! Unfortunately \SwapAboveDisplaySkip gives me a lot of errors (maybe for some reasons like this, I use a lot of packages). I tried \useshortskip but it only reduces the space before, even if I put it after . Is there any solution for the space after? – Taekwondavide Apr 24 '18 at 17:29
• @Taekwondavide: I've posted a solution with a patch of nccmath . Is it more like what you want? – Bernard Apr 24 '18 at 19:12
• it's not clear to me how the patch work. Does it affect any equation or the ones with \SwapAboveDisplaySkip? Anyway I added the patch to my preamble and I don't notice significant changes. With reference to both of your screenshots, what I need is to have in the first paragraph "In the first place..." to have before and after eqn (1) the same space that there is before eqn (2), but \useshortskips only works with the space before – Taekwondavide Apr 26 '18 at 15:05
• Sorry, I made a mistake, now I can see the space reduction below, anyway the space below is still larger than the space above. Is there any way to have (almost) the same reduced space above and below? – Taekwondavide Apr 26 '18 at 15:47
• In the patche (which is only for \useshortskip, you can replace \belowdisplayskip\belowdisplayshortskip with, say, \belowdisplayskip 0.5\belowdisplayshortskip, or even\belowdisplayskip\z@skip, for instance, but I find it's too tight. It's also a semantic question: is what follows the continuation of the equation or not? – Bernard Apr 26 '18 at 15:59