# Why is \active defined as \char13 (and not 13)?

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?

• @Gradient you see the same in many places eg \newbox\foo (or the latex \newsavebox{\foo} then \foo is defined by \chardef (or sometimes \mathchardef in lualatex) – David Carlisle Mar 25 '17 at 20:33
• @DavidCarlisle Ah, I learned something new. My prior comment (which I have now removed) referred to changing catcode within a document, not plain TeX sources. – user103221 Mar 25 '17 at 21:32

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.)

• I found in the TeXbook, page 271: "When a <chardef token> or <mathchardef token> is used as an internal integer, it denotes the value in the \chardef or \mathchardef itself." This explains why \active used in catcode assigment is like 13 and not \char13`. – Gradient Mar 25 '17 at 20:25