4

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?

2
  • 1
    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, 2016 at 9:25
  • 3
    @egreg as usual goes for the verbose long form, a more compact definition is \lowercase{\let\spacecharC= } % :-) Mar 21, 2016 at 9:36

2 Answers 2

2

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/ %
or
\edef\tmp{\let\noexpand\spacetoken= \space}\tmp
or
\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.

0
6

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

or

\let\spacechar=x

or

\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= }\\ }
                              ^   ^

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .