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.

How should I put command so that my inline math environment could be together. For example 0<x<1 is break up into two parts, 0< and x<1 in the next line.

share|improve this question
    
This is not a good idea but you can try to use \mbox{}. –  Sigur Aug 28 '12 at 0:10
    
thank you sigur, it works too. –  azlan aznam Aug 28 '12 at 0:54
    
In the future, please always add a fully compilable minimal working example (MWE) that illustrates your problem. –  canaaerus Sep 14 '12 at 5:53
add comment

2 Answers

up vote 8 down vote accepted

There are some strategies that you could use: enclosing the expression inside braces, or boxing it, but in some cases this can produce overfull boxes. Most of the times the best solution is to rephrase the text where the formula appears so that a line break doesn't occur.

An example where things go right:

\documentclass[draft]{article}

\begin{document}

Text text text text text text text text text text text text text text te $0<x<1$

Text text text text text text text text text text text text text text te ${0<x<1}$

Text text text text text text text text text text text text text text te \mbox{$0<x<1$}

\end{document}

enter image description here

And another one, where things go wrong (notice the overfull boxes):

\documentclass[draft]{article}

\begin{document}

Text text text text text text text text text text text text texttexttex $0<x<1$ text text text text text text text text text text text text text text text text text text

Text text text text text text text text text text text text texttexttex ${0<x<1}$ text text text text text text text text text text text text text text text text text text

Text text text text text text text text text text text text texttexttex \mbox{$0<x<1$} text text text text text text text text text text text text text text text text text text

\end{document}

enter image description here

In the situation illustrated in the last example, \sloppy could be used to prevent the bad boxes, but now some lines of text will stretch and the interword spacing will look ugly:

\documentclass[draft]{article}

\begin{document}

Text text text text text text text text text text text text texttexttex $0<x<1$ text text text text text text text text text text text text text text text text text text

{\sloppy Text text text text text text text text text text text text texttexttex ${0<x<1}$ text text text text text text text text text text text text text text text text text text\par}

{\sloppy Text text text text text text text text text text text text texttexttex \mbox{$0<x<1$} text text text text text text text text text text text text text text text text text text\par}

\end{document}

enter image description here

As egreg mentions in a comment both \mbox{$0<x<1$} and ${0<x<1}$ will cause the spaces around the < not to share their stretching and shrinking with the line they end in; $0<\nobreak x<1$ is better for avoiding a line break; possibly add \nobreak also after the second <.

The best solution, most of the times, is (as I already said) try to rephrase the text where the formula appears so that a line break doesn't occur.

share|improve this answer
    
thank you so much for your advice, putting {} works ok with my problem. thank you so much again. –  azlan aznam Aug 28 '12 at 0:53
    
@azlanaznam You're welcome! I'm glad I could help. –  Gonzalo Medina Aug 28 '12 at 1:04
2  
\mbox{$0<x<1$} and ${0<x<1}$ are equivalent and wrong, because the spaces around the < won't share their stretching and shrinking with the line they end in; $0<\nobreak x<1$ is better for avoiding a line break; possibly add \nobreak also after the second <. –  egreg Aug 28 '12 at 9:24
    
@egreg thank you for sharing the knowledge, I learned a new thing. thank you again. –  azlan aznam Aug 28 '12 at 13:06
add comment

You could set the \relpenalty higher (it is already quite high; 500 in plain). For example,

\relpenalty=10000

would try to never break line with relational class mathematical character. I was actually having a hard time getting TeX to break a line with the example $0<x<1$ with the default setting, so to test it I set the penalty to zero.

Another inline math penalty is \binoppenalty for binary class mathematical characters, so to suggest to TeX to try and never break inline maths, one could set them both to 10000. Of course, TeX will have big trouble finding line-break points if you have lots of long inline maths with that setting.

share|improve this answer
add comment

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.