[Tex/LaTex] Usage of LaTeX macro \space (compared with \␣)

spacing

Occasionally I find that internal package code contains the macro \space (defined as \def\space{ } by LaTeX). The most-taught way to produce "explicit" spaces in paragraph text is to use \␣, and I think I haven't seen any source teach \space as a user-level command.

What community knowledge or practices are there regarding the use of \space, especially as compared with \␣?


Here some examples, from the memoir class, which uses \space as well as \␣ in its definitions.

  • For example it defines \newcommand*{\booknamenum}{\space}; this macro is "called between printing the book name and the number".
  • A macro the user is more likely to encounter is \printchapternum; memoir defines it using \renewcommand*{\printchapternum}{\centering\chapnumfont \thechapter\space\space}, with two consecutive \spaces.
  • The class defines \wrappingoff (for use within verbatim environments) via \newcommand*{\wrappingoff}{\def\@xobeysp{\leavevmode\penalty\@M\ }\def\wrapright{}}.

Related:


(An interesting observation regarding visual appearance within code: a\space\space␣b and a\␣\␣b within paragraph text give seemingly the same output (but note that I haven't tested the exact linebreaking behavior). I personally find \space visually clearer than \␣: when I see the letter string "space", I immediately know what it is. Backslashes and spaces are so ubiquitous in LaTeX that the combination \␣ is harder to make out on the screen. That said, such aspects should only be considered in contexts where there is functionally no difference between the two: only then can it be considered a question of coding style.)

Best Answer

\space

\space expands to the normal space token, a character with code of the space (32, 0x20) and the catcode of 10 (space).

  • In opposite of the space token TeX does not collapse several \space commands and it is not ignored after command names, when reading the input. Therefore it is often used in error messages, warnings and other messages. Example of the LaTeX kernel (latex.ltx):

    \gdef\@badlinearg{%
      \@latex@error{%
        Bad \protect\line\space or \protect\vector
       \space argument}\@ehb}
    

\␣

From "The TeXbook" by Donald E. Knuth, "Chapter 25: Summary of Horizontal Mode":

\␣. A control-space command appends glue to the current list, using the same amount that a ⟨space token⟩ inserts when the space factor is 1000.

  • As use case it can be used after commands names for typesetting:

     \TeX\ is a fascinating language.
    
  • It can not be used in messages, because it is not expandable. The backslash would also appear in the error message above, if \␣ instead of \space had been used there.

  • \␣ sets the normal inter-word space (space factor 1000), not the prolonged space after sentences. Thus it can also be used after abbreviations. Example:

    abc.\ is short for abcdef.\@ and
    abcdef.\@ is short for abcdefghi.
    

    Here \␣ is shorter to type (2 characters) than \@␣ (3 characters). (\␣ - like \relax and many other primitives - is independent from the space factor: it neither uses nor changes it, but ignores it and uses 1000 instead. Note that \@␣ resets the space factor.) \space cannot be used, because it sets the prolonged space according to the space factor settings.

Related Question