Why TeX Re-Breaks Your Whole Paragraph (and How to Tune It)
TeX's Knuth–Plass algorithm optimizes whole paragraphs at once instead of breaking lines greedily. Here's how the tolerance and emergency-stretch knobs work, with a narrow-column example.
20 May 2026, 16:38 UTC

You delete one word from the first sentence of a paragraph, and suddenly the last line moves. If you came from Word or LibreOffice, this looks like a bug. It isn't: it's the visible signature of TeX's line-breaking algorithm doing exactly what it was designed to do. Understanding that design is the difference between fighting your typesetter and steering it.
Total fit instead of first fit
Most word processors break lines greedily: they fill the current line with as many words as fit, break, and move on. Once a line is committed, it's never reconsidered. TeX uses the Knuth–Plass algorithm, which treats an entire paragraph as one optimization problem. It considers every feasible set of breakpoints and picks the layout that minimizes total "demerits" across the whole paragraph.
The raw material is glue: the space between words isn't fixed, it has a natural size plus a stretch and a shrink component. For each candidate line, TeX computes a badness — roughly, how hard the glue had to be stretched or compressed, on a scale where 100 is already visibly bad. Demerits are derived from badness, with extra penalties for things like consecutive hyphenated lines. The winning layout is the one with the lowest total, so TeX will happily make line 2 slightly looser if it lets line 5 avoid a terrible break.
The knobs that actually matter
Three parameters do most of the practical work:
\tolerance— the maximum badness TeX will accept for a line before it gives up and either hyphenates more aggressively or produces an overfull box. Default is 200.\emergencystretch— extra virtual stretch added in a third pass, used only when the first two passes fail. This is the surgical tool: it rescues hopeless paragraphs without loosening everything else.\hyphenpenalty— the cost of breaking at a hyphenation point. Raise it to discourage hyphens; lower it if narrow columns need more break opportunities.
And then there's \sloppy, which cranks tolerances up globally. It works, but it trades overfull boxes for visibly gappy, underfull lines everywhere. A better habit is scoping it: wrap only the problem paragraph in {\sloppy ... \par} so the rest of the document keeps strict settings.
A worked example: the two-column squeeze
The classic stress test is a twocolumn article, where the narrow measure gives the algorithm few good options. Compile this with pdflatex:
\documentclass[twocolumn]{article}
\usepackage{lipsum}
\begin{document}
\lipsum[1-3]
\end{document}Check the log for Overfull \hbox warnings. Then add, before \begin{document}:
\emergencystretch=1.5em
\tolerance=2000Recompile and compare the log. In practice this combination clears most overfull boxes in narrow columns without the uniform looseness of \sloppy — but verify on your own document, because the right value of \emergencystretch depends on your column width and font. If you want to see the algorithm's reasoning, set \tracingparagraphs=1 (pdftex/luatex) and read the trace of feasible breakpoints and demerits in the log.
One further step, if your engine supports it: load \usepackage{microtype}. It adds character protrusion (letting punctuation hang slightly into the margin) and font expansion (subtly widening or narrowing glyphs), which reduces badness before the paragraph breaker even has to compromise. Check texdoc microtype for what your installed version supports.
Where the model runs out
Knuth–Plass optimizes lines, not pages. Page breaking in TeX is a separate, simpler mechanism, so no amount of \tolerance tuning will fix a bad page break or a float stranded three pages from its reference. Also, hyphenation quality depends entirely on the language patterns loaded via babel or polyglossia; with the wrong patterns, no tolerance setting will save a paragraph full of unbreakable long words. And remember the trade-off: every overfull box you eliminate by raising tolerance is paid for in looser spacing somewhere else. The log's Underfull \hbox messages are the bill.
A practical workflow
When a paragraph misbehaves: first confirm the right language is loaded, then try microtype, then add \emergencystretch locally, and only then reach for a scoped \sloppy. Compare overfull and underfull warnings in the log before and after each change — that count is your objective measure, and it keeps you from "fixing" one line by quietly degrading ten others.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.