40

~ stands for a non-breaking space, and \mbox{<text>} creates a box with text in it that cannot be broken (since its a "box").
I understand that \mbox has broader application than ~ (e.g. when you put not text only, but also pictures in it).

However, considering text only, what is the difference between ~ and \mbox? And when should I use the one or the other in following circumstances?

  • A phone number: 012345678901
  • A page number abbreviation : p.210sq.
  • A two-parts family name : Jean de LaFontaine
  • Punctuation: (in french) «Oh là là: c'est un cul-de-sac!»
  • 11
    \mbox produces non-streatchable spaces, while ~ produces a space which stretches as the other spaces on the same line – User Apr 19 '16 at 8:14
  • 1
    A good use for \mbox with text is to disallow breaking of things that contain hyphens. For example, I write a lot of documents that contain our company's part numbers. An example is \mbox{040-24800}. – James Apr 19 '16 at 11:03
52

In none of the presented cases you should use \mbox.

  • Phone numbers should use a kern, such as 123\,456\,7890

  • Things such as p.~210~sq.\@ should use a tie (note the \@ in order not to make the period as a sentence ending one)

  • Names should use ~: Jean de~La~Fontaine (you may want to remove the first ~ if line breaking becomes otherwise unfeasible)

  • Space before French punctuations (but after «) should be a kern; the only exception is the colon, where ~:<space> should be used.

For French punctuation, leave the job to babel-french that usually works well.

What's the difference between p.~210 and \mbox{p. 210}? In the former case, the space is not considered to be after a sentence ending period and it still participates to stretching and shrinking together with all other spaces in the line. In the latter case, the space is fixed and . is sentence ending; so it will probably be much bigger than other spaces in the line. You might cure this by doing \mbox{p.\@ 210} or \mbox{.\ 210}, but still this space will usually be different from other spaces in the same line, because it's rigid.

23

The \mbox is totally unbreakable, i.e., it does not allow hyphenation nor any other breaks.

The tilde ~ inserts an unbreakable space, but does not affect the breakability of its left and right neighbours. So in La~Fontaine the Fountaine part can still be hyphenated.

So, the tilde is easier to type and to read in the TeX source and it has the other advantage that its neighbours can be hyphenated.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.