194

I can use ~ to produce a non-breaking space. But it is too large for me, and I would like a non-breaking space of the size of \, for example. Is it possible ?

3
  • 49
    The space inserted by \, is non breaking.
    – egreg
    Commented Oct 10, 2012 at 11:55
  • upss... :) sorry. Commented Oct 10, 2012 at 13:23
  • 17
    Don't worry, it's been a good occasion for describing some lesser known TeX features. For example, why \, is a non breaking space.
    – egreg
    Commented Oct 10, 2012 at 13:24

1 Answer 1

242

There are two kinds of spacing that TeX can use: skips and kerns. The first sort of space can be flexible (the interword space is a skip, for instance), while the second one is rigid.

Both disappear at line breaks, but TeX will never break a line at a kern (unless it's followed by a skip), while it's willing to do it at skips. Therefore

word\,word

would never be broken across lines.

The command \, inserts a kern, precisely it's defined (in text mode) as

\kern 0.16667em

(where 1em is approximately the width of an uppercase "M", whence the name, or near the font size in points); so the space inserted by \, is 1/6 of an em.

Conversely, ~ is defined as a skip: its definition is \nobreakspace, which translates into

\leavevmode\nobreak\ 

(the last is "backslash+space"). There will be no line break at it, because the skip inserted by \<space> is preceded by so high a penalty that breaks are impossible (\nobreak translates into \penalty 10000).

You can space by inserting \kern yourself, but using a macro is preferable. If you need that the space is non breakable and flexible, use the same trick as ~:

\nobreak\hspace{.16667em plus .08333em}

would insert a space normally equal to 1/6 of an em, but stretchable to 1/4 of an em.

I left out the \leavevmode because such spaces should always be inserted between words. LaTeX takes that precaution, because users might use ~ in order to indent lines (which is not the best thing to do, though).

5
  • \nobreak\hspace{.16667em plus .13333em} would insert a space normally equal to 1/6 of an em, but stretchable to 1/5 of an em. Are you sure that's right? Maybe I just am not familiar with the syntax, but it seems like that space would be stretchable to about 0.3em. If you want stretchable to approximately 1/5 em, shouldn't that be .16667em plus .03333em (which works out to .19997em)?
    – user
    Commented Oct 11, 2012 at 14:11
  • 2
    So is \kern 0.16667em the same as \nobreak\hspace{.16667em}?
    – StrongBad
    Commented Oct 11, 2012 at 16:21
  • 3
    @DanielE.Shub Not really: \unskip wouldn't remove it (there's \unkern).
    – egreg
    Commented Oct 11, 2012 at 17:16
  • why is wrong with "inserting \kern yourself"?
    – snoram
    Commented Oct 24, 2018 at 9:16
  • 4
    @snoram It's not wrong, but a macro is preferable, so you don't have to chase across your document for \kern if you realize that you have to change to 1/4 of an em instead of 1/6.
    – egreg
    Commented Oct 24, 2018 at 10:05

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .