45

I am using the acmsmall template and my inline formulas are being broken at equal signs and arrows; how can I prevent them from being typeset like that globally (i.e. without having to put tildes everywhere)?

Screenshot

Martin Scharrer
  • 262,582
  • Possible duplicate: http://tex.stackexchange.com/questions/10850/prevent-latex-to-break-an-inline-math-equation – diabonas Mar 25 '11 at 14:49
  • 4
    @diabonas: Good that you found that question. But here it's about avoiding these line breaks globally. The answers to that other question don't address this. – Hendrik Vogt Mar 25 '11 at 14:52
  • 3
    I added globally to the title, so that is clearer – NoWhereMan Mar 25 '11 at 15:14
  • 1
  • @cabohah That's the question linked in the first comment. While the two are related, they are not duplicates as this one is about achieving the effect globally and the other is about a single formula. I would therefore not classify them as duplicates. – Andrew Stacey Apr 16 '23 at 18:42
  • @AndrewStacey If you put the lines of David's answer or to the document preamble it is a global solution! See also Andreas' adaption And on the other side, two of the answers below are not globally. – cabohah Apr 16 '23 at 18:44
  • 1
    @cabohah Duplicate answers doesn't make duplicate questions. With duplicates, the principle is to think about someone searching for the question afresh. That person might well distinguish between a solution that works globally as to one that works on an individual question. There could be a third question that clearly asks both versions of the question, in which case each of these could be closed as a duplicate of that (it's not uncommon for these meta-questions to be asked), but given how old these questions are then I'd leave well alone. – Andrew Stacey Apr 16 '23 at 18:55
  • @AndrewStacey The other question wasn't explicitly a question for a local solution. So IMHO it is already the general question. – cabohah Apr 16 '23 at 20:05

3 Answers3

51

Increase the penalty for line breaks at relation symbols and binary operators:

\relpenalty=9999
\binoppenalty=9999

If you simply include these commands in your preamble (between \documentclass{...} and \begin{document}), it will prevent line breaks in most cases, but in extreme situations, they can still be broken. If you set

\relpenalty=10000
\binoppenalty=10000

equations will never be broken - this may, however, destroy your layout!

diabonas
  • 25,784
25

\mbox{$equation$} is not an answer, unfortunately: the spacing in the equation doesn't grow or shrink together with the other spaces in the line. The "correct" answer is

$LHS=\nobreak RHS$

TeX will choose another break point, if there is one, or warn about an Overfull \hbox

Diabonas's answer shows how to avoid such breaks globally, and correctly warns about the dangers of doing so.

egreg
  • 1,121,712
1

I found the easiest way to simply wrap the equation within curly brackets preceded by a tilde. See the example below.

Instead of

$x = \{x\,|\,x\in\mathbb{R_{\ge0}}\}$

you would write

$~{x = \{x\,|\,x\in\mathbb{R_{\ge0}}\}}$