In plain TeX, we have


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


gives an error but


isn't. In an explicit use that's not likely to be an issue but if we


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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.