# Forcing an equation to a new line

I'm writing a research statement for a research in computer science and I am using Lyx. In some lines I have an inline formula which is broken into two lines in a PDF output file.
I would like that in such cases an automatic line break will appear just before the equation, with the equation moved into the beginning of the next line. All such equations in my case can easily fit in a single line. Actually, they can even make do with less than half a line.
Is there a way to achieve this result and if so how?

• welcome to tex.sx. the `amsmath` package offers a number of ways to place equations on a separate line, but it isn't automatic. if you surround the math by `\[ ... \]` it will be set as a centered display (not needing any package). – barbara beeton Jan 27 '17 at 20:37
• Thank you for your comment which is really also an answer in a way. What I'm probably going to do, among other reasons, because I'm working with Lyx and not with plain Tex and in order not to spend too much time on formatting, is that I'll probably set the formula as a centered display. – Yaniv Tzur Jan 30 '17 at 12:32

i'm not a lyx user, so i don't know what's possible to apply automatically, but i suspect the options are limited.

the recommended way to set (unnumbered) one-line equations as displays is to surround them by `\[ ... \]`. this isn't automatic, but is really little more bother than using `\$ ... \$`. it requires no packages.

if you do find you need to handle multi-line equations, then `amsmath` offers quite a few options.

To prevent line breaks inside inline-math constructs, you could replace all instances of

``````\$ <some formula> \$
``````

with

``````\${ <some formula> }\$
``````

This will make all inline math formulas into what TeX calls "math atoms" (molecules?!), and TeX never breaks math atoms across lines.

If you go this route, you should probably also execute either `\raggedright` or `\sloppy` to avoid getting overfull lines and/or lines with very bad interword spacing. As @barbarabeeton has pointed in a comment, rather than introduce a line break immediately ahead of the long-ish inline math formula, you should probably take a different approach altogether, viz., typeset the long-ish formulas as displaymath entities, on lines all by themselves.

• like the other answer, this will often result in bad text spacing or overfull lines. i think the only reliable mechanism is to treat the math strings as displays. spacing and alignment can be adjusted to avoid the extra vertical space and centering if desired. – barbara beeton Jan 28 '17 at 2:19
• @barbarabeeton - Thanks! I've added a paragraph to warn about the perils of overfully lines and poor interword spacing. – Mico Jan 28 '17 at 7:02
• This method should not be used, because it additionally freezes the spaces in the formulas. If used together with `\raggedright` it is just more complicated than setting to infinity the relevant penalties. – egreg Jan 28 '17 at 9:51
• Thank you for your answer but I'm probably not going to apply the original answer in order to avoid the risk of bad formatting and because I'm working with Lyx rather than plain Tex and this attempt at a solution might overly complicate things. Rather, as suggested above, I'll probably just use a centered display. – Yaniv Tzur Jan 30 '17 at 12:36

I believe that changing the `\relpenalty` and `\binopenalty` values in your document would prevent line breaks. A simple example that would prevent all line breaks is below.

``````\relpenalty   = 10000
\binoppenalty = 10000
``````