# Ensure minimum length of last line by tightening word spacing

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.

• You can try adding \looseness=-2 at the end of the paragraph (or at the beginning). For a global effect, you can set \linepenalty=-100 so TeX will try harder to make shorter paragraphs. – egreg Sep 25 '19 at 14:22
• note that if you make \parfillskip a 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
• There are a couple of TUGboat articles in the Glisterings series that deal with unusual paragraphing requirements that may be of interest: tug.org/TUGboat/tb28-2/tb89glister.pdf and tug.org/TUGboat/tb29-2/tb92glister.pdf. (Caution I was the author). – Peter Wilson Sep 25 '19 at 17:02
• The easiest soltuion is tho put the last few words of a paragraph into an \hbox for any paragraph which offends your aesthetics. – John Kormylo Sep 26 '19 at 22:09
• @egreg Do you perhaps mean \linepenalty=100, without the minus? – solisoc Jan 6 at 9:42