TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

In cwebmac.tex the following construct is used:

{\def\\{\global\let\spacechar= }\\ }

In cwebmac.tex \spacechar is used only once, in the following code:

\else\ifx\nxt\spacechar \addF\space

Why is \spacechar defined in such a curious manner?

share|improve this question
An equivalent definition with the same number of tokens (but it requires \space to be defined) is \begingroup\edef\x{\endgroup\let\noexpand\spacecharB=\space\space}\x – egreg Mar 21 at 9:25
@egreg as usual goes for the verbose long form, a more compact definition is \lowercase{\let\spacecharC= } % :-) – David Carlisle Mar 21 at 9:36
up vote 2 down vote accepted

The reason was described by @David, we need to say \let\spacetoken=space space in order to set space-token to the control sequence \spacetoken. There are more elegant ways to do this:

\def\tmp/{\let\spacetoken= }\tmp/ %
\edef\tmp{\let\noexpand\spacetoken= \space}\tmp
\lowercase{\let\spacetoken= }

IMHO, most elegant way is never to use \spacetoken. The \ifx test can be done by

\expandafter\ifx\space\nxt ...

so, you need not any \spacetoken.

share|improve this answer

LaTeX has a very similar definition

\def\:{\let\@sptoken= } \:  % this makes \@sptoken a space token

If you want \spacechar to be an implicit x you could use

\let\spacechar x




\let\spacechar = x

as space characters are absorbed after the \spacechar csname and one optional space is ignored after = in the \let syntax.

So to get a space instead of x you need

\let\spacechar =[space][space]

where [space] is a space token. the first one is discarded as an optional space and the second one is taken as the value.

Typing two space tokens is tricky as if you type two space characters they only make one token but you can add them indirectly, one space in the definition of \\ and one space following the \\ token.

 \def\\{\global\let\spacechar= }\\ }
                              ^   ^
share|improve this answer

Your Answer


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.