[texhax] Finding ascii value of a parameter

Ross Moore ross at ics.mq.edu.au
Fri Oct 24 16:58:30 CEST 2003

Hello Michael,

On Thu, 23 Oct 2003, Michael Barr wrote:

> The code
> \newcount \temp
> \temp`\a
        ^--------  this \ is redundant
> \showthe\temp
> will produce 97, the ascii code for a.  Is there any way to define a macro
> \ascii with the property that
> \ascii a
> \showthe\temp
> will produce the number 97 in the same way?

Yes, very easily.
You don't even need to use \newcount , which wastes a \count register;
 --- anyway, it's probably more convenient to have a text representation
of the character-code, accessible within a macro:


\ascii a

\ascii &

However to get the \mathcode of mathematical symbols
is trickier; e.g.  \show\alpha
gives              \alpha=\mathchar"10B

To get that hex value "10B you'll need something like:

{\let\z\catcode \let\y\gdef \global\let\zz\count
 \z`m=12 \z`a=12 \z`t=12 \z`h=12 \z`c=12 \z`r=12


 should give you  276  as the \mathcode value.

Hope this helps,

	Ross Moore

> _______________________________________________
> TeX FAQ: http://faq.tug.org/
> TeX newsgroup: http://groups.google.com/groups?group=comp.text.tex
> Mailing list archives: http://tug.org/pipermail/texhax/
> More links: http://tug.org/begin.html
> Automated subscription management: http://tug.org/mailman/listinfo/texhax
> Human mailing list managers: postmaster at tug.org

More information about the texhax mailing list