1

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?

Picture of the Problem

enter image description here

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}
  • 1
    Spaces are ignored in math mode, unless explicitly added. – egreg Jul 25 '14 at 14:11
  • Wouldn't it work as wanted if in math mode you used \DistThirtyMM{} instead? – Alexis Pigeon Jul 25 '14 at 15:02
2

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}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.