I am finalizing a document. There are a few underfull vbox I just cannot figure out where they are. Sometimes it is easy to figure out which page is underfull vbox from the log file, but sometimes it is not so easy. Is there any easy way to visualize the underfull vbox just like the visualized little bar for an overfull hbox?
[Tex/LaTex] How to visualize the underfull box in final output PDF files
line-breakingtypographywarnings
Related Question
- [Tex/LaTex] What are underfull hboxes and vboxes and how can I get rid of them
- [Tex/LaTex] What are the finishing touches you put to a document
- [Tex/LaTex] how to suppress “Underfull \vbox (badness 10000) … while \output is active”
- [Tex/LaTex] Underfull hbox in tabular
- [Tex/LaTex] Underfull \vbox – how to find offending page
Best Answer
Well, I've found a way to show the undefull boxes in the pdf. Nothing is impossible with luatex!
The process is a bit convoluted, but it works (at least in my minimal examples). But let see first the results. This is a little example document I prepared which produces a couple of Underfull vboxes.
The example
Paragraphs marked with 2 and 3 are typeset in a
\vbox
too large, and the same for the first\vbox
inside the table. lualatex complains:And the result pdf shows how paragraphs 2 and 3 are too separated, because TeX had to stretch the
\parskip
between them to make them fill the\vbox
.The desired result
Now, I add a single line in the preamble of the above tex source:
After compiling again with
lualatex
, the new pdf shows the underfull vboxes in red:How was it done
My first idea was to process from lua the
log
file generated by tex, and search for the "Underful vbox" messages, take note of the line number in which they happened and the hook into theprocess_input_buffer
callback to insert at that line some kind of mark. I had some problems trying to implement this approach, so I asked for help.In the end, I got convinced that this approach was unfeasible because LuaTeX does not provide callbacks to get the messages being written in the log, and in addition
file.open
andfile.read
cannot be safely used from lua to read toelog
file because that file is open and TeX is writting in it at same time.So I tried a different approach. I hooked into
vpack_filter
callback, which is called when TeX has material to be packed in a vertical box and it is about to start packing it. From lua I have the opportunity of examining that box (in fact the node list composing it), throw it, let it pass, or modify it by inserting, deleting or changing nodes, all before TeX start the actual packing.So, from this function I call
node.vpack
which "emulates" what TeX is about to do, and returns the result of the packing and the badness value. So I can read this badness and decide if it is a "underfull vbox" (badness > 100). In this case I modify that list by inserting nodes which "push" the red color at the beginning and "pop" it at the end. I learned from the source code of chickenize package some nifty tricks to do so.The code
This is the content of
DetectUnderfull.lua
file:Update: Thanks to uli for detecting a problem with LuaTeX 0.76.0, and to Paul Gessler for fixing it.