There are already a few questions that ask how to ensure a minimal length for the last line of a paragraph: Ensure minimal length of last line and Minimum length of last line of a paragraph. But unless I'm mistaken, both the accepted answers work by lengthening the final line until it is acceptably long. Is there a way of doing the opposite—reducing the spaces between words on the second-to-last line until the material on the last line can fit at the end?
The use case for this is to deal with short words and bits of math that end up on their own on the last line of a paragraph.
I imagine there would only be one parameter for the user to set: the maximum amount that the space between words on the second-to-last line can be reduced.
LuaLaTeX solutions are perfectly welcome.
\looseness=-2at the end of the paragraph (or at the beginning). For a global effect, you can set\linepenalty=-100so TeX will try harder to make shorter paragraphs. – egreg Sep 25 '19 at 14:22\parfillskipa fixed maximum (say half text width) this does not just stretch out the words in the last line, the entire paragraph breaking is attempted to get the best breaks while meeting that constraint. – David Carlisle Sep 25 '19 at 16:06\hboxfor any paragraph which offends your aesthetics. – John Kormylo Sep 26 '19 at 22:09\linepenalty=100, without the minus? – solisoc Jan 06 '20 at 09:42linepenaltyfrom-100to100after realising the mistake; strangely, the number of pages in my document (>1000) did not change. Even more strangely, when I then removed the change tolinepenaltyaltogether so that (I presume) it returned to its default value of10, the document became two pages longer! Possibly just the way the numbers work out, I suppose... – solisoc Jan 06 '20 at 11:19