# How do I keep a string of text together without it doing a line break?

I'm writing up a long paper, in which in prose I have various equations. However, I do not want a line break to occur within the equation - I want the equation to stick together. I want to do this without displaying the equation, though. Is there a way to do this?

-
Preventing an in-line math expression to break (boxing it with, for example, \mbox) will produce overfull boxes (the equation will overflow the margin), which isn't desirable; you could try rephrasing the lines containing the equation so that a line break won't occur inside the equation. –  Gonzalo Medina Mar 21 '12 at 2:39
Welcome to TeX.SE! Please consider providing a bit more information about your documrnt's setup (such as the line width) and the average length of the inline equations. –  Mico Mar 21 '12 at 4:19
You could force a line break before the equation with \linebreak[4] –  Vivi Mar 21 '12 at 7:02
if breaking an in-line expression is really bad, an experienced copyeditor would most likely display it without a number -- $...$ will accomplish that. this is usually better than forcing a line break and stretching out the preceding text, or leaving a short line. –  barbara beeton Mar 21 '12 at 13:23

Anything you enclose within an \hbox or the equivalent LaTeX \mbox will not break. However overflowing into the margins is not a good idea. In the minimal below you can see the effect by using the geometry package to show a border around the normal text area.

\documentclass{octavo}
\usepackage[showframe=true]{geometry}
\begin{document}
\mbox{This is an extremely long line. This is extremely long. $a^2+c^2=42$ }
\end{document}


For long equations rather use the breqn package to break them at an appropriate point.

-
+1: I like the idea of using the geometry package to visualize the size of boxes. –  Tatjana Heuser Mar 21 '12 at 9:26
@TatjanaHeuser -- Thanks there are also the layouts and layout packages, you should give them a try. –  Yiannis Lazarides Mar 21 '12 at 9:29

I use a solution to this problem that cannot be used always. Once I finish my work, I go thru the "almost-final" version of the whole paper and when an inappropriate break appears (inside equation, stupidly-broken name/date/... that does not look good in my opinion), I rephrase the text so that this piece appears in the middle of the line. Actually, you have to do the very same thing with overfull \hboxes anyways, but they are at least listed in the log.

Of course this needs you to be the author (of to have the author's permission to do small modifications) and it might be against the idea of TeX/LaTeX in someone's opinion (the idea is that you shouldn't have to do such things manually).

Edit / Added: You can decide to enclose your math into \mbox{...} to disallow like breaking, as Yiannis Lazarides says in his answer. In this case the inline math will often go out of the line. You can visualize these overfull boxes by adding [draft] parameter to your \documentclass (works for most standard classes).

-
+1 This is the best solution. That is what I do as well. I have an overfullrule1pt normally during drafts and helps me visualize as I go along. Between various edits they tend to disappear. –  Yiannis Lazarides Mar 21 '12 at 10:41
I could mention the draft option that visualizes overfull \hbox, I'm adding that. –  yo' Mar 21 '12 at 10:50
@tohecz -- if you've read the texbook, you'd know that this is exactly what don knuth recommends (or at least practices himself). so it's not "against the idea of tex". –  barbara beeton Mar 21 '12 at 13:25
@barbarabeeton Thanks for details, I changed "is completely" to "might be" ;) –  yo' Mar 21 '12 at 13:26