7

I am using the probsoln package to generate random math quizzes. For polynomial division, I can generate random integer coefficients, but I had planned on using the polynom package to auto-generate the solution, but I keep getting one of those "I was expecting a number" errors.

Here is an MWE

\documentclass{article}
\usepackage{probsoln}
\usepackage{polynom}

\newcounter{myCounter}

\begin{document}
  \random{myCounter}{1}{10}
  \[ \polylongdiv{ \value{myCounter}x^2 + 1 }{ x + 1 } \]
\end{document}

I have also tried this using \arabic{myCounter} instead of \value, and I have tried using \pgfmathsetmacro{\newMacro}{\value{myCounter} followed by \pgfmathtruncatemacro{\truncatedMacro}{\newMacro}. Each time, `\polylongdiv' issues the same error.

The .sty file: I have even opened up the .sty file to try and understand how \polylongdiv works, but it just looked like my cats and my kids had randomly played with my keyboard. I couldn't even begin to parse it.

Does anyone have a quick insight/adjustment I can use to accomplish this?

5

You should expand the number before \polylongdiv starts its work:

\documentclass{article}
\usepackage{probsoln}
\usepackage{polynom}

\newcounter{myCounter}

\newcommand\epolylongdiv[2]{%
  \begingroup\edef\x{\endgroup
  \noexpand\polylongdiv{#1}{#2}}\x}

\begin{document}
  \random{myCounter}{1}{10}
  \[ \epolylongdiv{ \themyCounter x^2 + 1 }{ x + 1 } \]
  \random{myCounter}{1}{10}
  \[ \epolylongdiv{ \themyCounter x^2 + 1 }{ x + 1 } \]
\end{document}

enter image description here

  • This worked really well, thanks! I was also able to adapt your suggestion to work with the \polynomialfrac' command from the polynomial' package. – HTG Nov 8 '12 at 3:58

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.