为了让 LaTeX 的使用更轻松、更快捷(尤其是更快捷),我在序言中借助 xspace 定义了一些宏。它们在文本模式下按预期工作,但在数学模式下却无法正常工作。
我如何在数学模式下使用宏?
或者在这种情况下我不应该使用 xspace?
问题图景
平均能量损失
\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
这与 无关siunitx
。在数学模式下,空格无论如何都会被忽略,因此 由 添加的空格\xspace
属于此类别。
如果您希望在数学模式中不自动插入空格,则必须使用“反斜杠空格”明确添加:
\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}