# siunitx disturbs spacing of \, in math with xelatex

In the following example - compiled with XeLaTeX - the spacing of \thinspacing/the value of mu (used by \,) is disturbed if \SI is used in the math before:

\documentclass{article}

\usepackage{unicode-math}
\usepackage{siunitx}

\begin{document}

$1\mskip20mu1$ $\Leftarrow$

$\SI{1}{1}$

$1\mskip20mu1$ $\Leftarrow$

$1\mskip20mu1$

$\SI{1}{1}$

$1\mskip20mu1$ $\Leftarrow$

$a\SI{1}{1}$

$1\mskip20mu1$

\end{document}


unicode-math

A similar effect can be seen if \SI is the first command:

\documentclass{article}

\usepackage{unicode-math}
\usepackage{siunitx}

\begin{document}

$a\SI{2}{2}1\mskip20mu1$

$\SI{2}{2}a1\mskip20mu1$

\end{document}


# Observations

• it doesn't happen with LuaLaTeX,
• it doesn't happen with all fonts (unicode-mathCambria is not affected, but xits is),
• one must use \SI in math and in math mode,
• if only happens if \SI is the only thing in the math (which means that it is probably not a very problematic problem),
• at the next math, the value is again correct.

Has someone an idea if it it a XeTeX, a siunitx or a fontspec/unicode-math math bug?

Minimising the example by 'one round' we can remove siunitx but not unicode-math

\documentclass{article}

\usepackage{unicode-math}

\begin{document}

$1\mskip20mu1$

\hbox{\everymath{\scriptscriptstyle} $a\,b$}

$1\mskip20mu1$

$1\mskip20mu1$

\end{document}


As you'll see, I've taken the 'core' of \text to put in just enough code to cause a failure.

-
It's 'not my fault': try $\text{$1\,1$}$ (which is internally used by siunitx) and you should see the same, although not with $\mbos{$1\,1$}$ – Joseph Wright Feb 5 '14 at 10:17
I was just going to remark that this is clearly a bug report. However, it is not, because the question is: Whose bug it is? (this comment should hopefully prevent anyone trying to close it as off-topic as a bug report) – yo' Feb 5 '14 at 10:33
@JosephWright It works if one load amsmath, but not if one load a renamed amsmath, so probably some of the "if package amsmath loaded" code of unicode-math is the problem. – Ulrike Fischer Feb 5 '14 at 11:13
I've not traced it all through, but with my latest test version I'm strongly suspecting a XeTeX bug. There's no macro code causing the failure, and I think the \scriptscriptsize size for a muskip is leaking from the \hbox when unicode-math activates Unicode math handling in XeTeX. (Release LuaTeX ha a muskip size bug which means that the cases will be different.) – Joseph Wright Jan 26 '15 at 8:01
@LaRiFaRi: I answered my question and made a bug report at the xetex tracker. – Ulrike Fischer Aug 5 '15 at 12:52