[Tex/LaTex] How to make text in math mode which would cause an `overfull \hbox` automatically start on the next line

line-breakingmath-mode

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?

\documentclass{article}
\begin{document}

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)$.

\end{document}

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…

Best Answer

\documentclass{article}
\begin{document}

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)$.

\end{document}

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

\cup\nobreak

but leave these decisions for when the document is complete.

Related Question