Syntax of let with and without =

The syntax for \let is

\let<control sequence><equals><one optional space><token>

so an = and a space are consumed while parsing. This only makes a difference if you want to let something equal to = or a space when you have to use

\let\foo==

as the first = is discarded

<equals> here is texbook syntax for any number of optional spaces, optionally followed by one =.

The latex format has the following line to define \let a command name to be a space token

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

note that \:␣ expands to \let\@sptoken=␣␣ and the = and one optional are discarded so \@sptoken is let to .

If you just went

\let\@sptoken=  %

then the two would be tokenised as a single space as usual and so \let would discard them both as an optional space.

(Using to represent a space in a visible manner in this discussion)


The = is optional, but there are places where it needs to be explicitly used.

Suppose you want to implement a syntax such as \bold{text in bold}. If you look in this witty article by Arsenau, Chen and Eijkhout on TUGboat you'll find

enter image description here

Let's look at the wizard and guru solutions. Both want to remove a brace, but the first one fails in case the user says \bold x. With the guru solution this doesn't happen, because the { is required by the syntax.

More generally, when one wants to remove a token with the \let\next trick, the equal and the space are mandatory. Consider

\def\removeA{\let\next}
\def\removeB{\let\next=}
\def\removeC{\let\next= }

and try them:

\removeA =xyz \show\next
\removeB =xyz \show\next
\removeC =xyz \show\next

In the first case \next will be the character x, not the token immediately following the macro. What about the difference between \removeB and \removeC? Try

\expandafter\removeA\space xyz \show\next
\expandafter\removeB\space xyz \show\next
\expandafter\removeC\space xyz \show\next

Now only the latter makes \next into blank space.

Note that most likely \removeC will appear as the trailing token in the definition of another command, that maybe absorbs an argument, so a space token can be found even without resorting to the trick above for forcing one.

Tags:

Syntax

Macros