39

I'd like to test if the last paragraph has any overfull line.

The naive approach of looking at the \badness once the paragraph is finished does not work, as it will only give the badness of the last line. For instance, the following code shows a badness of 1000000 after Hello, world! but 0 after Hello, world, X!, simply because the last line (X!) is less than 15pt wide.

\hsize=15pt
Hello, world!\par   \immediate\write16{BADNESS=\the\badness} % 1000000
Hello, world X!\par \immediate\write16{BADNESS=\the\badness} % 0
\bye

I use this to do trial typesettings with different line-lengths until finding a line-length which is big enough to avoid overfull lines. Afterwards, I rescale the result to make it fit in the page. This would of course be a terrible idea for text, but the material I'm typesetting is maths over which I have no control and which may occasionally not split nicely into short lines. It is better to get something that is hard to read (small) rather than have it get out of the page. Because of this application, I'm also interested in a way to know the longest line in a paragraph.

lockstep
  • 250,273
  • 2
    Happy new year! Not too sure if it works ok, but give it a try https://github.com/yannisl/phd/blob/master/test-badness.tex – yannisl Jan 02 '15 at 09:05
  • @YiannisLazarides Thanks! If I understand correctly you split the paragraph into lines (with \lastbox, \unskip, \unpenalty) and re-typeset each line into a box of width \hsize to test their badness? You're actually more than half-way to an answer to the question «Obtain \badness or glue adjustment for each line». (I'd say it's more natural to initialize \maxbad globally since later assignments are global.) – Bruno Le Floch Jan 02 '15 at 09:28
  • Why is there \hss in \eatlines? It is not there in \printlines. – Bruno Le Floch Jan 02 '15 at 09:42
  • It is not needed. This is some old code from Will Robertson. \begin{minipage}[t]{55pt} \mbox{} \trypar\hyphenpenalty=-500\looseness=1. – yannisl Jan 02 '15 at 10:20
  • 2
  • While not providing information in the log file, \hfuzz=0pt \overfullrule=7pt would give a visual clue for overfull lines in the document.
  • The https://www.ctan.org/pkg/adjustbox package might be helpful to solve the original problem (fit some math to some width).
  • – Stephen Jun 21 '15 at 14:08
  • @erreka Have you read the question?! This is hardly an easy option for automatically generated texts! – yo' Nov 03 '15 at 23:00
  • My apologies: I misunderstood the question. – jarnosc Nov 03 '15 at 23:44