# Where are those overfull/underful boxes and lines? Show me, I'm lazy!

Sometimes I compile a document with a lot of overfull/underfull line/box messages, which fill up my terminal and I can't make heads or tails of them without very careful scrutiny & scrolling.

Is it possible to get pdfTeX to mark these boxes and lines somehow? Say, with a box of some color, a dot, an underline, a side-bar, etc.?

• Does not work in all cases but two strategies: 1) compile with draft option, all horizontal boxes sticking out into the margin will be marked with a black bar 2) look at the line number of the warning, with a good editor that support synctex, you can just jump to the right place. – user36296 Apr 3 '17 at 18:44
• There are lots of questions about overfull and underfull boxes already on TeX.sx – with lots of helpful advice how to debug them. But I'm too lazy (!) to search them for you… No doubt this is a duplicate question. – cgnieder Apr 3 '17 at 18:45
• Related/duplicate: Is it possible to make LaTeX mark overfull boxes in the output? – Werner Apr 3 '17 at 18:46
• @samcarter: Which document classes does that apply to? – einpoklum Apr 3 '17 at 18:53
• @einpoklum Just had a look into IEEE and ACM, they also have a draft option. And for the many others, most of them will be based on one of the standard ones, so they will know the draft option, too. – user36296 Apr 3 '17 at 19:20

## 2 Answers

Yes, using the \overfullrule command in your preamble. This has to be set to a length (I usually set it to be ~5pt) and it prints out a black rectangle near overfull hboxes.

Here is an example (words are not meaningful, but this way they can't be hyphenated, thus creating overfull hboxes)

\documentclass{article}
\overfullrule=5pt
\begin{document}
adfhafashfk jahsdkjash kjsahdkjashdkjhshskjdhkjhdkjdsh qwioeuqwoieuoqwiueoiw kwlqjewqejoqwiejowqiejoqwjewoqiejowqej oqwj oeijwqoie jqwoj eiwoi jeowijewjeejejeejlwkkkkkwwllwlwlwlwwlwlwlwlwlw jkljdlajkslsadj
\end{document}


With the fantastic result:

About draft:

Sometimes it's not either advisable or useful providing a draft option to the class, otherwise some packages (e.g. microtype) do not work as they would in the final stages.

• (1) Does \underfullrule work similarly? (2) Is this only for boxes or for lines as well? Or are overfull lines a special case of overfull hboxes? – einpoklum Apr 3 '17 at 19:00
• (1) AFAIK there's no \underfullrule command, or anything of that sort; (2) I don't understand what you mean by lines – Moriambar Apr 3 '17 at 19:11
• to (la)tex, a line of type on a page is a box. so an "overfull hbox" (usually) means a line of type. (but a too-wide display, table or figure is also considered a single "line", so the result of one being too wide will be a {possibly very long) rule in the margin. if draft is not usable for the reason given, you can explicitly set \overfullrule=5pt'. just don't forget to get rid of it when you're ready to compile the final version. – barbara beeton Apr 3 '17 at 21:46

The log file gives the line number of the bad lines so your editor should be able to locate them in the source. in emacs for example this is optional: you can toggle (C-c C-w) TeX-toggle-debug-bad-boxes, and when this is on, after running latex the usual next-error command (C-x) will step through bad boxes moving the cursor at point to each bad line in turn, as if it had had an error. Other editors presumably have similar features (but I only know about emacs)

• But emacs lacks a decent texteditor :) – Skillmon Apr 3 '17 at 21:09
• Isn't it the case that underfull boxes are rarely a problem? At least in flowing text (not math). – user103221 Apr 3 '17 at 23:26
• @RobtA in straight text perhaps. Most common cause of underfull boxes by far is mis-using \\  but avoiding underfull boxes in text depends a lot on how well the hyphenation patterns fit the actual text which varies from language to language and community to community. – David Carlisle Apr 4 '17 at 7:21