# What's special about \def\\ vs. \def\mksp?

In the following definitions, \\ captures a space token but \mksp does not.

\documentclass{article}
\begin{document}
{\def\\{\global\let\sp= } \\ }
{\def\mksp{\global\let\spx= } \mksp }
\show\sp
\show\spx
\end{document}


When run, the output indicates that \sp is a space token but \spx is }.

> \sp=blank space  .
l.5 \show\sp

?
> \spx=end-group character }.
l.6 \show\spx


Why is the \\ special? Where does Knuth discuss this in the TeXbook?

-
You get the same with commands like \. or \; or \?. In short: if the command name consist of a non-letter. In this case TeX knows that the command name ends after the one char. With \mksp the space after the name is needed to end the command name so it is goobled. –  Ulrike Fischer Nov 16 '11 at 18:15

The difference is that \\ is a control symbol, while \mksp is a control word.

In the second example, the space after \mksp doesn't go over the tokenization process, which comes even before expansion: the tokenization rules have the consequence that spaces after control words are discarded during the process, which is the same by which multiple spaces are reduced to one or spaces at the beginning of a line are discarded. On the contrary, a space after a control symbol is not ignored. So, after tokenization, TeX sees (I'll denote by • a space token that survives the tokenization pro)

{\def\\{\global\let\sp=•}•\\•}


After the definition, the space after the closing brace is ignored, because it's seen in vertical mode; then \\ is expanded and TeX confronts with

\global\let\sp=••}


The space after the = is ignored by rule, but the second one remains. After that the closing brace does its duty.

In the second case, what TeX is presented with is

{\def\mksp{\global\let\spx=•}•\mksp}


which becomes, after executing {, the definition and the expansion of \mksp,

\global\let\spx=•}


Again, the space is ignored by rule, so what \spx is defined to be is }`, exactly as you got. The compiler will also say that a group has not been closed.

-
The TeXBook discusses this in Chapter 8, pages 46 - 47, where he describes the tokenizing algorithm. Thanks! –  Justin Bailey Nov 16 '11 at 18:45