0

I need to get better control on the abovedisplayshortskip when the last text line is shorter than the equation below it. My current solution is an hack and is ackward to use. See for example the MWE example below and its preview picture:

\documentclass[11pt,letterpaper,twoside]{book}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[french]{babel}
\usepackage[nomath]{lmodern}
\usepackage[total={6in,10in},left=1.5in,top=0.5in,includehead,includefoot,showframe]{geometry}
\usepackage[nodisplayskipstretch]{setspace}
\setstretch{1.1}
\raggedbottom
\usepackage{microtype}
\usepackage{nccmath,amsmath}
\usepackage{amsfonts}
\usepackage{mathtools}
\usepackage{tensor}
\newcommand*{\topless}{\vspace{\glueexpr\abovedisplayshortskip-\abovedisplayskip}}

\begin{document}

\setlength{\abovedisplayskip}{2ex}
\setlength{\abovedisplayshortskip}{0pt}
\setlength{\belowdisplayskip}{\abovedisplayskip}
\setlength{\belowdisplayshortskip}{\belowdisplayskip}
\setlength{\jot}{3ex}

\noindent
This is just a test, to see what will happen next and the equation below this dummy text sample:
\begin{align}
    y^2 + x^2 - z^2 = 1
\end{align}
This is just a test, to see what will happen next and the equation below this dummy text sample:
\topless
\begin{align}
    y^2 + x^2 - z^2 = 1
\end{align}
This is just a test, to see what will happen next and the equation below this dummy text sample:
\begin{equation}
    y^2 + x^2 - z^2 = 1
\end{equation}
This is just a test, to see what will happen next and the equation below this dummy text sample which has no meaning:
\begin{equation}
    y^2 + x^2 - z^2 = 1
\end{equation}
This is just a test, to see what will happen next and the equation below this dummy text sample which has no meaning at:
\begin{equation}
    y^2 + x^2 - z^2 = 1
\end{equation}
This is just a test, to see what will happen next and the equation below this dummy text sample which has no meaning at:
\topless
\begin{equation}
    y^2 + x^2 - z^2 = 1
\end{equation}
This is just a test, to see what will happen next and the equation below this dummy text sample:
\begin{gather}
    y^2 + x^2 - z^2 = 1
\end{gather}

\end{document}

Preview showing the problem in red: enter image description here

Currently, I could reduce the vertical space of equations (1), (5) and (7) by using the macro that I called \topless, but this is really ackward since I need to predict the spacing problem. I could use that command only after a first compilation, and it's not very reliable (especially if I need to change the text or font size, for example).

I need an automatic solution, at the preamble level, for any environment (equation, align, gather, etc).

As you can see on the preview, the equation environment has a better tolerance to the displayshortskip minimal limit (see (3), (4), and (5). The overlap limit is small), while the align and gather environments have a much lower tolerance (the overlap limit is pretty large!). I hate that! I want to get rid of my hack style macro, but still reduce the vertical spacing when the last text line is close to the displayed equation below it. My limit would be 1ex in size.

Can we have access to the size limit that LaTeX uses to change the vertical spacing, when the end of the last text line is close to the display? I want to reduce that limit to about 1ex size. Is this possible? If so, how could we implement this in the preamble?

Cham
  • 2,304
  • ams alignments are always full width so never use the short versions. – David Carlisle Jan 05 '20 at 15:58
  • @DavidCarlisle, then how could we change that? Is this possible? And even the equation environment limit is a bit too high for my taste. Can we reduce it too? – Cham Jan 05 '20 at 15:59
  • 1
    Not at all easy (you would need to extensively re-write amsmath). This is a documented feature, and the main reason you should not use align for one-line equations. The hard part (using classic tex) is to find the position of the visible left edge of the first row of the alignment, given that the alignment is build on a \halign that is the width of the page. – David Carlisle Jan 05 '20 at 16:01
  • no the overshoot limit for standard display math like equation is fixed in tex at 2em and is not changeable without changing the source of tex-the-program – David Carlisle Jan 05 '20 at 16:02
  • @DavidCarlisle, in the MWE example above, I used the align environment with a single equation for the example only. Of course, I use that environment only to display several equations. – Cham Jan 05 '20 at 16:03
  • well basically you have a table and if line 5 is wide then the table columns will adjust and it's not so easy to check after the fact that actually the entry in the first row is small. – David Carlisle Jan 05 '20 at 16:04
  • @DavidCarlisle, eew! So does this implies that I would have to use my hack, as my only solution? – Cham Jan 05 '20 at 16:04
  • 1
    fixing amsmath not to do this is way more effort than is reasonable to put into an answer on this site, it would be a good thing to do though, I am not discouraging anyone from trying to propose an updated package... – David Carlisle Jan 05 '20 at 16:05
  • one possible way of automatically fixing things up without re-writing all of amsmath would be to arrange to use \pdfsavepos at the end of the paragarph and at the start of the first row of math, then if you write the \pdflastxpos of each to the aux file then on the next run you can check their relative positions and adjust the vertical space if necessary. perhaps.... – David Carlisle Jan 05 '20 at 16:09
  • @DavidCarlisle User wea0 proposes a solution for align, but not for gather, in this answer.Plain TeX's \eqalign automatically detects when and when not to use abovedisplayshortskip: see Barbara Beeton's response to this comment.) – Gabriel A. Lozada Jun 27 '23 at 19:12
  • @GabrielA.Lozada i think you are wrong about \eqalign aren't you? like align that is a full width \halign – David Carlisle Jun 27 '23 at 19:20
  • @DavidCarlisle \documentclass{article} \usepackage{plain} \begin{document} \showboxbreadth=\maxdimen \showboxdepth=3 \tracingoutput=1 \tracingonline=1 Hello world! \begin{plain} $$\eqalign{x &= 1 \cr y &= 2.}$$ Hello Hello Hello Hello Hello Hello Hello Hello Hello $$\eqalign{x &= 1 \cr y &= 2.}$$ \end{plain} \end{document} shows \abovedisplayshortskip and \belowdisplayshortskip for the first alignment and \abovedisplayskip and \belowdisplayskip for the second alignment. – Gabriel A. Lozada Jun 27 '23 at 19:36
  • @DavidCarlisle You might be thinking of Plain TeX's \eqalignno, which (unlike Plain's \eqalign) does not automatically detect when and when not to use abovedisplayshortskip. – Gabriel A. Lozada Jun 27 '23 at 20:02
  • ah could be, or I could simply have been wrong. let's assume the former:-) @GabrielA.Lozada – David Carlisle Jun 27 '23 at 20:50

0 Answers0