# Automating "good" pagebreak (manual local pagebreak optimization)

I was recently typesetting a book with LaTeX where the publisher had the following requirements:

1. Absolutely no clubs; widows tolerated, but avoid if possible. (The text contained many 2-line and 3-line paragraphs.)
2. No hyphen at pagebreak.
3. Good looking pages.
4. I could choose the page layout to some extent (tuning margins and such).

The steps I did were the following:

1. With fixed \textwidth, use microtype for considerable paragraph flexibility. Find all Overfull hbox and adjust hyphenation of the word being broken, or adjust wording of the phrase; this was always in the first paragraph line.
2. Set \clubpenalty=10000 and \widowpenalty=10000. Many Underfull vbox were the result. Find the best \textheight around given page size; I tried initial guess ±4mm with 1mm step. One of them generated the least number of Underfull vboxes, which was the pagesize I chose.
3. For each Underfull vbox page, find a paragraph which was close to being shorter (last line short) or longer (last line long) by 1 line. Set \looseness to 1 or -1 and retry. Usually a better pagebreak was found right away by adjusting just one paragraph in this way, and only on the page where the problem was. Continue until no more Underfull vbox appear (with \vbadness=3000).
4. Visually find all hyphenations at page break, and put the word broken into \hbox{...} to prevent the break. In all cases, the paragraph was fine that way. (Using \brokenpenalty would move pagebreak but not try to not hyphenate.)

Some of the steps (#3, #4) were highly repetitive. Although the approach is naive trial-and-error, only providing simple feedback from pagebreak to linebreak improved the result quite a bit in terms of something like local optimization.

The question is: is there some automation of these tasks already done or in the process of being programmed? (I am not asking about Frank's Alice goes floating which has much broader goal of global optimization.)

• Setting \brokenpenalty = 10000 will prohibit a page break after a line that ends with a hyphen.
– GuM
Jun 11, 2017 at 11:08
• @GustavoMezzetti yes, but that was usually the best (or only) line to break page, so \brokenpenalty=10000 would cause Underfull vbox instead of just avoiding the hyphen and doing the page break there. Jun 11, 2017 at 11:19

In classic tex, without using lua callbacks there is not a lot more that can be done but...

step 2 sounds wrong.

\textheight should always be \topskip + some multiple of \baselineskip otherwise on a page with just text there is no possibility of avoiding an underfull box.

If you can allow yourself an extra line without adjusting the page size you can use

\enlargethispage{\baselineskip}


usually best to do on both pages of a spread of course.

but basically it requires hand tuning as you say.

you didn't say what you have \parskip set to. If you have lots of small 2-3 line paragraphs you presumably have lots of inter-paragraph space so if you set club and widow penalties so the paragraphs don't break one option (in some designs) is to make \parskip quite flexible so that in practice you can always take a three line paragraph over to the next page without making the current page under-full. If you need to keep vertical glue controlled or even not stretchy at all to keep things on a grid layout then more hand tuning is needed.

• For a book with no mathematics and no headers apart from the chapters, anything other than \parskip=0pt usually looks messy. If the OP did have several "large" breaks on most pages, the question probably wouldn't arise anyway. Personally, I just use the manual \looseness method that the OP doesn't like. Don't forget that you can sometimes stretch or shrink the number of lines in a long paragraph, to fix a page-break problem on a later page in the document. Jun 12, 2017 at 4:07