# What's the difference between \tolerance and \badness ?

I'm having some difficulty understanding this sentence on page 29, Chapter 6 of Knuth's TeXbook:

Run TeX again, and begin this time by saying

\hsize=2in \tolerance=1600 \input story

so that lines with badness up to 1600 will be tolerated. Hurray! There are no overfull boxes this time. (But you do get a message about an underfull box, since TeX reports all boxes whose badness exceeds a certain threshold called \hbadness; plain TeX sets \hbadness=1000.)

-

The \tolerance setting influences the paragraph breaking routine itself: changes to \tolerance (and \pretolerance) actually affects which line breaks are chosen. Higher values allow worse lines (usually meaning: with stretched inter-word spaces) to be accepted, with the value 10000 indicating a 'panic mode' where anything at all is acceptable. Normally the lower the value, the better the paragraph will look, but you run the risk of reducing the list of possible breaks so much that you end up with overfull lines.

The \hbadness setting only influences the user report (the messages you see on screen and in the log) about the actually chosen lines, it has no effect on the breaking routine itself.

-
Could you tell me where can I find in Knuth's book what you have just said above, that is, "The \hbadness setting only influences the user report (the messages you see on screen and in the log) about the actually chosen lines, it has no effect on the breaking routine itself". –  bellochio May 27 '11 at 16:35
@bellochio it is implied in the quote you gave in the question. –  Taco Hoekwater May 27 '11 at 18:14
I'm giving you the credit for the answer, for I have the feeling you're right, although it would be better if I had some statement in the book confirming this. Thanks anyway ! –  bellochio May 27 '11 at 18:26
@bellochio ... since TeX reports all boxes whose badness exceeds a certain threshold called \hbadness... That is your confirmation: this explains exactly what ‘\hbadness‘ does. –  Taco Hoekwater May 27 '11 at 18:34

You can think of three groups of parameters that are used by TeX when typesetting a paragraph, those that are set by the typesetter and the font designer, and those calculated by TeX internally. The \badness is calculated by TeX internally, whereas \tolerance is set by the typesetter to tell TeX what can be tolerated in terms of line and overall paragraph badness.

Tweaking these parameters is a bit of a black art.

Run the following minimal with pdfTeX.

\overfullrule=0.1pt
\hsize150pt

\def\astory{Fast pace and mechanically intensive
facilities such as data-centers, hospitals, and
laboratories typically require the most intense
coordination efforts. Architectural and structural
systems are often designed first with allowances
for MEP systems. Tensions between the size of
these MEP spaces, usable floor space,
and ceiling height exist. }

\astory

\the\tolerance,
\the\pretolerance,
\the\hfuzz,
\the\emergencystretch,
% Second test
\pretolerance=150
\tolerance=753
\hfuzz0pt
\emergencystretch=0em

\astory
\bye


In the minimal the paragraph is typeset, firstly with default values and second without. The first one produces a lot of overfull and underfull boxes. We get rid of them by suitably adjusting the \tolerance. In this particular example I set the tolerance to one higher than the hbadness value reported by TeX. This eliminated all the underfull warnings.

There is a nice surprise when you set the \hsize from 150pt to 160pt and this is where the "black art" part comes along!

-
@Yiannis Thanks for your reply. Maybe my question is silly, since I've just started reading Knuth's book, but I still don't understand what these two entities differentiate in the TeX language. –  bellochio May 27 '11 at 8:56
For instance, in your example, what does it mean these two commands: \tolerance = 753 and \hbadness = 752 ? –  bellochio May 27 '11 at 9:18
@bellochio \tolerance tells TeX how much badness is allowable without error. The value can range from 0 to 10000, and there are no units. The fit of the text within its specified dimensions is measured by its badness, which is a number between 0 and 10000. A badness of 0 is a perfect fit, and a badness of 10000 means that the line probably will never fit. The default value of \hbadness is 1000. If you set \hbadness to 10000, TeX does not report underfull lines. In my example since the tolerance was higher than the \hbadness no errors were reported up to that point. –  Yiannis Lazarides May 27 '11 at 10:03