4

The code is as follows:

\newlength{\stretchable}
\newlength{\fixed}
\setlength{\stretchable}{2cm plus 6cm}
\setlength{\fixed}{8cm}
\hbox to 10cm{|\hfil|}                 % the sample of a 10cm hspace
\hbox to 10cm{|\hspace{\fixed}|}       % the badness is 10000 and the right '|' lacks 2cm yet
\hbox to 10cm{|\hspace{\stretchable}|} % no badness message and the output is fine (like \hfil)
  • So TeX tends to fill all the provided space in a box so that's why \hfil is okay (it is as elastic as needed).
  • The case of \fixed is clear that it is not stretchable at all and the box of 10cm is rather underfull (8cm is not enough).
  • But, in case of 2cm plus 6cm, I supposed the system could take only 6cm at maximum over the base 2cm length so that finally the space would be 8cm as well.

Why does TeX stretch more than the plus-component and why it does not report the badness message in this case (in fact, it had to stretch more than it was assured first)?

1
  • Because Knuth decided so…
    – egreg
    Commented Oct 14, 2021 at 17:05

1 Answer 1

5

The computed badness of the last box is 179, which is less than the default threshold 10000.

You can see this if you make \hbadness as small as possible.

\hbadness=-\maxdimen
\newskip\fixed
\fixed=8cm
\newskip\stretchable
\stretchable=2cm plus 6cm

\hbox to 10cm{|\hfil|}
\hbox to 10cm{|\hskip\fixed|}
\hbox to 10cm{|\hskip\stretchable|}

\bye

Compile with tex or pdftex.

The console will show

Underfull \hbox (badness 10000) detected at line 8
\tenrm | |

Underfull \hbox (badness 179) detected at line 9
\tenrm | |

By Knuth's decree, stretchable glue is allowed to stretch beyond the stated limit, at the expense of badness. This way interword spaces can be kept as small as possible. Otherwise their stretchability should be larger than it is by default and one would lose control on interword space.

Stretching always add to badness, but much less when it remains below the stated amount than when it has to go beyond.

2
  • I've run the code above and examined the output. So TeX kind of ignores the stated stretchability to prevent possible more serious problems (with interword spaces and etc)? It will complement the missing space at the cost of badness. So TeX does it by its nature (D. Knuth put such behavior into it).
    – Vladimir
    Commented Oct 14, 2021 at 18:05
  • 1
    @Vladimir To put it another way: The "plus" (stretchability) component of the glue should be understood not as the maximum stretch, but as the amount of stretch at which the badness is exactly 100. (In the example of stretching a 2cm plus 6cm glue to 10cm, the badness would be (roughly 100 * (8/6)^3, which is) 237. In the above example, because of the |s the required stretching is less, so it's only 179.) See page 97 of The TeXbook or page 1127 (page 9 of the article/pdf) of Breaking Paragraphs into Lines. Commented Dec 3, 2021 at 0:44

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .