TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

This is kind of a follow up to this question. Consider the sample code:

A text with an inline equation which is broken in to two parts
but is not wanted right here $v_{initial} = 11111$.

Without any modification, TeX splits the inline formula after the = sign. One can modify the code adding braces around the content of the inline math: ${v_{initial} = 11111}$, then TeX does not split the formula, thus it runs in the right margin and TeX complains with an overfull box.

Now comes LuaTeX and its callback that can alter the paragraph building algorithm (post_linebreak_filter). Would it be possible to add some lua code, triggered when TeX enters an inline math expression, that would see that

  • 11111 is "too" short to come up alone in the next line
  • v_{initial} is not that "long" so it could be pushed to the next line without leaving "too much" blank on the line
  • and that it would be worth adding some glue before the inline math so that the whole inline math would be at the beginning of the second line?
share|improve this question
Just increase the value of \relpenalty. LaTeX sets it to 500, a larger value would make less desirable a break after the equals sign. – egreg Jan 18 '13 at 14:51
@egreg Sorry, but I do not think it does what I want. I want the whole inline expression on the next line, and depending on the width of the splitable parts. – cjorssen Jan 18 '13 at 15:07
You're starting from a false assumption: $v_{initial}=$ is almost 40pt, so it can't be considered "small", being more than 10% of a standard line width. – egreg Jan 18 '13 at 15:48
@egreg Ok. But sometimes, you get the same behavior with inline math like $1+1=2$. – cjorssen Jan 18 '13 at 15:52

enter image description here

I don't think you need lua callbacks here:

A text with an inline equation which is broken in to two parts
but is not wanted right here $v_{initial} = 11111$.
share|improve this answer
Wouldn't \relpenalty=10000 suffice? :) – egreg Jan 18 '13 at 15:38
yes but you might mis-type the number of 0s Better to whack it with a sledgehammer: tex.stackexchange.com/questions/10850/… :-) – David Carlisle Jan 18 '13 at 15:40
Ok, but sometimes you do want a line break at binop and relop, when the inline math is wider than a simple 2 = 1 + 1. – cjorssen Jan 18 '13 at 15:49
BTW, I tested the suggestion @egreg made in comment and no line break occurred. I must have done a silly mistake. Thanks for the \maxdimen trick. – cjorssen Jan 18 '13 at 15:50
@cjorssen 10000 is enough to prevent breaks , the default is 500 there are a lot of numbers in between which just discourage breaks with varying degrees of strength so that breaks are still allowed (eg if the expression is wider than textwidth) although even 9999 isn't enough to prevent the break in your example unless you make everything else even more sloppy than \sloppy – David Carlisle Jan 18 '13 at 16:01

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.