Knuth-Plass: adjacent demerits on the first line

Paulo Ney de Souza pauloney at gmail.com
Thu May 4 02:06:29 CEST 2023


On Wed, May 3, 2023 at 1:35 PM Don Hosek <don.hosek at gmail.com> wrote:

> if I understand sections #859 and #864 in the KP algorithm correctly,
>> TeX adds adjacent demerits to solutions for the /first/ line which are
>> not in the decent fit class. That is because the root active node in
>> #864 is initialized with a fitness of decent_fit, and there's no
>> special-casing of the first line in #859.
>>
>> If this is correct, I find it weird to consider adjacent demerits for
>> the first line, given that there is no previous line to actually compare
>> with.
>>
>> Again, IIUC, doing this will favor paragraph solutions for which the
>> first line is as close to natural spacing as possible. But what about
>> the repercussions on the subsequent lines? Given the default values for
>> adjacent demerits and hyphen penalties for example, it seems to me that
>> it would be possible for the KP algorithm to prefer a paragraph solution
>> with a decent first line over one with fewer hyphens.
>>
>> I couldn't find a rationale for this design decision anywhere, so I'm
>> wondering if there is one, and if somebody actually knows about it.
>>
>>
> Part of this comes down to the fact that the first line is at a
> disadvantage compared to other lines in the paragraph¹ when it comes to
> line breaking options since you can’t adjust previous lines to make the
> line breaks better. This is part of why TeX has a tendency to let the first
> line go overfull or have badness 10000 (depending on the \tolerance
> setting).
>

It is more than that -- the first line is allowed to go overfull -- even in
old typesetting (before TeX), because of the lack of comparison with any
lines before it. It is easier for the untrained eye to detect an overfull
if you can draw a line joining the two neighbor endings that the middle one
surpasses.



> 1. The last line is usually less disadvantaged thanks to \parfillskip
> making things much easier on the line breaking algorithm, although
> non-standard settings for \parfillskip could come into play. These are rare
> enough, though, that there’s no need for different treating.
>

It is also more than that. Probabilistically, the first-line is almost
always full while the last-line is almost always NOT a full line.

Paulo Ney
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://tug.org/pipermail/texhax/attachments/20230503/be822a21/attachment.html>


More information about the texhax mailing list.