6

Sometimes a line break inside inline math is acceptable and sometimes it detracts from the message. I'd like to be able to see exactly where such breaks (meaning any line break during inline math mode) occur in my final-minus-epsilon draft and decide if any action should be taken to rearrange sentence wording, etc. (based on my manual inspection of the instance). I know there are automated ways to prevent line breaking in inline math, but I don't want to do that. The document is huge, so it's not OK to just manually look through it for such breaks.

Is there a way to mark where these things occur? Ideally by line number in the log. But also OK would be some sort of visual or searchable signal that stands out in the PDF, if somehow that is easier.


Added later: David Carlisle's answer to a related question points out that \binoppenalty and \relpenalty are the badness contributors that matter. So can we log when these are used?

5
  • 1
    In tex.stackexchange.com/questions/113795/… he manually added highlighting and position macros to the inline math. A similar technique could specifically test for line breaks, BUT you would have to modify every single inline math expression to add the test. Commented Aug 13, 2015 at 4:10
  • 1
    You can set \overfullrule=5pt for "visual signal in PDF" and you can search "Overfull \hbox ... in lines ..." in the log file.
    – wipet
    Commented Aug 13, 2015 at 6:14
  • @wipet Can you explain a bit how that would work? If the inline math is line breaking, how would \overfullrule help? Or are you suggesting that I also prevent inline math from breaking at the same time? I wonder though if doing that might push all the math to the next line, and then I'd still miss such instances when I reverted to turning these things off. Commented Aug 13, 2015 at 8:02
  • Please define more clearly what you mean by "acceptable" and "unacceptable" line breaks inside inline math math material. Are you concerned mostly with overfull lines, or are other criteria in play as well?
    – Mico
    Commented Aug 13, 2015 at 19:18
  • @Mico I think you are misunderstanding the question. I will manually determine what is acceptable by inspecting each instance and considering the context (and then if I want to change something, manually making some kind of change). To that end, I want to be able to jump to each instance of any line break within math mode without having to manually look at each right edge of each line of text on each page. I'll edit the question to hopefully clear this up. Commented Aug 13, 2015 at 19:26

2 Answers 2

8

You didn't mention what constitutes "acceptable", in terms of line breaks inside inline math material. The best I can therefore suggest is that you choose a method for highlighting all inline math material with some lurid color. That way, any unfortunate line break will jump out at you immediately.

If it's mostly overfull lines you're concerned with, you could add the option draft to the \documentclass instruction. That way, a big fat "slug", i.e., a solid rectangle, will be inserted at the end of each overfull line.

enter image description here

\documentclass[draft]{article}
\usepackage[x11names]{xcolor}
\everymath{\color{DarkOrchid3}} % Is "DarkOrchid3 lurid enough?!
\begin{document}

Completely unimportant text 
$ABC_{1234} = ABC_{1234} + ABC_{1234} - ABCDEFGHI_{1234} \times ABC_{1234} - ABC_{1234} \times ABC_{1234} - ABC_{1234} + ABC_{1234} - ABC_{1234} + ABC_{1234} - ABC_{1234} + ABC_{1234} - ABC_{1234}$
Some more text.

Completely unimportant text 
$ABC_{1234} = ABC_{1234} + ABC_{1234} - ABC_{1234} + ABC_{1234} - ABC_{1234} + ABC_{1234} - ABC_{1234} + ABC_{1234}$
Some more unimportant text.
\end{document}
6
  • Now that the slug is there (and lurid), this is good. Without the slug, it still looked like I'd have a lot of manual inspection to do. I'll accept this if there isn't a log-based answer forthcoming. Thanks! Commented Aug 13, 2015 at 19:30
  • Actually it looks like this still leaves a lot of manual inspection. The color coding helps for sure, but mostly it's still "look at the right edge of one line, and look at the left of the next, and repeat". The slug only comes in when there's an overfull box. Commented Aug 23, 2015 at 8:06
  • @alex.jordan - You will remember that I had asked you for guidance as to what constitutes "acceptability" in line-breaks. You replied that you wanted to be able to have an easy method for inspecting manually (ocularly?!) each and every line break that occurs while in inline math mode. However, you didn't state what the things were -- other than overfull boxes -- that bothered you. Given this rather broad objective, the best I was able to come up with was the color-coding idea. If you want to automate the search process, you need to specify what exactly is acceptable or unacceptable.
    – Mico
    Commented Aug 23, 2015 at 8:23
  • I want to jump to each instance of a line break that occurred during math mode. One way to do this would be for the log to tell me every line number in the source where it happens. Another way would be to insert an obtrusive slug where it happens, which is a strong enough visual signal to give each page less than a second of review time. But in a document full of math mode, with coloring all over, this color coding approach is still asking me to inspect one line at a time, making each page take say 10 seconds, and making the whole process on 200 pages be mentally taxing. Commented Aug 23, 2015 at 8:46
  • Don't worry about "acceptability"; that's irrelevant to my request and only came up as background. If you feel that is important, then I haven't done a good enough job explaining the question. Commented Aug 23, 2015 at 8:46
3
\documentclass{article}

\showoutput
\begin{document}


one two three four $1+2+3=3+2+1$ five six
one two three four $1+2+3=3+2+1$ five
one two three four $1+2+3=3+2+1$ five
one two three four $1+2+3=3+2+1$ five
one two three four $1+2+3=3+2+1$ five
one two three four $1+2+3=3+2+1$ five
one two three  $0+1+2+3+4=4+3+2+1+0=10=5\times(5-1)/2$ 
one two three four 
five six   seven  eight nine ten
\end{document}

Produces

enter image description here

so several inline math lists, two of which are broken over a line.

The log file lists lots of things but in particular it logs the start and end of every inline math (\mathon and \mathoff) and the end of every line (\rightskip). (Actually it does not log the start of math that starts a line as that node is discarded)

So we are only interested in lines that have those commands.

You can search for those with grep or any search tool, in this case

grep '\\mathon\|\\mathoff\|\\rightskip' file.log

produces

....\mathon
....\mathoff
....\mathon

....\glue(\rightskip) 0.0

....\mathoff
....\mathon
....\mathoff
....\glue(\rightskip) 0.0
....\mathoff
....\mathon
....\mathoff
....\glue(\rightskip) 0.0
....\mathon
....\mathoff
....\mathon

....\glue(\rightskip) 0.0

....\mathoff
....\glue(\rightskip) 0.0
....\glue(\rightskip) 0.0

So it is easy to see there are exactly two \rightskip appearing before \mathoff corresponding to two broken math lists.

Note that some \mathon have been discarded at line breaks which complicates a fully automatic test, but the information is basically there. alternatively if you know that binoppenalty and relpenalty are unique you just need to spot those before \rightskip so the two lines that end in a broken math list are both marked by

....\penalty 500
....\glue(\rightskip) 0.0

Here I just used grep and highlighted the rightskip in math by eye but you could find them automatically given a few lines of perl or python or lua or whatever.

1
  • certainly reliable, but not for the faint of heart or the newbie. Commented Mar 11, 2018 at 1:59

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .