12

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

\documentclass{article}
\usepackage{amssymb}
\begin{document}
\the\mathcode\upuparrows
\end{document}

but this produced an error:

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

Note that 13332 is the right number: writing

\def\test{\mathchar 13332 }
$\test$

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:

\documentclass{article}
\usepackage{amssymb}
\begin{document}

\newlength{\test}
\setbox0=\hbox{$a\mathord{\upuparrows}b$}
\setbox1=\hbox{$a\mathop{\upuparrows}b$}
\setbox2=\hbox{$a\mathbin{\upuparrows}b$}
\setbox3=\hbox{$a\mathrel{\upuparrows}b$}
\setbox4=\hbox{$a\mathopen{\upuparrows}b$}
\setbox5=\hbox{$a\mathclose{\upuparrows}b$}
\setbox6=\hbox{$a\mathpunct{\upuparrows}b$}
\setbox7=\hbox{$a\upuparrows b$}

\begin{tabular}{ll}
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\\
\end{tabular}

\end{document}

producing:

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:

\documentclass{article}
\usepackage{amssymb}
\begin{document}
\the\mathcode\string\upuparrows
\end{document}

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 '13 at 20:02
13

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.

4

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

\documentclass{article}
\usepackage{amssymb}
\begin{document}

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

\end{document}

Produces, on the terminal and log:

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

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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