# xspace's spacing with siunitx macro does not work in math mode

To make life with LaTeX easier and faster (especially faster), I defined some macros in the preamble with the help of xspace. They work as intended in text mode, but fail in math mode.

How could I make use of the macro in math mode?

Or should I not use xspace in this case?

## MWE

\documentclass[
a4paper
]{scrreprt}

\usepackage{
lmodern,
siunitx,
xspace
}

\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}

\newcommand{\DistThirtyMM}{\SI{30}{\milli\metre}\xspace}

\begin{document}
Some words to show that the macro for \DistThirtyMM works.

And then there is the math mode: $$a\cdot \DistThirtyMM x$$ some more words.
\end{document}

• Spaces are ignored in math mode, unless explicitly added. Jul 25 '14 at 14:11
• Wouldn't it work as wanted if in math mode you used \DistThirtyMM{} instead? Jul 25 '14 at 15:02

This has nothing to do with siunitx. Spaces are ignored anyway in math mode, so the one added by \xspace falls in this category.

If you want a non automatically inserted space in math mode you have to explicitly add yourself with “backslash space”:

\documentclass[
a4paper
]{scrreprt}

\usepackage{
lmodern,
siunitx,
xspace
}

\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}

\newcommand{\DistThirtyMM}{\SI{30}{\milli\metre}\xspace}

\begin{document}
Some words to show that the macro for \DistThirtyMM works.

And then there is the math mode: $$a\cdot \DistThirtyMM x$$ some more words.

And then there is the math mode: $$a\cdot \DistThirtyMM\ x$$ some more words.

And then there is the math mode: $$a\cdot \SI{30}{\milli\metre} x$$ some more words.

And then there is the math mode: $$a\cdot \SI{30}{\milli\metre}\ x$$ some more words.
\end{document}