[Tex/LaTex] How to prevent inline math from entering the margins on the right

inline()math-mode

I'm writing a document (double columned, if it matters), and it seems that while normal text wraps just fine to fit the structure, when I use inline math, it tends to violate the page margins.

For example, in the image below, the R_{uniform} part should begin at a new line, as it has no room at the current line.

enter image description here

The code used for this theorem is:

\begin{theorem}\label{thm:different-qualities-improved-ranker}
  There exists a \frf{} $\UniformRanking$ such that for any \qm{} $\qualityMatrix 
  \in[0,1]^{[2]\times[2]}$, the \diffqpg{} \DQPGDEF[\dqpg][2][2][\qualityMatrix] 
  [\UniformRanking] achieves \poa{} of at most $1.7$.
\end{theorem}

Where

\newcommand{\UniformRanking}{R_{uniform}}

Is the command for R_{uniform}.

How do I force it to start a new line when needed, but never to exceed the line length?

Best Answer

Try to imagine, how the text would look like, if TeX had decided to put the inline math in the next line … the interword spacing in the first line would be too high. Since TeX is a perfectionist, it rather ignores the right margin, than allows this to happen and also notifies the user by inserting a warning overfull hbox in the log.

You now have a few possibilities to solve this:

  1. Rewrite the text. In this case you probably want it to be longer in front of the formula. This is the best solution in my opinion, because you don't have to compromise typographically.
  2. Add \\ in front of the formula. This breaks justification of course.
  3. Allow TeX to be more sloppy maybe by using \begin{sloppypar}…. Our TeX-Gurus might help you here… I'm not really familiar with the internals of TeX and how to adjust them, sorry ;-)

Apart from those general solutions, how about changing the the formula? An index that long does not look good … especially in conjunction with other formulas. $R_{\mathrm{uni}}$ for example fits really well … typographically at least. (By using find&replace it's also quite easy to change this throughout the whole document)

Related Question