0

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.

solisoc
  • 640
  • 2
    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: https://tug.org/TUGboat/tb28-2/tb89glister.pdf and https://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 06 '20 at 09:42
  • @solisoc Yes, lapsus keyboardi :-) – egreg Jan 06 '20 at 10:15
  • @egreg I just changed linepenalty from -100 to 100 after realising the mistake; strangely, the number of pages in my document (>1000) did not change. Even more strangely, when I then removed the change to linepenalty altogether so that (I presume) it returned to its default value of 10, the document became two pages longer! Possibly just the way the numbers work out, I suppose... – solisoc Jan 06 '20 at 11:19

0 Answers0