# What does mathchar do?

The package `cmll` defines `\with` (looks like '&') as

``````\$ texdef -t latex -p cmll with

\with:
\mathchar"2026

\the\with:
8230
``````

When I take a look at `\&` it is defined as

``````texdef -t latex \&

\&:
\char"26

\the\&:
38
``````

So `\with` and `\&` seem to be different, although the resuls look identical to me. What is the difference?

• I really have no idea how to tag this question. Please feel free to adjust it, if `tex-core` was not appropriate. Feb 23 '15 at 15:26
• Is `\with` allowed only in math mode? Feb 23 '15 at 15:35
• @Sigur A command defined with `\mathchardef` (or `\DeclareMathSymbol`) can only be used in math mode. Feb 23 '15 at 15:49

The four hexadecimal digits `"kfab` in a `\mathchar` specify

• `k` is the atom type (0 = ordinary, 1 = operator, 2 = binary operation, 3 = relation, 4 = opening, 5 = closing, 6 = punctuation, 7 = variable family);

• `f` the math group (font family) where the glyph should be taken from;

• `ab` the slot in the font.

One can use `\mathchar<15 bit number>` directly or define

``````\mathchardef<cs>=<15 bit number>
``````

so, for instance, after `\mathchardef\with="2026` the command `\with` is equivalent to typing `\mathchar"2026` (or `\mathchar8230`, for `"` specifies hexadecimal number).

Typing `\char<8 bit number>` tells TeX to use the character from the current font in the specified slot. However, when in math mode, `\char"ab` is equivalent to saying `\mathchar"00ab`, so ordinary symbol from math group 0 and the same slot. The `\chardef` command is the counterpart of `\mathchardef` and, indeed, `\&` is usually defined as

``````\chardef\&="26
``````

Small lie: it's `\chardef\&=`&`, but it's not really important.

There is a big difference between `\$x \mathchar"2026 y\$` and `\$x \char"26 y\$`, or, with the definitions above

``````\$x \with y\$

\$x \& y\$
``````

In the first case the `&` symbol is spaced as it's good for a binary operation, in the second case no space is added, because we're specifying three ordinary symbols.

• Which font does `\mathchar` use (per default, if there are multiple ones)? Are there other ways than using latex to look at this font? Feb 23 '15 at 18:06
• @moose The font is the one specified in the “math group”; there are four predefined ones: 0 usually is the standard text font, 1 is the math italic font, 2 is the symbol font and 3 is the large symbols font. Math font packages set them. Feb 23 '15 at 18:09
• I also see some packages using `\mathchardef` just to hold a number, like a register (not to ultimately typeset a symbol in mathematics)... why? Edit: Ah I see answers here: Why to store a number via chardef? and here: Macro vs counter: How to store and operate with numbers in TeX without using (too many) counters. Feb 1 '19 at 15:13
• @ShreevatsaR One of Knuth's optimization: you can use a `\chardef` or `\mathchardef` token whenever TeX is looking for a `<number>` Feb 1 '19 at 15:57