For debugging a complicated macro I would like to print out the catcode of a token. Optimally I would like to have a macro \getcatcode
such that, for example, \getcatcode{a}
would expand to 10
. How can this be done?
I found lots of information about how to set/change catcodes, but nothing about how to read them.
Best Answer
Use
\catcode
together with\the
to get the catcode of the token:Note: The
`
turns the next character into its ASCII number which is required for\catcode
.As custom macro:
Special characters must be escaped with a backslash, e.g.
%
must be written as\%
,#
as\#
etc. It doesn't hurt to write normal letters the same way, e.g.\getcatcode\a
works as well.