# LaTeX is crossing its limits

Pardon for the funny title. I have a large report in the middle of which there is a sentence

Let $\mathcal{L}$ : $\mathcal{O}$ $\rightarrow$ $\mathcal{S}$ be a function


This shows in the report as in the third line of the following image. Now I want the function declaration L:O->S to be in one line. Can anything be done?

Also, there is another line in the report

For example, a square lattice has the security classes, $\mathcal{S}$ = \{\textit{Unclassified},\textit{$Secret_1$},\textit{$Secret_2$},\textit{Top Secret}\}.


This line shows in the report like this

I don't want S = {Unclassified, Secret1, Secret2, Top Secret} to go beyond the margins. MWE for this problem is:

\documentclass{report}
\begin{document}
For example, a square lattice has the security classes, $\mathcal{S}$ = \{\textit{Unclassified},\textit{$Secret_1$},\textit{$Secret_2$},\textit{Top Secret}\}.
\end{document}


Can anything be done?

-
Welcome to TeX.SX! You can have a look at our starter guide to familiarize yourself further with our format. Please help us to help you and add a minimal working example (MWE) that illustrates your problem. It will be much easier for us to reproduce your situation and find out what the issue is when we see compilable code, starting with \documentclass{...} and ending with \end{document}. –  Christian Hupfer Apr 18 '14 at 9:26
Try [ \mathcal{L} \colon \mathcal{O} \to \mathcal{S} ], to get the correct spacing around the colon. –  Benjamin McKay Apr 18 '14 at 9:29
@ChristianHupfer By one line, I meant not to be broken into two lines. Rather like this: Blah blah L:O->S blah. I could have given it multiple spaces so that it completely shifts to next line but LaTeX would take that as a single space. –  kamalbanga Apr 18 '14 at 9:40
First of all, you shouldn't use math like that, then Latex doesn't space it correctly. Instead $\mathcal{L} \colon \mathcal{O} \to \mathcal{S}$ (the \colon is just a : with punctuation spacing). As for the second: $\mathcal{S} = \{\textit{Unclassified},$ $\textit{Secret}_1,$ $\textit{Secret}_2,$ $\textit{Top Secret}\}$. This doesn't answer your question, but is an improvement, I think. –  Manuel Apr 18 '14 at 9:57
You could simply put an \allowbreak after every comma in the list, say, \textit{foo},\allowbreak\textit{bar}... :) –  Paulo Cereda Apr 18 '14 at 9:57

Another option, as suggested in the comments, is to turn the formula into a displayed one by replacing the $ pair with $ and $. There is a third solution which is: forcing it to be unbreakable wrapping it with a \mbox, or inserting ad-hoc line-breaks. I do not recommend doing this is the other options can work and if you do choose this one consider doing it only when the text is stable and only needing finishing touches. This is because if later changes remove the need for the manual adjustments you may end up with a suboptimal or plain wrong layout. # Commas not breaking lines in math mode The second problem is caused by the fact that commas in math mode do not mark a point where you can break a line. To solve this I use the following macro: \mathchardef\breakingcomma\mathcode\, {\catcode,=\active \gdef,{\breakingcomma\discretionary{}{}{}} } \newcommand{\commabr}[1]{\mathcode\,=\string"8000 #1}  It is a bit complicated to explain but it defines a command \commabr which you can use to enclose regions of formulas where you want the comma to mark a "breakable point" (example: $S = \{\commabr{\mathit{Unclassified}, \mathit{Secret1}, \mathit{Secret2}, \mathit{Top Secret}}\}$) - I understand the second problem, so I think I will just give spaces after comma rather than using this macro. Thanks btw. – kamalbanga Apr 18 '14 at 9:54 You don't need a \mbox to make inline math unbreakable: You can use a pair of braces: ${a=b=c=d}$ – Ulrike Fischer Apr 18 '14 at 10:26 @UlrikeFischer I didn't know that! useful tip! – Bordaigorl Apr 18 '14 at 10:28 How can the mbox (or pair of braces) lead to suboptimal layout if the text changes in the future? – T. Verron Apr 18 '14 at 10:50 "Unclassified", et al., really should be set with either \mathit or \textit. as it is, the letters in those words will be italic, but will have the spacing of variables. – barbara beeton Apr 18 '14 at 13:42 The second problem can be solved by giving spaces next to comma. Like this: $\mathcal{S}$= \{\textit{Unclassified}, \textit{$Secret_1$}, \textit{$Secret_2\$}, \textit{Top Secret}\}.

@MarcvanLeeuwen Ok. So I think I should do something like \textit{foo},\allowbreak\textit{bar}... `. –  kamalbanga Apr 18 '14 at 12:10