Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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?

share|improve this question
3  
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

1 Answer 1

up vote 11 down vote accepted

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.

share|improve this answer
2  
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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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