8

If I have a letter/character, I can output its ASCII value using \number and backtick command:

*\typeout{\number`a}
97

What do I do if I have "97", and I want to show "a" in terminal? I have thought of \char - but note that \char typesets, it doesn't output to terminal (removed \char"97 hex usage as per comment):

*\typeout{\char97}
\char 97

What is the right command to use here?

sdaau
  • 17,079

2 Answers2

10
 {\uccode`A=97
    \uppercase{\typeout{== A ==}}}

will typeout the character with character code 97

David Carlisle
  • 757,742
  • not catcode though :-) last time I checked TeX didn't have that many catcodes --- character code – Frank Mittelbach Jun 23 '12 at 15:19
  • 1
    I have written a small tool called texref which can give quick information about category codes and character information, and maybe other things too in future. If you think it's useful, perhaps consider including it in your answer.

    https://github.com/kieranclancy/texref.git

    – codebeard Jul 08 '12 at 16:32
5

If you have hex value rather than the ascii code value then you can use ^^61 to represent a. The hex digits have to be in lowercase (for the letters a-f). If you have only the ascii code number then you have to build your own table (if you want to mix such output with other material) or use the ingenious trick with \uccodeby David, but the latter doesn't really mix well with anything in addition. A simple way to build such a table would be

\makeatletter
\def\asciichar#1{\@nameuse{ascii@\number#1}}
\@namedef{ascii@97}{a}
\@namedef{ascii@98}{b} ... % and all the others
\makeatother

You could add some safety checks to see if the internal command is actually defined etc.