Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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?

share|improve this question

1 Answer 1

up vote 5 down vote accepted

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

share|improve this answer
    
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

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.