What is the "right" way of determining the math class (e.g. ordinary/0, relation/3, closing/5, etc.) of a non-keyboard symbol?

Something like \oplus is easy enough to guess, but I wasn't immediately sure about \upuparrows (enter image description here); on the one hand, my impression is that arrow symbols are generally treated as relations, while I know that Knuth's up-arrow notation uses it to denote a binary operation.

I tried writing


but this produced an error:

Bad character code (13332) \the\mathcode\upuparrows

Note that 13332 is the right number: writing

\def\test{\mathchar 13332 }

does not produce an error, and gives the double-up-arrow symbol. And 13332 is equal to the hex number 3414, which starts with 3, correctly indicating that it is a relation.

How did I end up figuring out that is correct? Because I ran the following extremely silly code:


\setbox7=\hbox{$a\upuparrows b$}

mathord    &  \setlength{\test}{\wd0}  \the\test\\
mathop     &  \setlength{\test}{\wd1}  \the\test\\
mathbin    &  \setlength{\test}{\wd2}  \the\test\\
mathrel    &  \setlength{\test}{\wd3}  \the\test\\
mathopen   &  \setlength{\test}{\wd4}  \the\test\\
mathclose  &  \setlength{\test}{\wd5}  \the\test\\
mathpunct  &  \setlength{\test}{\wd6}  \the\test\\[0.1in]
ACTUAL     &  \setlength{\test}{\wd7}  \the\test\\



enter image description here

Obviously this is not the right way of going about it either; besides the silliness, there is the issue that several math classes can have the same length.

Now in contrast, writing \the\mathcode`< worked fine; it produced 12604 (which is 313C in hexadecimal, which has leading digit 3 = mathrel, as it should).

I did try adding the backtick in front of \upuparrows, but this just produced the errors

Improper alphabetic constant \the\mathcode`\upuparrows
Missing $ inserted \the\mathcode`\upuparrows
Missing $ inserted

(Incidentally, what is the backtick doing exactly? I am reading the TeXbook and the examples given there use it, e.g. enter image description here but I couldn't find an explanation.)

I also tried the approach that seemed to be suggested by this TeX.SE thread:


but that produced

Missing number, treated as zero \the\mathcode\string\upuparrows
  • 1
    The backquote denotes an "alphabetical constant": `b when TeX is looking for a number denotes the position of b in the ASCII code. It can be used only in front of a character or a (not necessarily defined) control sequence whose name consists of one character. Thus \the\mathcode`\\ is legal although not very useful because it gives the mathcode of the backslash. Only characters have a mathcode.
    – egreg
    Apr 22, 2013 at 20:02

2 Answers 2


Use \show\upuparrows instead. You will get this response:

> \upuparrows=\mathchar"3414.

Now you need to decode that. As explained in section 21.1 of TeX by Topic, that code is parsed as "xyzz where x is the math class, answering your question right there – while y is the font family number and zz is the position of the character in the font.

To add a little detail, \mathchar is a command to typeset the given character with the given class and family. And as you might guess, that is how non-keyboard characters are handled. Only actual characters have an associated \mathcode.


Rather than showing each command separately you can get TeX to show you the current math list structure.


$ a \sin b \upuparrows \times 2   \showoutput \showlists $


Produces, on the terminal and log:

### math mode entered at line 5
.\fam1 a
..\fam0 s
..\fam0 i
..\fam0 n
.\fam1 b
.\fam4 ^^T
.\fam2 ^^B
.\fam0 2

which tells you in that expression \upuparrows produced a mathrel atom followed by the mathbin from \times.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .