7

It often happens that LaTeX breaks up an inline formula over two lines. However, I find it quite distracting when it breaks an inline formula over multiple pages. For example:

\documentclass{article}
\usepackage{lipsum}
\begin{document}
\lipsum[1-5]

We could go on like this for some time.  We eventually get $x = 15y + 4z + 3w + 2u - 5v$, which is unpleasant.  In contrast, something like $x = 2y + 3z - 4w - 15u - 4v$ is no problem.
\end{document}

Is there a global way (or, failing that, a local way) of forbidding breaks over multiple pages while allowing breaks over multiple lines?

  • Does this help: http://tex.stackexchange.com/a/18299/10898 – azetina Aug 22 '12 at 16:20
  • @azetina: How should that help? That one prevents line breaks! (And I don't see how \nopagebreak would help.) – Hendrik Vogt Aug 22 '12 at 16:45
  • Ah well, guess I misunderstood the question but really thought it would have helped the OP as he asked forbidding breaks. – azetina Aug 22 '12 at 16:48
  • 1
    Tricky. Of course you can forbid page breaks in the whole paragraph by adjusting \interlinepenalty. A more involved solution would probably set a high \brokenpenalty (you don't want page breaks at hyphens anyway, do you?), forbid line breaks in inline formulas in general and then re-insert break points using discretionary breaks so you get \brokenpenalty between lines where a formula broke. – Stephan Lehmke Aug 22 '12 at 16:54

1 Answers1

4

enter image description here

\documentclass{article}
\usepackage{lipsum}
\everymath{\vadjust{\nobreak\null}}
\begin{document}
\lipsum[1-5]

We could go on like this for some time.  We eventually get $x = 15y + 4z + 3w + 2u - 5v$, which is unpleasant.  In contrast, something like $x = 2y + 3z - 4w - 15u - 4v$ is no problem.
\end{document}
David Carlisle
  • 757,742
  • How does this differentiate whether or not a formula is line-broken? – Stephan Lehmke Aug 22 '12 at 16:56
  • Wow, why does this work? – Hendrik Vogt Aug 22 '12 at 17:00
  • @StephanLehmke you are so rude about my carefully crafted code:-) Actually the description isn't totally innacurate it has "home time" feel to it now I look again. It actually prevents a page break after the line on which the math starts so would prevent it even if the math didn't split. Probably you could vadjust a penalty at the end of the math to re-allow page breaks in the non split case... – David Carlisle Aug 22 '12 at 17:08
  • OK, this works, but at a (high?) price: It adds an empty line at the end of the page. (@Stephan: ?) – Hendrik Vogt Aug 22 '12 at 17:10
  • It shouldn't add an empty line, but the page falls short because of \raggedbottom try \flushbottom so long as there is some stretch somewhere on the page – David Carlisle Aug 22 '12 at 17:13
  • @DavidCarlisle Sorry the comment wasn't in earnest, it was just too tempting. Another problem might occur if one inline formula line-breaks twice. – Stephan Lehmke Aug 22 '12 at 17:20
  • 1
    @StephanLehmke oh no need to apologise, as I say it was basically accurate anyway. Yes the two break case I had thought of (and chose to ignore) but I just blanked out the no-break case. \def\allowbrk{\vadjust{\penalty0}} \everymath{\vadjust{\nobreak\null}\aftergroup\allowbrk} doen't quit ework though but now it really is home time so I'm offline for a bit – David Carlisle Aug 22 '12 at 17:23
  • 2
    @DavidCarlisle -- you might adjust that example so that the paragraph with math in it has more than three lines so that it won't be affected by either \clubpenalty or \widowpenalty. i know, picky, picky. – barbara beeton Aug 22 '12 at 18:00
  • @David: I'm not sure that I understand your second comment. Could you clarify it, please? – Andrew Uzzell Aug 29 '12 at 08:53
  • As written, Stephen is correct that the code in my answer doesnt work, it prevents page break on a line on which math starts even if the marh ends on the same line. I have left the answer rather than delete as it can probably be made to work, but I am just on android with no tex today so cant test any fix, others may step in.... – David Carlisle Aug 29 '12 at 21:05
  • @David: Sorry, I should have been clearer about my question. Could you clarify your comment about raggedbottom and flushbottom, please? – Andrew Uzzell Aug 30 '12 at 11:06
  • when it works my code prevents a page break at the specified line, but it doesnt change the line breaking. so if the page is full of text lines and hasnt got stretchy space from section heads or displayed lists etc then stopping tex break at that line means the page will be short. if raggedbottom tex will think that ok, but if flushbottom tex will try tostretch to get the new last line to the bottom of the page and will fail, so complain about an underful page – David Carlisle Aug 30 '12 at 17:07