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

8

1 Answer 1

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}
3
  • From the comments this isn't really what OP is looking for though
    – user202729
    Jan 6, 2022 at 16:27
  • @user202729 comments came later:-) \sloppy could be replaced by \RaggedRight from ragged2e (which is generally preferable output) Jan 6, 2022 at 16:28
  • @user202729 short line version added Jan 6, 2022 at 16:54

You must log in to answer this question.

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