4

Last week, I handed in a homework where an equation went off the edge of the page. Embarassing...

I would like to prevent this from happening again by having LaTeX stop compilation when it notices an overfull \hbox. I've tried setting \tolerance=0, but LaTeX seems happy to keep compiling, still printing warnings like: Overfull \hbox (222.96991pt too wide) detected at line 46.

I'm wondering, how can I make sure that documents with equations running off the page fail to compile? (I am using XeLaTeX if it makes a difference.)

  • 1
    overfull boxes can happen quite often, at leas a bit overfull. It wouldn't be a good workflow if they would error all the time. You could use the draft option to get a visual feedback on the page. – Ulrike Fischer Nov 18 '20 at 18:43
  • 1
    An Overfull \hbox warning is not a “failed compilation”. It simply tells you that the equation doesn't fit and TeX never tries to split a displayed equation. – egreg Nov 18 '20 at 18:43
  • Yeah, I must be confused. I guess I am really just worried about equations -- some paragraph text hanging over the margin a little is fine. – mostsquares Nov 18 '20 at 18:43
  • 1
    I want to find a way to force myself to keep my equations from going off the edge of the page, and I'm definitely open to rephrasing the question to suit that. – mostsquares Nov 18 '20 at 18:44
  • always read the log file. I read it before looking at any pdf output usually. – David Carlisle Nov 18 '20 at 19:07
  • 1
    Another possibility is to set \overfullrule to, say, 10pt. The awful blob of ink will be difficult to miss in preview... – Rmano Nov 18 '20 at 21:37
  • 3
    As noted by @Rmano, a nonzero \overfullrule will put a black blob in the margin to the right of the overfull line. But it's easier to just add the [draft] option to the \documentclass. (You might want to remove it from the final run, although if there are no overfull lines left then, no blob will appear to embarrass you.) – barbara beeton Nov 19 '20 at 02:44
  • 1
    Uh, it just occurred to me that the nasty black box will follow the overfull line, and if that is already cut off at the edge of the page, you won't be able to see it. You'll have to check the width of overfull boxes in the log. You can suppress the warnings on "shorter" overfull boxes by specifying \hfuzz=.5cm or some such. – barbara beeton Apr 13 '22 at 22:31

1 Answers1

1

Provided that you're willing to use LuaLaTeX, it is quite simple to force an unrecoverable error whenever an overfull \hbox is found:

\documentclass{article}

\directlua{ luatexbase.add_to_callback("hpack_quality", function(incident, detail, head, first, last) texio.write_nl( "term and log", incident .. " \string\hbox (badness " .. detail .. ") on lines " .. first .."--" .. last .. [[.^^J]] )

        if incident == "overfull" then
            tex.nest[0].head = nil --[[ Force a fatal error ]]
        end
    end,
    "overfull_hbox"
)

}

\begin{document} Hello!

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

\end{document}

A much better solution would be for you to always check the log file, since there are many other warnings that can be important to read; nevertheless, this should do what you asked.

Max Chernoff
  • 4,667
  • error("note: overfull hbox") or something similar may be an easier way to force a fatal error? – user202729 Aug 12 '22 at 00:51
  • @user202729 If you are running in \nonstopmode, you can still ignore errors from the error function. By completely corrupting the main node list, you make sure that it's impossible to produce a PDF. There is likely a gentler way of forcing a fatal error; I'm just quite familiar with weird node issues so that's what I thought of first. – Max Chernoff Aug 12 '22 at 04:13