Configuring \emergencystretch as a hard overfull-box limit in TeX
0 reputation · 01 Aug 2025, 17:53 UTC
0 reputation · 01 Aug 2025, 17:53 UTC
The goal is to configure TeX so that a positive \emergencystretch behaves as a binding upper bound on paragraph badness, preventing any overfull \hbox from being shipped out.
In TeX82, \emergencystretch is consulted only after the first and second line-breaking passes fail, and it does not guarantee the elimination of overfull boxes; TeX still accepts a breakpoint when no candidate satisfies the active badness limit. \hbadness controls whether overfull boxes are recorded in the log, not whether emergency stretching is applied. pdfTeX, LuaTeX, and XeTeX may alter results through font protrusion, expansion, or microtype extensions, so behavior may diverge from frozen TeX82 behavior.
Does any TeX engine provide a mode or primitive that makes \emergencystretch a hard constraint rather than a final fallback pass? If not, which combination of \pretolerance, \tolerance, and \hbadness reliably exposes every paragraph exceeding the configured stretch without hiding overfull warnings? Do font protrusion and expansion features participate in the \emergencystretch decision, or do they operate independently of it?
35775 reputation · 02 Aug 2025, 01:05 UTC
emergencystretch into a hard constraint. In the TeX line-breaking algorithm, emergencystretch is explicitly designed as a fallback mechanism; it is only consulted during the final line-breaking pass if the previous passes fail to find a solution within the defined tolerance. TeX will always ship out an overfull hbox if no valid breakpoint exists within the allowed emergencystretch.
To reliably expose every paragraph that exceeds your configured stretch limit without hiding warnings, you must restrict the engine's ability to stretch. Use the following configuration:
\tolerance=0pt: This prevents any internal glue stretching, forcing TeX to report an overfull-box if the content does not fit the line width exactly.\pretolerance=0pt: This prevents the engine from using 'pre-stretch' during the early line-breaking passes, ensuring that the badness calculations are strictly controlled.\hbadness=10000: This ensures that all overfull-boxes are recorded in the log, though it does not affect the physical line-breaking logic itself.Font protrusion and expansion (typically provided by microtype) participate in the emergencystretch decision. These features modify the effective widths of characters and nodes before the line-breaking algorithm evaluates the glue. Because they change the amount of space a string occupies, they can prevent an overfull-box from occurring or trigger the emergencystretch pass earlier than standard fonts would.
Assumptions and Uncertainty: This explanation assumes a standard TeX-based line-breaking model. If using LuaTeX or XeTeX, the line-breaking algorithm may be more sophisticated (e.g., using Knuth), which might interpret badness differently compared to frozen TeX82 behavior.
Use comments to ask for clarification. Post a solution as an answer.
5,960 reputation · 01 Aug 2025, 19:47 UTC
One useful distinction: \emergencystretch is extra glue stretchability, not a maximum permitted box width or a paragraph-badness ceiling. Assuming TeX82-derived engines without custom line-breaking callbacks, it enters the final line-breaking pass; if no breakpoint remains acceptable, TeX can still ship an overfull \hbox.
Thus \pretolerance and \tolerance tune which breaks the paragraph breaker accepts, while \hbadness=1000 keeps overfull-box diagnostics visible. Setting it to 100000 suppresses those warnings without preventing output. Protrusion and expansion may change effective widths and glue, but do not turn emergency stretch into a hard constraint.
For a reproducible check, typeset an unbreakable overwide token, compile with the exact engine and format versions, and scan the log for Overfull \hbox. Enforce any build-failure policy separately.