在下面的例子中,为什么 Spam 这个词出现了四次?
$ cat mwe.tex
\documentclass{beamer}
\usepackage{breqn}
\newcommand{\spam}{\textrm{Spam}}
\begin{document}
\begin{frame}
\[ \spam \]
\end{frame}
\end{document}
...我该怎么做才能只获得它一次?
我在用着:
- LuaTeX,版本 beta-0.80.0 (TeX Live 2015) (rev 5238),
- beamer 2015/01/05 3.36,
- breqn 2015/08/11 v0.98d。
答案1
\mathchoice
如果包中的 重新定义mathstyle
满足 LuaTeX 的,则会触发此问题\mathstyle
,来自包mathstyle
:
\def\mathchoice{%
\relax\ifcase\mathstyle
\expandafter\@firstoffour % Display
\or
\expandafter\@firstoffour % Cramped display
\or
\expandafter\@secondoffour % Text
\or
\expandafter\@secondoffour % Cramped text
\or
\expandafter\@thirdoffour % Script
\or
\expandafter\@thirdoffour % Cramped script
\else
\expandafter\@fourthoffour % (Cramped) Scriptscript
\fi
}
\ifcase
期望一个数字并继续扩展,直到找到一个不包含数字(非数字)的标记。因此,\expandafter
当数字仍在读取时,第一个“显示样式”的案例“0”在错误的时间被调用。A\relax
停止了这种情况并应该修复了这个问题:
\documentclass{beamer}
\usepackage{breqn}
\makeatletter
\def\mathchoice{%
\relax\ifcase\mathstyle\relax
\expandafter\@firstoffour % Display
\or
\expandafter\@firstoffour % Cramped display
\or
\expandafter\@secondoffour % Text
\or
\expandafter\@secondoffour % Cramped text
\or
\expandafter\@thirdoffour % Script
\or
\expandafter\@thirdoffour % Cramped script
\else
\expandafter\@fourthoffour % (Cramped) Scriptscript
\fi
}
\makeatother
\newcommand{\spam}{\textrm{Spam}}
\begin{document}
\begin{frame}
\centering
$\displaystyle \mathchoice{D}{T}{S}{s}$
\[ \spam \]
\end{frame}
\end{document}