0

I often use small inline math notation such as $\FuncName(a)$ in paragraphs. These math expressions are smaller than some words, so I think it's fine to inline them instead of putting them on their own line with something like double $$.

But LaTeX will allow these short math notations to hang over the edge of a justified paragraph. I don't like this.

Here's an example:

\documentclass{article}
\newcommand{\FuncName}{\mathsf{FuncName}}
\begin{document}
Nam dui ligula, fringilla a, euismod sodales, esollicitudin vel, ewisi. $\FuncName(a)$
Culpa vitae magnam quis quidem. Tempora quis vitae in odio eligendi ea ea. Qui non cumque velit. Non et quis rerum voluptate. Dignissimos consequuntur impedit aut at explicabo dolor. Reiciendis a fuga et blanditiis et impedit architecto
\end{document}

Here's that code compiled

As you can see, the inline math is outside of the box for the paragraph. I'd like LaTeX to simple put the inline math on the next line. I'd also accept another solution where the paragraph looks nice, but I really don't want to have to do any positioning manually or put the math on its own line.

My question is really similar to this question (How to automatically linebreak an inline math formula?) but the solution in that question was to split up the inline math into text mode pieces, which I can't do in my case.

Here's another example where I would want a line break inside the math mode:

\documentclass{article}
\begin{document}
Nam dui ligula, fringilla a, euismod sodales, esollicitudin vel, ewisi. $\{a,b,c,d,e,f\}$
Culpa vitae magnam quis quidem. Tempora quis vitae in odio eligendi ea ea. Qui non cumque velit. Non et quis rerum voluptate. Dignissimos consequuntur impedit aut at explicabo dolor. Reiciendis a fuga et blanditiis et impedit architecto
\end{document}

enter image description here

2
  • If you allow shorter lines why not use \raggedright? Commented May 10, 2022 at 21:34
  • @PrzemysławScherwentke I want the text to be justified.
    – Grifball
    Commented Aug 10, 2022 at 17:39

1 Answer 1

3

This is not really related to math mode, you will see the same with any non-hyphenatable text. To allow this to be inline without changing the surrounding words to fit, you need to allow white space to stretch more. The simplest way to do that is to use \sloppy

enter image description here

\documentclass{article}
\begin{document}
\sloppy
Nam dui ligula, fringilla a, euismod sodales, esollicitudin vel, ewisi. $\{a,b,c,d,e,f\}$
Culpa vitae magnam quis quidem. Tempora quis vitae in odio eligendi ea ea. Qui non cumque velit. Non et quis rerum voluptate. Dignissimos consequuntur impedit aut at explicabo dolor. Reiciendis a fuga et blanditiis et impedit architecto
\end{document}
4
  • 2
    \slippyness is sometimes necessary, but please don't inflict it on an entire document. Apply sloppypar to only those paragraphs that need it, even though that can't really be done until the text is reasonably final. Commented May 10, 2022 at 22:08
  • @barbarabeeton well sure and in practice, I'd probably use a less sloppy sloppy perhaps just fiddling wih \emergncystretch but just establishing the general principle that to break the lines wihout changing the text you have to give something up, most likely a constraint on how much space can stretch. Commented May 10, 2022 at 23:01
  • thanks @DavidCarlisle, I've been using \sloppy for a bit now and started realizing that I want my equations to line-break in more locations without having to manually line-break them myself. For example, the \{a,b,c,d,e,f\} would make the first line look better if it were line-broken between the b and c. Is there maybe a way to define my own rules on where a math equation should be line-broken?
    – Grifball
    Commented Aug 10, 2022 at 17:36
  • you would need to define , as math active (like ') and define it to do ,\linebreak[0] so that it allows line breaks (or simpler use a command like \mycomma instead of , defined by \newcommand\mycomma{,\linebreak[0]} @Grifball Commented Aug 10, 2022 at 18:15

You must log in to answer this question.

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