In plain TeX, we have
\chardef\active=13
\catcode`\~=\active
I thought a catcode should be assigned a number between 0 and 15, but \active is \char13
. So how does it work?
Would \catcode`\~=13
also work?
There are three issues here, two about performance and one about 'safety'. A \chardef
'd token is parsed slightly faster than TeX looking for the end of a number, so \active
is a little better in that regard than an explicit 13
. Today this is not so much of an issue, but was in the past. Similarly, \active
is a single token in terms of memory, whereas 13
is two tokens: there's a saving in using the former. Once again,, memory usage today isn't a big problem but was in the past.
Perhaps more important is the rule that TeX keeps looking for the end of a number when digits are given explicitly, whereas for a \chardef
token this doesn't happen. So for example
\catcode`\a=134
gives an error but
\catcode`\a=\active4
isn't. In an explicit use that's not likely to be an issue but if we
\def\foo{\catcode`\a=\active}
then \foo 4
is OK, whereas for an explicit 13
we need a space or \relax
(so yet another token).
(TeX is 'looking for a number' in this context so a \chardef
or \mathchardef
token is fine in place of an explicit run of digits. Making \active
a macro expanding to 13
has the some of the same issues as an explicit value.)
\active
used in catcode assigment is like 13 and not \char13
.
\newbox\foo
(or the latex\newsavebox{\foo}
then\foo
is defined by\chardef
(or sometimes\mathchardef
in lualatex)