6

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:

enter image description here

\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?

2
  • 7
    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
    – daleif
    Commented May 7, 2021 at 5:38
  • 4
    ...or display de equation, which in this case is sufficiently complex to be put on a line by itself, in my opinion.
    – Rmano
    Commented May 7, 2021 at 5:42

1 Answer 1

7

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}

enter image description here

and with $P = \min(1, \exp(-\beta[U(\vec{r'}) - U(\vec{r})])$

enter image description here

with .. (1,\allowbreak .. you can get

enter image description here

or, enter image description here

2
  • 1
    +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
    Commented 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.
    – 2xMax
    Commented May 7, 2021 at 19:52

You must log in to answer this question.

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