Take the 2-minute tour ×
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.

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. L:O->S 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

S={U,S1,S2,TS}

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?

share|improve this question
    
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 at 9:26
1  
Try [ \mathcal{L} \colon \mathcal{O} \to \mathcal{S} ], to get the correct spacing around the colon. –  Benjamin McKay Apr 18 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 at 9:40
2  
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 at 9:57
3  
You could simply put an \allowbreak after every comma in the list, say, \textit{foo},\allowbreak\textit{bar}... :) –  Paulo Cereda Apr 18 at 9:57

2 Answers 2

up vote 8 down vote accepted

Avoiding line breaks in inline formulae

For the first problem, it maybe requires a little rearranging/rephrasing.

You can for example rephrase the previous sentence so it is a little longer and the formula (along with its introducing "Let") gets pushed into the next line.

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}}\}$)

share|improve this answer
    
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 at 9:54
4  
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 at 10:26
    
@UlrikeFischer I didn't know that! useful tip! –  Bordaigorl Apr 18 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 at 10:50
1  
"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 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}\}.
share|improve this answer
7  
This is a fundamentally wrong approach. You should not be going in and out of math mode all the time; a single pair of dollars surrounding the whole formula should suffice. If you need additional break points inside the formula, there are ways to address that, but interrupting the formula thwarts TeX's attempts to generate proper spacing between symbols. If you prefer placing everything by hand, you shouldn't be using TeX in the first place; there are formula editors out there the will let you (actually force you) to do that. –  Marc van Leeuwen Apr 18 at 11:44
1  
@MarcvanLeeuwen Ok. So I think I should do something like \textit{foo},\allowbreak\textit{bar}... . –  kamalbanga Apr 18 at 12:10

Your Answer

 
discard

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.