3

I would like to use polynomial macro, just with the standard way. But the coefficients of the polynom are generated by \FPeval or \pgfmathrandominteger commands => the result of polynomial isn't the expected one ...

\begin{document}
\pgfmathrandominteger{\VRcoeffa}{-5}{-1}
\pgfmathrandominteger{\VRcoeffb}{-5}{-1}
\pgfmathrandominteger{\VRcoeffc}{-5}{-1}
\pgfmathrandominteger{\VRcoeffd}{-5}{-1}

$f(x)=\polynomial[reciprocal]{\VRcoeffa,\VRcoeffb,\VRcoeffc,\VRcoeffd}$\par

\FPeval\VRcoeffa{(0-1)}     \FPclip\VRcoeffa{\VRcoeffa}
\FPeval\VRcoeffb{(0-3)}     \FPclip\VRcoeffb{\VRcoeffb}
\FPeval\VRcoeffc{(0)}       \FPclip\VRcoeffc{\VRcoeffc}
\FPeval\VRcoeffd{(0-12)}    \FPclip\VRcoeffd{\VRcoeffd}
\FPeval\VRcoeffe{(1)}       \FPclip\VRcoeffe{\VRcoeffe}
\FPeval\VRcoefff{(0-1)}     \FPclip\VRcoefff{\VRcoefff}

$f(x)=\polynomial[reciprocal]{%
\VRcoeffa,%
\VRcoeffb,%
\VRcoeffc,%
\VRcoeffd,%
\VRcoeffe,%
\VRcoefff%
}$
\par
$\polynomial[reciprocal]{-1,-3,0,-12,1,-1}$

\end{document}

I suspect a managment of type of variable I've no idea about with LaTeX (I'm not very used to LaTeX ... but I'm trying ;o). Thanks in advance for your help !

**** EDIT ****

This is unrelated to pgfmath. Looks like an expansion issue. Here's a MWE.

\documentclass{article}

\usepackage{polynomial}

\begin{document}

\newcommand{\vl}{-3}

$\polynomial[reciprocal]{1,\vl}$

\end{document}

This produces

enter image description here

instead of $x-3$

  • Welcome to TeX.SE – user31729 Feb 15 '17 at 14:21
  • 2
    Could you complete the example to include a documenclass (article is fine) and the necessary packages? And what exactly are you asking? – Torbjørn T. Feb 15 '17 at 14:31
  • 1
    @TorbjørnT. I added a MWE to OP's post. – JPi Feb 15 '17 at 14:59
  • 1
    This is clearly a bug. @JPi, I think you are right that it has to do with expansion. The coefficient \vl is not expanded before the check of -. I will dig into the code. – StefanH Feb 15 '17 at 15:49
2

As stated in the comments this is a bug due to that the coefficient \vl in the MWE is not expanded before the check of -. Try to include the code from \makeatletter and \makeatother (including these commands) after \usepackage{polynomial} in the preamble as in the modified MWE below. (I also removed the [resiprocal] since it is irrelevant).

Please let me know if this work so I can upload a corrected version to CTAN (after re-learning how to pack it correctly:).

\documentclass{article}

\usepackage{polynomial}
\makeatletter
\def\shpol@getcoeff#1{% Parse the coeffs and store in #1-vars
  \shpol@numcoeff=0%
  \@for\shpol@coeff:=#1\do{%
    \advance\shpol@numcoeff by 1\relax%
    \expandafter\edef\csname shpol@coeff\romannumeral\shpol@numcoeff\endcsname{\shpol@coeff}%
  }%
}
\makeatother

\begin{document}

\newcommand{\vl}{-3}

$\polynomial{1,\vl,-4}$

\end{document}

enter image description here

As pointed out by B.Gravouil there is a problem with passing expanded versions of some commands. For example \dfrac and \tfrac from the Ams-packets does not work with this fix. However, \frac works as expected and a workaround in this case is to use \displaystyle and \textstyle versions of it.

\newcommand{\vl}{-3}
\newcommand{\fl}{\frac{2}{3}}
\begin{document}
\begin{itemize}
\item $\polynomial{1,\vl,\frac{2}{3}}$
\item $\displaystyle\polynomial{1,\vl,\frac{2}{3}}$
\item $\polynomial{1,\vl,\displaystyle\frac{2}{3}}$
\item $\polynomial{1,\fl,\frac{2}{3}}$
\item $\displaystyle\polynomial{1,\fl,\frac{2}{3}}$
\item $\polynomial{1,\fl,\displaystyle\frac{2}{3}}$
\item $\polynomialfrac{1,2,3}{2,\vl,4}$
\end{itemize}

enter image description here

  • works for me.... you don't need the curlies around \vl. – JPi Feb 15 '17 at 16:30
  • 1
    @JPi I removed them. They where leftovers from testing. – StefanH Feb 15 '17 at 16:43
  • 1
    @B.Gravouil I have added a workaround for the \dfrac case. – StefanH Feb 15 '17 at 20:55

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.