unexpected extra parskip before equation, when the last line reach the end

like the figure below, it always generates a extra vertical space, if the line before equation is full.

what I have found：

remove hyperref or option parskip=full* can solve this, but I want to know, how does it happen

Thank you all.

MWE

\documentclass[a4paper,12pt, parskip=full*]{scrbook}
\usepackage{hyperref}

\usepackage[fleqn]{amsmath}
\setlength{\parindent}{0pt}
\newcommand{\myparagraph}[1]{\paragraph{#1}\mbox{}\\[1em]}

\begin{document}
\section*{Test}

\myparagraph{extra vspace}
xxxxxxxxxxx xxxxxxxxx xxxxxxx xxxxxxxx xxxxxxxxxxxxxxxxxx xxxxxx xxxxx end
$$a + a + a$$

\myparagraph{right space}
xxxxxxxxxxx xxxxxxxxx  end
$$a + a + a$$

\end{document}

• Off-Topic: You can use \RedeclareSectionCommand[afterskip=1sp]{paragraph} to make \paragraph a displayed/free-standing title instead of a runin-title. This would also avoid page breaks between the title and the following text. BTW: There is an article in German on komascript.de why not to use \setlength{\parindent}{0pt}. – Schweinebacke Oct 8 '18 at 6:18
• aha, thanks for the advice, very helpful @Schweinebacke – sun0727 Oct 8 '18 at 10:00

hyperref adds something when TeX starts processing that contributes to the current paragraph, before the display actually start.

If you add % at the end of the long line, you'll see that its natural width is less than the line width, but the anchor inserted by hyperref causes TeX to form an empty line. A message about an overfull box appears after adding the %, but is spurious and due to internal workings.

You're being unlucky. One more reason not to use parskip.

Note that it's mostly the parskip* option to blame (thanks to Ulrike Fischer for noting), because it sets \parfillskip to 0.25\columnwidth plus 1.0fil and this makes it much more difficult to break paragraphs. However, I think that the problem could present also with parskip=full-, that doesn't change \parfillskip. Not going to investigate, as I firmly believe that using a nonzero parskip is bad: just a waste of space with no benefit for the reader.

Minimal example

\documentclass[a4paper,12pt,parskip=full*]{scrbook}
\usepackage{showframe}
\usepackage{hyperref}

\usepackage[fleqn]{amsmath}
\setlength{\parindent}{0pt}

\begin{document}
\section*{Test}

% extra vspace
xxxxxxxxxxx xxxxxxxxx xxxxxxx xxxxxxxx xxxxxxxxxxxxxxxxxx xxxxxx xxxxx end
$$a + a + a$$

% no extra vspace
xxxxxxxxxxx xxxxxxxxx xxxxxxx xxxxxxxx xxxxxxxxxxxxxxxxxx xxxxxx xxxxx end%
$$a + a + a$$

% right space
xxxxxxxxxxx xxxxxxxxx xxxxxxxxx end
$$a + a + a$$

\showoutput

\end{document}


Analysis of the log produced by \showoutput

First case (excess space)

.....\OT1/cmr/m/n/12 e
.....\OT1/cmr/m/n/12 n
.....\OT1/cmr/m/n/12 d
.....\glue(\rightskip) 0.0
....\penalty 10050
....\glue(\baselineskip) 14.5
....\hbox(0.0+0.0)x448.13095, glue set 336.09822fil
.....\hbox(0.0+0.0)x0.0
......\hbox(0.0+0.0)x0.0, shifted -14.5
.......\pdfdest name{equation.0.0.1} xyz
.......\penalty 10000
.....\penalty 10000
.....\glue(\parfillskip) 112.03273 plus 1.0fil
.....\glue(\rightskip) 0.0
....\penalty 10000
....\glue(\abovedisplayskip) 12.0 plus 3.0 minus 7.0


An empty line (containing only the invisible anchor) is quite evident.

Second case (with % after end)

.....\OT1/cmr/m/n/12 e
.....\OT1/cmr/m/n/12 n
.....\OT1/cmr/m/n/12 d
.....\penalty 10000
.....\hbox(0.0+0.0)x0.0
......\hbox(0.0+0.0)x0.0, shifted -14.5
.......\pdfdest name{equation.0.0.2} xyz
.......\penalty 10000
.....\penalty 10000
.....\glue(\parfillskip) 112.03273 plus 1.0fil
.....\glue(\rightskip) 0.0
....\penalty 10000
....\glue(\abovedisplayskip) 12.0 plus 3.0 minus 7.0


Here the anchor can be set as part of the final line of the paragraph so far (before the display).

Third case (short line)

.....\OT1/cmr/m/n/12 e
.....\OT1/cmr/m/n/12 n
.....\OT1/cmr/m/n/12 d
.....\glue 3.91663 plus 1.95831 minus 1.30554
.....\penalty 10000
.....\hbox(0.0+0.0)x0.0
......\hbox(0.0+0.0)x0.0, shifted -14.5
.......\pdfdest name{equation.0.0.3} xyz
.......\penalty 10000
.....\penalty 10000
.....\glue(\parfillskip) 112.03273 plus 1.0fil
.....\glue(\rightskip) 0.0
....\penalty 10000
....\glue(\abovedisplayskip) 12.0 plus 3.0 minus 7.0


This is quite similar to the second case.

• nice answer, very helpful. Thanks ^-^ – sun0727 Oct 4 '18 at 17:17
• The problem is not the \parskip setting but the \parfillskip setting, with e.g. parskip=full- or a local \parfillskip=0pt plus 1.0fil there is no problem. – Ulrike Fischer Oct 4 '18 at 17:21
• @UlrikeFischer I suspected it, seeing the strange \parfillskip glue. In my opinion, parskip is bad anyway. Trying to fix it so the final line is not flush with the margin is even worse. – egreg Oct 4 '18 at 17:23
• should hyperref be adding an ifhmode unskip somewhere so the % isn't needed? – David Carlisle Oct 4 '18 at 17:39
• The problem can also occur with \parfillskip=0pt plus 1fil (e.g. using parskip=false). Try, e.g., xxxxxxxxxxx xxxxxxxxx xxxxxxx xxxxxxxx xxxxxxxxxxxxxxxxxx xxxxxx xxxxxxxend with removed parskip=full*. With xxxxxxxxxxx xxxxxxxxx xxxxxxx xxxxxxxx xxxxxxxxxxxxxxx xxxxxxxend it does also happen with book instead of scrbook. So it is not a problem of KOMA-Script and even not a problem of using paragraph skip or paragraph indent. – Schweinebacke Oct 8 '18 at 6:11