0

For some reason, this code:

\documentclass{standalone}

\usepackage{polynom}

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

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

gives an error:

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

but this code:

\documentclass{standalone}

\usepackage{polynom}

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

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

compiles fine ... into an empty document. (test.dvi PS 69x13 69x13+0+0 16-bit sRGB 513B 0.000u 0:00.000.)

Full error output:

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.

My goal is to perform calculations on polynomials without unnecessarily repeating calculations or LaTeX code (to calculate properties of rational functions). Full code in 2019-1-3.bac.tex.

  • most latex commands may not be used in \edef, what do you want it to do here? – David Carlisle Jan 7 at 23:27
  • I added a clarification. – Solomon Ucko Jan 7 at 23:30
1

Most latex commands can not be used inside \edef. Clearly, the commands of this package do not work by expansion and can not be made to do anything sensible in \edef.

To see why you get the error consider

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

that defines \tmp so that if executed it defines \zzz to be abc but

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

\edef expands token by token without doing any assignments, so \def expands to \def then \zzz expands, or at least would expand, but as it has no definition you get an undefined control sequence error.

  • Is it possible to use \noexpand to get it to work? Or is there a better way to reuse the result of \polyfactorize? – Solomon Ucko Jan 7 at 23:39

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.