3

I have big tex document that was created for a4 paper, I wanted to change a4 to a5. After doing so, latex rendered some inline math in kinda awkward way:

Something something x + y + z =
f(x).

I would prefer if instead of breaking on operators and white spaces latex would move whole inline math to the new line

Something something
x + y + z = f(x).

I know I can do that manually with \\ or wrap it some new environment, but it would take SO much time.

I also found this:

\binoppenalty=\maxdimen
\relpenalty=\maxdimen

but it didn't help and made things even worse because sometimes a part of the math would simply go beyond page border.

So, is there a simple and painless way to automatically move inline math to a new line instead of breaking it in awkward places?

MWE:

\documentclass{report}

\begin{document} Something Something Something Something Something Something $ x + y + z = f(x)$ \end{document}

bad inline math breaking

Demiler
  • 77

1 Answers1

6

You can set the penalties to prevent breaks within math then allow the white space outside math more flexibility to avoid overfull boxes

enter image description here

\documentclass{report}
\binoppenalty=10000
\relpenalty=10000
\sloppy

\begin{document}

\noindent X\dotfill X

Something Something Something Something Something Something $ x + y + z = f(x)$ \end{document}

Or, if you want the preceding line to be short, add white space before each math expression that can fill the line

enter image description here

\documentclass{report}
\binoppenalty=10000
\relpenalty=10000

\everymath{\hskip 0pt plus 1fil\penalty50\hskip 0pt plus -1fil }

\begin{document}

\noindent X\dotfill X

Something Something Something Something Something Something $ x + y + z = f(x)$

Something Something Something Something $ x + y + z = f(x)$ Something Something \end{document}

David Carlisle
  • 757,742