# What happens in \begin{document} when using unicode-math?

Here's a MWE:

\documentclass{minimal}
\usepackage{unicode-math}
\let\x\times
\begin{document}
\let\y\times
$a \x b$
$c \y d$
\end{document}


The command \times apparently changes meaning at the \begin{document} line, because the alias made to it before that line does not work properly:

This does not happen without the unicode-math package. What am I seeing here? I have always thought of the \begin{document} as a rather innocent marker, which only delimits the end of preamble (disallowing further use of certain commands), but it apparently has side effects at least in interaction with this package.

I'm using xelatex if this makes any difference.

• Lots of packages hook into \begin{document} (via \AtBeginDocument or \AtEndPreamble). Some because they need to execute code when all packages have been loaded (to avoid effects of package loading order) or when other packages have done their thing. I think it is not unusual for some font setup to happen at or around \begin{document}. May 15 '20 at 6:44
• \begin{document} is not an innocent marker. If you want to see what is happening there put \tracingmacros=1 before is and \tracingmacros=0 behind it. Compile and then look in the log. (in a current tex system expect around 2.700.000 lines of log, stuff with __um in the name is from unicode math). May 15 '20 at 6:48

When you do \let\x\times the meaning of \times is still the LaTeX default; indeed, if you add

\show\x


after the \let operation, you get

> \x=\mathchar"2202.
l.4 \show\x


If you further add \showthe\textfont2 before the first \], that is, in the display where \x is used, you get

> \TU/latinmodern-math.otf(2)/m/n/10 .
l.7 $a \x b\showthe\textfont2$

You see that \x instructs TeX to make an operation symbol (first byte is 2) taking from the font in the math family 2 the character at slot "02. And indeed the log file shows
Missing character: There is no ^^B in font

Why doesn't unicode-math change the meaning of \times when it is loaded? Because it needs to know the entire math and text font setup, which can only be detected at begin document.