31

I am new to La Tex and wondering when to use a tilde, or a \mbox? A tilde prohibits a line break and so does \mbox, so when to use one or the other? For example, should I use:

\mbox{words to kept together} 

or,

 words~to~be~kept~together
Caramdir
  • 89,023
  • 26
  • 255
  • 291
Leena
  • 521

1 Answers1

36

There are probably other reasons, but I believe the space given by a ~ can stretch or shrink as other spaces in the line, while an \mbox gives you a fixed box, with fixed spaces.

And words joined with ~ can still be hyphenated, while an \mbox won't.

\documentclass[a5paper]{article}
\sloppy
\begin{document}
A text with~some~unbreakable~spaces might stretch to jusssssssssssstify the line.
A text \mbox{with some unbreakable spaces} might stretch to jusssssssssssstify the line.
A~text~with~unbreakable~spaces~might~be~hyphenated~if~necessary.
\mbox{A text with unbreakable spaces might be hyphenated if necessary.}
\end{document}

enter image description here

Jellby
  • 3,323
  • 5
    I'd add that \mbox{...} is very useful for avoiding line breaks in a particular word. – egreg Jul 02 '12 at 10:45