# Inline equations go off margin

My problem is that sometimes long inline equations go off the margin. For some of the equations, advice from a similar thread of using \raggedleft helped with most of the equations, but it does not work for certain equations and I don't know why: \documentclass[8pt]{article}

\begin{document}

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam sed justo at nisi
interdum eleifend ut vitae libero. Duis cursus Lorem ipsum $P = \min ( 1,{\rm e}^{-\beta [U(\vec{r'})- U(\vec{r})] } )$, consectetur adipiscing elit. Nullam sed justo at nisi

Lorem ipsum dolor sit amet, consectetur adipiscing elit  $s^2 = R^2 + r^2 - 2 Rr \raggedleft [\sin \theta \sin \theta^{\prime} \cos(\varphi - \varphi^{\prime}) + \cos \theta \cos \theta^{\prime} \raggedright ]$. Curabitur dignissim, ligula sed mattis sodales, purus felis viverra metus, id tempor diam magna eget dolor. Nulla pellentesque hendrerit tortor, vel pretium ante cursus vel.

\end{document}


Does anybody know how to force the line-breaking algorithm for equations every single time?

• Of course, you cannot break an exponential, latex is not allowed by default to break at a comma in math, and breaking after the = would cause excessive stretch. So larex does this to catch your attention to fix it. Three solutions, (1) rephrase the text so the break points are different, (2) allow excessive stretch, (3) allow breaking after the comma via (1,\allowbreak May 7, 2021 at 5:38
• ...or display de equation, which in this case is sufficiently complex to be put on a line by itself, in my opinion. May 7, 2021 at 5:42

Loading microtype can solve many of these problems automatically. Other suggestions not mentioned in comments include writing the linear form of the \exp. Also, \allowbreak helps here as suggested by @daleif. Finally you can choose a suitable abbreviation for \beta [U(\vec{r'})- U(\vec{r})], say \beta_r, instead of the full form.

Not related to the main issue, but the 8pt option is not supported in the standard article class.

\documentclass[10pt]{article}
\usepackage{microtype}
\begin{document}

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam sed justo at nisi
interdum eleifend ut vitae libero. Duis cursus Lorem ipsum $P = \min ( 1,{\rm e}^{-\beta [U(\vec{r'})- U(\vec{r})] } )$,
consectetur adipiscing elit. Nullam sed justo at nisi

Lorem ipsum dolor sit amet, consectetur adipiscing elit
$s^2 = R^2 + r^2 - 2 Rr \raggedleft [\sin \theta \sin \theta^{\prime} \cos(\varphi - \varphi^{\prime}) + \cos \theta \cos \theta^{\prime} \raggedright ]$. Curabitur dignissim, ligula sed mattis sodales,
purus felis viverra metus, id tempor diam magna eget dolor. Nulla
pellentesque hendrerit tortor, vel pretium ante cursus vel.

\end{document} and with $P = \min(1, \exp(-\beta[U(\vec{r'}) - U(\vec{r})])$ with .. (1,\allowbreak .. you can get • +1. I think you should also (a) remove the text-mode directives \raggedright and \raggedleft from the second inline equation and (b) replace ^{\prime} with '.
– Mico
May 7, 2021 at 8:33
• Thank you so much, I chose \allowbreak and it worked like a charm and I put it in all long equations. As for \usepackage{microtype}, for some reason, it did not work in my case, maybe because it was in a bullet list. May 7, 2021 at 19:52