In an earlier post of mine, I asked how to create separate exercise and solution pages for basic arithmetic. I'm trying the same thing now for factoring simple trinomials, but it's not working and I'm not sure why. I feel like the key parts of the code - defining the exercise page and the solution page - are basically the same, but they obviously are not since my code does not compile.
I do know that if I comment out the line in the body \FactoredPage
, it compiles, though I still get minor error messages.
What's happening?
\documentclass{article}
\usepackage{pgf}
\usepackage{pgffor}
\setlength{\parindent}{0pt}
\pagestyle{empty}
\pgfmathsetseed{\number\pdfrandomseed}
\newcommand{\InitVariablesSTA} %all positives
{%
\pgfmathsetmacro{\avar}{int(1)}
\pgfmathsetmacro{\bvar}{int(random(1,11))}
\pgfmathsetmacro{\cvar}{int(1)}
\pgfmathsetmacro{\dvar}{int(random(1,11))}
\pgfmathsetmacro{\Avar}{int(\avar*\cvar)}
\pgfmathsetmacro{\Bvar}{int(\avar*\dvar+\bvar*\cvar)}
\pgfmathsetmacro{\Cvar}{int(\bvar*\dvar)}
}
\newcommand{\STA}
{%
\InitVariablesSTA%
\newcommand{\factored}{\((x+\bvar)(x+\dvar)\)}%
\newcommand{\expanded}{\(x^2+{\Bvar}x+\Cvar\)}%
}
\newcommand{\FactoredPage}{}
\newcommand{\ExpandedPage}[1]
{%
\foreach \x in {1,...,#1}
{%
\STA \expanded \par
\xdef\FactoredPage{\FactoredPage \factored \par}%
}
}
\begin{document}
\ExpandedPage{10}
\FactoredPage
\end{document}
pgf
ofpgffor
that I haven't heard of? Anyone else have ideas? I'd really appreciate any help! Thanks!\xdef
, if I replace\factored
with plain text, the code compiles. So, I'm guessing that the definition of\factored
is not defined in the\xdef
line but I'm not sure why.