![当参数包含 MathOperator 时,\StrSubstitute 会中断](https://linux22.com/image/382165/%E5%BD%93%E5%8F%82%E6%95%B0%E5%8C%85%E5%90%AB%20MathOperator%20%E6%97%B6%EF%BC%8C%5CStrSubstitute%20%E4%BC%9A%E4%B8%AD%E6%96%AD.png)
我正在使用包\StrSubstitute
中的函数,如果任何参数包含我用 声明的数学运算符,则xstring
.tex 文件似乎无法编译。一个最小的失败示例:\StrSubstitute
\DeclareMathOperator
% mfe.tex
\documentclass{article}
\usepackage{xstring,amsmath}
\DeclareMathOperator{\myop}{MyOp}
\begin{document}
$\StrSubstitute{a(B)}{a}{\myop}$
\end{document}
运行pdflatex mfe.tex
无法生成 .pdf 文件,并mfe.log
显示
! TeX capacity exceeded, sorry [input stack size=5000].
\@spaces ->\space
\space \space \space
l.10 $\StrSubstitute{a(B)}{a}{\myop}
$
If you really absolutely need more capacity,
you can ask a wizard to enlarge me.
Here is how much of TeX's memory you used:
1067 strings out of 494953
12733 string characters out of 6180978
173300 words of memory out of 5000000
4419 multiletter control sequences out of 15000+600000
4094 words of font info for 16 fonts, out of 8000000 for 9000
14 hyphenation exceptions out of 8191
5000i,3n,4003p,244b,52s stack positions out of 5000i,500n,10000p,200000b,80000s
! ==> Fatal error occurred, no output PDF file produced!
\myop
相比之下,我只需使用 就可以获得我想要的输出\mathrm
。一个最小的工作示例:
% mwe.tex
\documentclass{article}
\usepackage{xstring,amsmath}
\newcommand{\myoprm}{\mathrm{MyOp}}
\begin{document}
$\StrSubstitute{a(B)}{a}{\myoprm}$
\end{document}
输出结果如下:
你知道这里发生了什么吗?我该如何\StrSubstitute
与我的操作员合作?我被告知这\DeclareMathOperator{\foo}{foo}
比 更好\newcommand{\foo}{\mathrm{foo}}
,但我需要这些命令来配合\StrSubstitute
。