Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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?

share|improve this question
2  
\char"97 doesn't give an a even in a document. "91 is a hex-value, you would need either \char"61 or \char91. –  Ulrike Fischer Jun 23 '12 at 14:21
    
Thanks for the clarification, @UlrikeFischer - cheers! –  sdaau Jun 23 '12 at 14:28

2 Answers 2

up vote 7 down vote accepted
 {\uccode`A=97
    \uppercase{\typeout{== A ==}}}

will typeout the character with character code 97

share|improve this answer
    
Many thanks for that answer, @DavidCarlisle - cheers! –  sdaau Jun 23 '12 at 15:08
    
not catcode though :-) last time I checked TeX didn't have that many catcodes --- character code –  Frank Mittelbach Jun 23 '12 at 15:19
    
@FrankMittelbach, fixed thanks:-) –  David Carlisle Jun 23 '12 at 15:24
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. github.com/kieranclancy/texref.git –  codebeard Jul 8 '12 at 16:32

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.

share|improve this answer
    
Many thanks for posting this answer, @FrankMittelbach - cheers! –  sdaau Jun 23 '12 at 15:21

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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