# Usage of LaTeX macro \space (compared with \␣)

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.)

• \space is expandable, \␣ isn't. Would you please add some examples? – egreg Jun 18 '13 at 10:38
• I think "the combination \␣ is harder to make out on the screen" is a pro here (says the guy who let you replace \cite{....} with []). – Ulrich Schwarz Jun 18 '13 at 10:54
• @UlrichSchwarz This is a valuable point of view. Let me propose to develop it in the following way: In a context where \␣ and \space are equivalent with respect to the typographic output, the former (\␣) is less obtrusive in user-level (document) code (where textual/mathematical content matters), while the latter (\space) is clearer in a programming context (where function/semantics matters). – Lover of Structure Jun 19 '13 at 12:39
• @egreg I've tried adding some example material; feel free to edit as you please. – Lover of Structure Jun 21 '13 at 6:23

## \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{%
\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.

• I thought \@ after a period ensures that the period is interpreted as an abbreviation period, not a sentence-final period. So .\␣ and .\@␣ should work identically I thought. – Lover of Structure Jun 18 '13 at 22:57
• Unless one means to denote specifically an abbreviation space where double sentence spacing is used, it seems harmless to use \space in place of \␣ if one has such a preference in one's coding style. (The reverse is of course not true, as you and egreg have explained.) Or are there any caveats to this? – Lover of Structure Jun 18 '13 at 23:01
• @LoverofStructure: \␣ does not change the space factor. With default settings the space factor is 3000 after a.\␣, but 1000 after a.\@ . – Heiko Oberdiek Jun 18 '13 at 23:49
• What is confusing is this: \␣ inserts a space as if the space factor were 1000, but you also write that "with default settings the space factor is 3000 after a.\␣". Could you help? – Lover of Structure Jun 29 '13 at 7:44
• @LoverofStructure: Assuming \sfcode of a is 1000, \sfcode of . is 3000, then the space factor is 3000 after the two tokens a.. As \␣ does not change the space factor, it remains 3000 after a.\␣ as it would after a.\relax\typeout{...}. – Heiko Oberdiek Jun 29 '13 at 7:59

The main difference between \space and \␣ is that the former obeys the space factor and the latter doesn't. There is another more subtle difference: \space expands to a space token, while \␣ is unexpandable.

The second aspect is relevant in some special situations: suppose you write

\spacefactor=3000\space x


(in a macro, probably) in order to add a space similar to what follows a sentence ending period; then you'll have a surprise, because no space will appear: a space token following a numeric constant is ignored. Only the first space token is ignored, so

\spacefactor=3000 \space x


would be the correct code.

This means that \␣ and \space are not interchangeable. Ever.


• The case of

\renewcommand*{\printchapternum}{%
\centering\chapnumfont \thechapter\space\space}


is somewhat different and I beg to disagree with how the code is written. If a user redefines \thechapter to expand to \arabic{chapter}., then both spaces will be affected by a space factor 3000, which is probably not what's really wanted. The definition should be

\renewcommand*{\printchapternum}{%
\centering\chapnumfont \thechapter\ \ }


if a double space is desired.

• The redefinition of \@xobeysp performed by \wrappingoff, namely

\def\@xobeysp{\leavevmode\penalty\@M\ }


uses \␣ for the same reason: we don't want a space that's affected by the space factor. The fact that usually in a verbatim environment a \frenchspacing command is issued shouldn't be taken into account: one might exploit \@xobeysp also in other places and this definition uses a predictable space amount.

• Could you proofread the sentence in my question statement with the word "seemingly" and edit accordingly? I'm not sure whether what I wrote there is still true. – Lover of Structure Jun 27 '13 at 9:31
• @LoverofStructure They give the same result because a doesn't force a space factor larger than 1000. They would give different results if, for instance, a period precedes the double space and \nonfrenchspacing is active: with \space\space you'd get two extended spaces, with \␣\␣ only two normal spaces. A line break can be taken only at the left edge of the first space (and the spaces would disappear at the break). – egreg Jun 27 '13 at 9:50
• But that does mean that it's permissible for the user to use \space instead of \␣ for reasons of clarity in personal style in some cases, no? If you disagree with this for reasons of purity of style (for example out of a desire to keep code free of TeX-/LaTeX-internal macros to the extent possible), that's a sound point of view, but I would think that a user who is familiar with space factor mechanics likely knows what he is doing. That would then make it more an issue of documenting he differences between \space and \␣ for the casual user and steering him to do the right thing. – Lover of Structure Jun 30 '13 at 2:05
• The macro \space is not documented in the manual and I don't find real uses for it in a document. – egreg Jun 30 '13 at 8:43