[Tex/LaTex] Forcing math mode to be on the same line

line-breakingmath-mode

I would like to have math mode expressions in dollar signs always to stay on the same line, which is what happens to a sequence of characters with no spaces while not in math mode. Is there a way to avoid having to do this manually by adding line breaks every time (which is terrible style, and gets very messy if one has to go back and change things, altering everithing that comes after)?

Best Answer

The following two lines put at the document preamble should help:

\binoppenalty=10000
\relpenalty=10000

It is a good idea to add \begin{sloppy}...\end{sloppy} to the paragraphs where mathematics appear, so that you allow the lines to be more stretchy. You can allow this stretch globally by putting \sloppy into the preamble.

However, this will completely forbid implicit linebreaks inside inline mathematics. I don't think it is a good idea. Better idea would be to set the pelanties to some value that will discourage the breaks, but allow them if really necessary:

\binoppenalty=3000
\relpenalty=3000
Related Question