# Why does TeX prefer an overfull box to hyphenating here?

Here is a short file which produces an overfull hbox:

\documentclass[12pt]{report}
\usepackage[left=1.5in,right=1in,paperwidth=8.5in,paperheight=11in]{geometry}
\begin{document}
\trivlist
\item[\hskip\labelsep{\bf2.3.12 Corollary [Isomorphisms are indexed bijections]:}]
Consider the functions $f$ and $g$
\endtrivlist
\end{document}


If I replace functions with func-\linebreak tions, the word is split across two lines, resulting in neither an overfull nor an underfull hbox. However, neither func\-tions nor func-tions produces this behavior. Why not? Is there a better way to convince TeX that it's okay to hyphenate this word to prevent an overfull box?

-
If you load microtype, the overfull box will be reduced from 10.7pt to 8.5pt. –  Sverre Mar 30 at 18:09
You may want to try and put \emergencystretch=.5em into the preamble. \sloppy is way too harsh. –  morbusg May 16 at 20:28

It's important to remember that TeX doesn't build a page line by line, but paragraph by paragraph; this is a major difference from the behavior of most word processing programs. TeX applies various rules -- resulting in penalties or demerits if they're not satisfied -- to come up with an "overall best" appearance. TeX assigns penalties not only to overfull lines but also to irregular inter-word spaces. Specifically, TeX will try very hard to produce roughly the same amount of interword space across all lines of a paragraph. It does so by assigning substantial penalties if the amount of interword space varies noticeably across lines within one and the same paragraph.

In the example you've provided, the unhyphenated word, "functions", happens to protrude by "only" two characters ("ns") into the right-hand margin. In TeX's view, this outcome appears to be preferable to hyphenating the word "functions", as hyphenating the word would also generate very large interword spaces between "Consider" and "the" as well as between "the" and "functions. (TeX isn't allowed to adjust any of the interword spaces between the words that are in the argument of \item, because that "box" has already been closed and is no longer accessible to TeX's paragraph building routine. As a result, there are only two interword spaces in the first line that TeX is allowed to modify while it's building the paragraph.)

To override TeX's default settings related to building paragraphs, one can issue the command \sloppy. Sure enough, if one inserts the instruction \sloppy before \item, TeX has no problem hyphenating the word "functions" -- and creating two rather large interword gaps in the first line of the paragraph. (If you don't want to go quite as far as \sloppy, you might try typing \tolerance=1000. The default value of \tolerance is 200 -- see pp. 29f. of the TeXbook for more information on this parameter.)

Another solution, which may or may not be to your liking, is to forgo full justification; load the package ragged2e and issue the command \RaggedRight to allow hyphenation. Without full justification, you're virtually assured that there will be no overfull lines.

In summary, the problem you describe arises because (i) TeX has only two interword spaces to play with on the first line and (ii) TeX generally, i.e., unless \sloppy is in effect, assigns fairly high penalties to irregular and large values of interword spaces. In the case of your example, these penalties appear to outweigh the penalty created by letting a word protrude slightly beyond the right-hand edge of the text block.

Finally, here's a comparison of the "tight" and "sloppy" looks of the two-line paragraph. I've highlighted some areas with little yellow rectangles to illustrate the issues of (i) overfull line boxes and (ii) excessive amounts of interword whitespace. The thin black lines are inserted by the showframe option of the geometry package.

\documentclass[12pt]{report}
\usepackage[left=1.5in,right=1in,showframe,
paperwidth=8.5in,paperheight=11in]{geometry}
\setlength\parindent{0pt} % just for this example
\begin{document}
Tight setting:
\trivlist
\item[\hskip\labelsep{\bf2.3.12 Corollary [Isomorphisms are indexed bijections]:}]
Consider the functions $f$ and $g$
\endtrivlist

Sloppy setting:
\sloppy
\trivlist
\item[\hskip\labelsep{\bf2.3.12 Corollary [Isomorphisms are indexed bijections]:}]
Consider the functions $f$ and $g$
\endtrivlist
\end{document}

-
I think it's not just to say TeX "prefers" overfull boxes. It certainly doesn't generate them with the intent to have words dangling over the boundary in any final print document. — I would take it that TeX prefers to give a definite warning, both as a message and as a visible feature in the output, so you can manually adjust your document to avoid either problem. If Tex just kept inserting big spaces, you wouldn't notice but the output would be ugly. Since it's only a warning (which you may ignore), this is still compatible with the focus-on-content-rather-than-presentation philosophy. –  leftaroundabout Mar 30 at 12:31
@leftaroundabout - Well, the claim about TeX "preferring" an overfull box to hyphenating a word is in the posting's title, not my answer. I use the (admittedly somewhat related...) expression "preferable" merely as a way of setting up the outcome of the choice TeX has to make between two not-so-great outcomes when building the paragraph: creating an overfull box on the one hand, vs. having very uneven spacing between words on the other. –  Mico Mar 30 at 12:42
Can I ask for slightly larger spaces in the trivlist label somehow? (Should I open a separate question for that?) –  Daniel Wagner Mar 30 at 14:10
@DanielWagner - May I suggest you post a new question (to inquire about how to get LaTeX to operate on the interword spaces inside an item's "label")? That way, more people will see it and have a chance to provide an answer. Thanks. –  Mico Mar 30 at 15:36
For posterity, I found that playing with \spaceskip in the label produced the effect I wanted: greater interword spacing along the whole line, and a hyphenated final word. –  Daniel Wagner Mar 30 at 22:41