I encountered what might be a bug in XeTeX (but I would be glad to be proven wrong) while chasing a strange interaction between bytefield, unicode-math, and mathtools.
In general, I do not expect a construction of the form \setbox\mybox\hbox{...} to affect the surrounding code, as long as the box \mybox is not used anywhere else, and the ... do not perform global assignments. I would thus expect the macro \ignore in the example to typeset its argument and do nothing with it. Given what I feed it (simple characters, \mathchar), no assignment should be performed: \everymath and \everhbox are empty; besides, \tracingall confirms this absence of assignments. Despite this, the spacing of the surrounding math mode (which contains no character... this might be a clue) is affected, as can be seen by inspecting the boxes on the terminal.
\global\font\xxx"[latinmodern-math.otf]"\relax
\global\textfont 0\xxx
\newbox\mybox
\def\ignore#1{\setbox\mybox\hbox{#1}}
\def\showhbox#1{\setbox0\hbox{#1}\showbox0\relax}
\tracingall
\showhbox{${\ \over\ }\ignore{a}$}
\showhbox{${\ \over\ }\ignore{$\mathchar`a$}$}
\showhbox{${\ \over\ }\ignore{a}$}
\bye
Odder still, the boxes have sizes
\hbox(3.93732+3.44841)x5.73332
\hbox(3.94+3.45)x5.73332
\hbox(3.94+3.45)x5.73332
The third box, which has the exact same contents as the first, should have the same size, but it does not. I haven't checked whether this problem is specific to the font.
I guess my question is in two parts: (1) am I interpreting correctly what I see when thinking it is a bug? (2) (How) can I perform box assignments safely in XeTeX without affecting the surrounding maths?
\setbox\mybox\hbox{...}has side effects, if LaTeX'scolorpackage is used. Internally it resets the color via\aftergroup, thus the color special can leak out of the box. Therefore LaTeX's box macros add an additional\begingroup...\endgrouplayer. – Heiko Oberdiek May 19 '13 at 17:333.93732+3.44841if I typeset that withpdftex– egreg May 19 '13 at 18:12\of each fraction byastill leads to differences, but they are more subtle (the horizontal rule is 0.4pt high for lines 1 and 3, and 0.39998pt high for line 2). BTW, how can you load that font with pdftex? – Bruno Le Floch May 19 '13 at 18:153.93999+3.45. You also need to define\scriptfont1for getting characters in the formulas. – egreg May 19 '13 at 18:18\fontdimen8\textfont3=10pt(from0.39998pt). This can be seen in the first\showhbox. But after the OpenType font is seen, the traditional TeX font dimen registers seem to be ignored and0.4ptis used. – Heiko Oberdiek May 19 '13 at 18:47