Given a control sequence \z
that was defined like \let\z=z
, how do you get the catcode the character z
had at the time \z
was defined?
The obvious solution
{\catcode`z=12 \global\let\z=z}
\the\catcode`\z
seems to work at the first glance, but it gives the wrong result 11
because '\z
isn't interpreted as the previously defined control sequence but just another denotation of the character code of the letter z
.
Using a different control sequence name makes it obvious
{\catcode`z=12 \global\let\thez=z}
\the\catcode`\thez
when it fails with
! Improper alphabetic constant.
This question deals with a similar problem, getting the character code of such a control sequence, but I don't see a way to use it for this problem as \meaning
only returns characters of category 12 and 10.
\token_case_catcode
.)