# Why overfull in terms of pts and underfull in terms of badness?

I am reading Knuth's The TeXbook, and experimenting around as directed in Chapter 6, I found that the quality of overfull warnings is reported by x pt too wide where x is a decimal; whereas, that of underfull warnings are reported as badness N where N is a nonnegative integer.

Questions: Why not report both warnings in the same format (or in both formats)? Also, how to convert from one to another?

Edit:

This is how I understand it currently: x pt too wide means that the line sticks out of the right margin by x points; on the other hand, badness N means that the interword spacing is too wide (wide, not narrow, since we have "under"-full) by N units on a linear scale where 0 is "perfect". So, the underfill boxes won't stick out of the right margin. So it does make sense to not report the x pt too wide for underfill lines. However, not reporting the badness of overfull lines seems to suggest that the badness of each of the overfulls is the same, namely the worst 10000, is that so?

• you changed the question as I was writingthe answer but your new question: yes overfull lines are always infinitely bad Commented Jul 19, 2023 at 14:15

The amount a box is overfull is a length, it sticks out that much, so pt is as good a unit as any.

The amount a box is underful is not a length, it is a measure of how much any white space has been stretched to make the content stretch to the box dimensions. Badness is a formula which combines the stretch and shrink components of all white space in the box and gives a measure of how much it is stretched.

• What is the "box" here? Something that encloses the line?
– Atom
Commented Jul 19, 2023 at 14:23
• more or less everything in tex that is not white space is a box, "box and glue" is the main typesetting paradigm used by tex. Each line of a paragraph is a horizontal box. (like \mbox or \hbox but made implicitly as the paragraph is broken in to lines). @Atom Commented Jul 19, 2023 at 15:25

TeX calculates badness of boxes wider than their implicit width but also of boxes narrower than their implicit width. There is symmetry from this point of view. The spaces include their implicit width and their stretch value and shrink value (i.e. there are three values for each space). When a box should be stretched from its implicit width then the sum of all stretching values from present spaces are counted. When the box should be narrowed then all shrinking values are counted. In both cases, denote this sum S. Denote the required stretching or shrinking R. Then the badness is calculated as 100*(R/S)^3.

The only difference (or asymmetry) between stretching and shrinking is that TeX allows boxes wider than S, i.e. R should be greater than S, i.e. badness should be greater than 100. But this isn't allowed for shrinking. The S is maximum allowed shrinking, never more. If the R>S in case of shrinking then the box is set as if R=S and the rest of box material exceeds over the box boundary to the right. This specific case is Overfull \hbox and the badness is assumed infinity (not calculated). The amount of exceeding over the box is reported.

When stretching box and R>S, then badness is calculated and spaces inside this box are stretched wider than their stretch value. The badness value has its allowed maximum 10000 and if the formula for badness (mentioned above) gives higher value then badness is set to 10000.

Assume the following example. The warning reports are added as a comment to appropriate line in this example:

\hbadness=0

\hbox to20pt{a b} % Underfull \hbox (badness 4927) detected at line 3
\hbox to18pt{a b} % Underfull \hbox (badness 1496) detected at line 4
\hbox to16pt{a b} % Underfull \hbox (badness 203) detected at line 5
\hbox to15pt{a b} % Loose \hbox (badness 29) detected at line 6
\hbox to14pt{a b}
\hbox to13pt{a b} % Tight \hbox (badness 51) detected at line 8
\hbox to12pt{a b} % Overfull \hbox (0.7778pt too wide) detected at line 9

\setbox0=\hbox{a b}

normal width: \the\wd0              % 13.88892pt

stretch value: \the\fontdimen3\font % 1.66666pt

shrink value: \the\fontdimen4\font  % 1.11111pt

\bye


We want to print warnings for all positive badness values. This is done using \hbadness=0. We try to calculate the badness manually, for example for the line 5:

The implicit width of the box is 13.88892pt, the box should be 16pt width, i.e. 2.11108pt wider than its implicit width. This is R value and we want to stretch the box. The stretching value of the space in the box is 1.66666pt, this is S value. Badness is 100*(2.11108/1.66666)^3 = 203.223. Badness is an integer value, i.e. 203.

Note that the line 6 reports "Loose" box (i.e. the box wider than its implicit width but with R<S). The line 6 reports "Tight" box, i.e. the box narrower than its implicit width but not overfull. The badness calculation for this line is b = 100*(.88892/1.11111)^3 = 52. The shrink value 1.1111pt of the space is used here.

Note that the line 7 reports no warning, because badness is 100*(.11108/1.6666)^3 = .029 = 0.

• +1. Thanks for taking the time to write such a complete answer! The examples are very helpful to understand (at user level, like me) Commented Jul 25, 2023 at 14:45
• a better answer than mine, but I got the tick, sorry:-) +1 anyway Commented Nov 4, 2023 at 11:26