TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have text within $s following normal text, which runs off the end of the line and creates an overfull \hbox warning.

By default, LaTeX doesn't let the stuff in math mode run off the end of the line, but it creates a line break at a certain place in the code. How do I tell it to instead, by default, put a line break before the text in the $s starts?


Here is text which starts off the line.
We can write $A^n$ as $\bigcup_{a^{n-1} \in A^{n-1}} \{(a^{n-1}, a) \,:\, a \in A \}$.

More text, then I have something like the following
$(-3, 3)^{C} \textrm{ in } A = (-\infty, -3] \cup [3, \infty)$.


I'm getting line breaks after the : in the first sentence, and after the \cup in the second sentence.

P.S. Also, might there be a better way of creating a "such that" sign within a set written in math mode, instead of \,:\,? Ideally, a | would be nice, preceded by and following spaces...

share|improve this question
up vote 3 down vote accepted

Here is text which starts off the line.
We can write $A^n$ as 
\bigcup_{a^{n-1} \in A^{n-1}} \{(a^{n-1}, a) : a \in A \}.

More text, then I have something like the following
$(-3, 3)^{C}$ in $A = (-\infty, -3] \cup [3, \infty)$.


The complicated formula is best set in display mode; no added spaces around the colon, possibly instead after \{ and before \}.

The second case has a big flaw: the word "in" must go outside math mode because it's text. If you want to avoid a break at \cup, write


but leave these decisions for when the document is complete.

share|improve this answer

My answer to this is not to write math like that; whenever I have an "overfull hbox" because of inline math, I realize that said math is way too complicated to be inline and switch it to a display. Basically any math other than single symbols or, I suppose, very simple statements like $x \in Y$, should be displayed simply for reasons of good style.

To nitpick your code itself: if you are writing any kind of serious math you will probably want to use the amsmath package, which provides many helpful features and some improvements to the default ones. In this case, it provides \colon, which is modified to have nice spacing of the sort you have given, and \text, which is a superior alternative to \textrm in math mode.

share|improve this answer
When you say "display," do you mean put inside \[...\] so that the math text is on its own line? I may want to write something as simple as $A = B \cup C$ within a paragraph, and if that happened to be towards the end of the line, LaTeX would automatically insert a line break after the \cup... – jamaicanworm Dec 14 '11 at 6:29
@jamaicanworm: Yes, I mean that. If you want to discourage a particular break you may put braces around that part: $A = {B \cup C}$, which in math mode has the effect of creating an unbreakable \hbox, but beware that this increases the likelihood of the expression becoming too long and making an overfull \hbox. Don't expect anything you put in the text to have total visual integrity; that is exactly what a display is for. – Ryan Reich Dec 14 '11 at 6:33
Actually, \colon is meant for expressions like $f\colon A\to B$. I see nothing wrong with $\{x:x>0\}$, but you can always say \newcommand{\setselector}[2]{\{#1\,:\,#2\}} (or put | in place of :). – mbork Dec 14 '11 at 7:43
@mbork: I actually prefer to use \mid for set-building notation, but @jamaicanworm put some effort into making the colon look good so I figured he'd want the version that does it automatically. In this case, what's good for the goose is good for the gander. – Ryan Reich Dec 14 '11 at 7:49
@Ryan: Using \nobreak (as egreg suggests) is superior to {...} since the former doesn't effect the spacing of the formula. The latter causes the spaces to be set to their natural width. – Hendrik Vogt Jun 24 '12 at 17:29

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.