TeX has a primitive parameter for that kind of situation: \emergencystretch
, of which Knuth writes in the TeXbook chapter 14
If you want to avoid overfull boxes at all costs without trying to fix them
manually, you might be tempted to set \tolerance=10000
; this allows
arbitrarily bad lines to be acceptable in tough situations. But infinite
tolerance is a bad idea, because TEX doesn’t distinguish between terribly bad
and preposterously horrible lines. Indeed, a tolerance of 10000 encourages TEX
to concentrate all the badness in one place, making one truly unsightly line
instead of two moderately bad ones, because a single “write-off” produces
fewest total demerits according to the rules. There’s a much better way to get
the desired effect: TEX has a parameter called \emergencystretch
that is added
to the assumed stretchability of every line when badness and demerits are computed, in cases where overfull boxes are otherwise unavoidable. If
\emergencystretch
is positive, TEX will make a third pass over a paragraph
before choosing the line breaks, when the first passes did not find a way to
satisfy the \pretolerance
and \tolerance
. The effect of \emergencystretch
is to scale down the badnesses so that large infinities are distinguishable
from smaller ones. By setting \emergencystretch
high enough (based on
\hsize
) you can be sure that the \tolerance
is never exceeded; hence
overfull boxes will never occur unless the line-breaking task is truly
impossible.
So you could use, for example
\emergencystretch=.5em
\emergencystretch[=]<dimen>