# How to prevent inline math from entering the margins on the right?

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.

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?

• It will not help the line breaking but never do R_{uniform}} as soon as I saw your image my head screamed No! math italic is designed to make adjacent letters not look like a word but as a product of variables so never use it for multi-letter words, use R_{\mathit{uniform}} and see the massive space around f go.... Mar 12, 2015 at 16:08

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.
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)