wspr/herries-press

The penalty used in \needspace is questionable and space check needs to apply \prevdepth correction

Opened this issue · 3 comments

After skipping ahead with

\vskip 0 plus requested space

it issues \penalty -100

This means that this breakpoint is usually preferable to filling the requested space with normal text (as that will generate a breakpoint with 0 (or higher)).

If the needed space is exactly available, then the badness of the page page will be at most 100 (and probably less) thus it becomes a bonus to break at this point.

Thus the penalty should be positive (probably something like 100 or perhaps even more).

Concerning \prevdepth: the skipping ahead without taking it into account first time may be ok as that is only a stretch amount, but when doing a real skip it should be substracted. Otherwise: if there are still exactly 3 lines left and we ask for 3 lines the skip will make the page overfull if \prevdepth is non-zero. E.g., something like

  \renewcommand{\needspace}[1]{%
  \begingroup
    \setlength{\dimen@}{#1}%
    \vskip\z@\@plus\dimen@
    \penalty 1000\vskip\z@\@plus -\dimen@
    \advance\dimen@-\prevdepth                         % <---- added
    \vskip\dimen@
    \penalty 9999%
    \vskip -\dimen@
    \vskip\z@skip % hide the previous |\vskip| from |\addvspace|
  \endgroup
}

The advantage of subtracting it only at the later point is that we don't have to worry that \prevdepth really exists as we know by then that we are in vertical mode. The above doesn't contain a fix for #32

Any comment concerning this and #32?

wspr commented

@FrankMittelbach — Sorry, I did look at this briefly over summer but didn't have proper time to sort out a fix. With #32 when you say "back up" over a vertical skip, you mean just add negative vskip for the sizes needed, right?

right. \addpenalty and friends store lastskip then back up (\vskip-\lastskip) then do what they do then readd the space so that their action appear as if done on that earlier point.