2

I would like to avoid at all cost line stretching, without forcing it manually. I will provide you with an example to clarify what I mean.

Here it is the code:

\documentclass{article}

\begin{document} \textbf{Standard output:}

This is for test purposes. This is just for test purposes. This is for test purposes. This is for test purposes. This is just for test purposes. This is for test purposes.

\textbf{Desired output:}

This is for test purposes. This is just for test purposes. This~is~for~test~purposes. This is for test purposes. This is just for test purposes. This~is~for~test~purposes. \end{document}

In other words, I wish there were some command in the preamble that saves me the work of adding all those ~ symbols. To make sure you understood, I'd like to fit more words in a line at any cost.

Lele99_DD
  • 588
  • I know this might be bad in typography, but I'd like to know how to do this for the sake of curiosity. – Lele99_DD Jul 03 '21 at 19:13
  • The effect is exacerbated by the so many sentence ending periods. Declare \frenchspacing in the document preamble and you'll see. – egreg Jul 04 '21 at 08:29

2 Answers2

3
\documentclass{article}
\begin{document}
 \textbf{Standard output:}

 \fontdimen3\font =0pt This is for test purposes. This is just for test purposes. This is for test purposes. This is for test purposes. This is just for test purposes. This is for test purposes.

 \textbf{Desired output:}

 This is for test purposes. This is just for test purposes. This~is~for~test~purposes. This is for test purposes. This is just for test purposes. This~is~for~test~purposes.
\end{document}
Ulrike Fischer
  • 327,261
  • 1
    +1 but may I suggest a link to https://tex.stackexchange.com/q/88991/82917? Not everyone knows about \fontdimen... – campa Jul 03 '21 at 19:34
2

If you look closely at your desired output, you'll notice something: The hyphen on the second line sticks out a little more than the hyphen on the first line (1.88937pt to be precise). So i'm not going to attempt to re-create that.

Instead it's worth knowing about a few parameters in the TeX engine surrounding line breaking that are relevant to your concerns:

  • \pretolerance is the level at which TeX is willing to say a paragraph is good enough without even trying to hyphenate. It's set at 100 by default which says that it can stretch spaces a bit but not a whole lot. There's also \tolerance which is the setting for how much badness to allow even after hyphenation, which by default is 200.¹
  • \hyphenpenalty is the penalty for having hyphens appear in a line. This is set to 50 by default. As a consequence, TeX is going to try really hard to keep you down to no more than 4 hyphens per paragraph.

These two parameters are enough to get you close to your desired output. We can put

\pretolerance=0
\hyphenpenalty=0

in the preamble and we'll get almost the specified output. The second line will be a little different because, as noted above, there's no way to make the line fit even with a hyphen although the spacing is not too bad.

Ulrike raised another possibility in her answer by meddling with the font dimens for the current font and removing all stretchability. This results in the same issue as your original output though, putting the output on the second line of the paragraph a bit into the margin again. For the sake of completeness, the font dimens that are relevant to spacing are:

  • \fontdimen2 interword space (⅓ em)
  • \fontdimen3 interword stretch (⅙ em)
  • \fontdimen4 interword shrink (⅟₉ em)
  • \fontdimen7 extra space at sentence end (⅟₉ em)

I'd argue that these values are not that great. In my typography classes, the default inter-word space was a ¼ em, shrinking to ⅕ em or expanding to ⅓ em which would give values of

\fontdimen2\font = 0.25em % ¼
\fontdimen3\font = 0.0833em % ⅓ - ¼
\fontdimen4\font = 0.05em % ¼ - ⅕

and I would edit the VF files for the fonts I used in typesetting Serif Magazine to reflect those numbers since the old afm2tfm tools would use the wider TeX defaults by default.

It's worth noting that adding those settings to your original document gives the line breaks you get with my \pretolerance and \hyphenpenalty settings without having to set them and fixes the line break issue in your setting with the ~s. Adding \frenchspacing (to get rid of yet another aspect of TeX's typesetting which puts way too much white space in the paragraph) and everything sets the same all the way through.


  1. If you do \sloppy in LaTeX \tolerance gets set to 10,000 which, as far as TeX is concerned, is infinity. This is why you'll often see, especially in narrow columns set with \sloppy a paragraph in which just one line has a huge space separating two words while the rest of the paragraph is normal. Arguably, TeX has set infinity a bit too low (a consequence of using 16-bit values for holding integer values, a choice which made more sense in 1982 than 2021) and it doesn't take too much stretching to hit infinity and its better to have one really bad line than multiple kind of bad but also infinitely bad lines.
ShreevatsaR
  • 45,428
  • 10
  • 117
  • 149
Don Hosek
  • 14,078