edef 中未定义控制序列(带有多项式)

edef 中未定义控制序列(带有多项式)

由于某种原因,此代码:

\documentclass{standalone}

\usepackage{polynom}

\newcommand{\calcRatFunc}[1]{
    \edef\tmp{\polyfactorize{#1}} % The only difference
}

\begin{document}
    \calcRatFunc{x^2 + x - 2}
\end{document}

给出错误:

! Undefined control sequence.
\pld@GetPoly #1#2->\def \pld@pool 
                                  {#1}\def \pld@aftermacro {#2}\pld@GetPoly@ 
l.10     \calcRatFunc{x^2 + x - 2}

但是这段代码:

\documentclass{standalone}

\usepackage{polynom}

\newcommand{\calcRatFunc}[1]{
    \polyfactorize{#1} % The only difference
}

\begin{document}
    \calcRatFunc{x^2 + x - 2}
\end{document}

编译成功...变成一个空文档。(test.dvi PS 69x13 69x13+0+0 16-bit sRGB 513B 0.000u 0:00.000。)

完整错误输出:

This is pdfTeX, Version 3.14159265-2.6-1.40.17 (TeX Live 2016/Debian) (preloaded format=latex)
 restricted \write18 enabled.
entering extended mode
(./test.tex
LaTeX2e <2017/01/01> patch level 3
Babel <3.9r> and hyphenation patterns for 11 language(s) loaded.
(/usr/share/texlive/texmf-dist/tex/latex/standalone/standalone.cls
Document Class: standalone 2015/07/15 v1.2 Class to compile TeX sub-files stand
alone
(/usr/share/texlive/texmf-dist/tex/generic/oberdiek/ifluatex.sty)
(/usr/share/texlive/texmf-dist/tex/generic/oberdiek/ifpdf.sty)
(/usr/share/texlive/texmf-dist/tex/generic/ifxetex/ifxetex.sty)
(/usr/share/texlive/texmf-dist/tex/latex/xkeyval/xkeyval.sty
(/usr/share/texlive/texmf-dist/tex/generic/xkeyval/xkeyval.tex
(/usr/share/texlive/texmf-dist/tex/generic/xkeyval/xkvutils.tex
(/usr/share/texlive/texmf-dist/tex/generic/xkeyval/keyval.tex))))
(/usr/share/texlive/texmf-dist/tex/latex/standalone/standalone.cfg)
(/usr/share/texlive/texmf-dist/tex/latex/base/article.cls
Document Class: article 2014/09/29 v1.4h Standard LaTeX document class
(/usr/share/texlive/texmf-dist/tex/latex/base/size10.clo)))
(/usr/share/texlive/texmf-dist/tex/latex/polynom/polynom.sty) (./test.aux)
! Undefined control sequence.
\pld@GetPoly #1#2->\def \pld@pool 
                                  {#1}\def \pld@aftermacro {#2}\pld@GetPoly@ 
l.10     \calcRatFunc{x^2 + x - 2}

? x
No pages of output.
Transcript written on test.log.

我的目标是对多项式执行计算,而无需不必要地重复计算或 LaTeX 代码(计算有理函数的属性)。完整代码在2019-1-3.bac.tex。

答案1

大多数 latex 命令无法在 中使用\edef。显然,此包的命令无法通过扩展起作用,也无法在 中执行任何有意义的操作\edef

要了解为什么会出现错误,请考虑

\def\tmp{\def\zzz{abc}}

定义\tmp如果执行它定义\zzzabc但是

\edef\tmp{\def\zzz{abc}}

\edef逐个标记地扩展标记而不进行任何分配,因此\def扩展到\def然后\zzz扩展,或者至少会扩展,但由于它没有定义,因此您会收到未定义的控制序列错误。

相关内容