Knuth-Plass Thoughts
github.com
github.com
https://en.wikipedia.org/wiki/River_(typography)
I love typography rabbit holes.
One thing I've often wondered is whether these algorithms treat a page break from even to odd differently from a page break from odd to even: it could make sense to do so, I think, in the case of an ordinary book, particularly when it comes to placing an illustration or table, but perhaps also for widows and orphans.
I really implemented this algorithm so that I could nicely "flow" images in a GUI window. I was working with Sean Parent & Jaakko Järvi on Adam/Eve. My assertion was that there were layout principles (Adam?) for UI similar to the constraint properties for the object model (Eve?). The "other" layout principle was the grid-bag (CSS's box model for grids).
In the common case where your pages are just text with a fixed spacing between lines, the only way for #2 to prevent widows and orphans is to make the page one line taller or shorter, making the margins look weird, which typically also gets penalized, and the only question is which penalty is larger. But if there are any variable spacings on the page, there will be the option of making them slightly larger or smaller in order to push a stray line from one page to another.
If so, nothing special needs to be done about widows and orphans either because TeX first uses essentially the same algorithm to decide where to put page breaks between lines (with page breaks between paragraphs getting lower penalties than page breaks within paragraphs), and having a single line of a paragraph on the top or bottom of a page leads to a fairly high penalty.
[1]: https://raphlinus.github.io/text/2022/11/08/minikin.html
[2]: https://developer.android.com/reference/android/widget/TextV...
My approach to runts was to apply the full penalty to the last line, but only if the number of words was below a threshold (by default, only if it's a single word).
It sounds as though TeX cannot do anything about widows and orphans in the boring "simple" case of a long prose text with a fixed number of lines per page, because the only way[] to improve page breaks in that case would be to change the line breaks, which have already been decided. Mixing up the line-break and page-break stages presumably gives you an NP-hard optimisation problem, and perhaps Knuth was less interested in working on messy heuristic algorithms.
I've just found a couple of references to work in this area:
https://mirrors.mit.edu/CTAN/macros/luatex/generic/lua-widow...
https://onlinelibrary.wiley.com/doi/10.1111/coin.12165
--------
[] I'm assuming that moving the margins or changing the line spacing would be unacceptable because it would make the pages of a book look obviously different from each other. So it turns out that the "simple" case is in some ways harder to handle than the "complex" case in which there are figures and footnotes and so on.