I am making basic arithmetic worksheets with random numbers.
I want to separate the questions from the answer page. Not sure how to do that.
Ideally, it would look something like this, but with more equations on each page.
QUESTIONS PAGE
2+3=__
7=__+4
1+__=9
ANSWERS PAGE
2+3=5
7=3+4
1+8=9
My code puts all the questions and answers together, which is what I'd expect given the code I typed, because I don't know how to separate them. Do I need to restructure the whole thing?
\documentclass{article}
\usepackage{ifthen}
\usepackage{pgf}
\usepackage{pgffor}
\pgfmathsetseed{\number\pdfrandomseed}
\newcommand{\InitVariables}
{
\pgfmathsetmacro{\PartA}{int(random(0,10))}
\pgfmathsetmacro{\PartB}{int(random(0,10))}
\pgfmathsetmacro{\Sum}{int(\PartA+\PartB)}
\pgfmathtruncatemacro{\Structure}{random(1,3)}
}
\newcommand{\onefact}
{
\InitVariables
\ifcase\Structure\relax %
\or
\newcommand{\Question}{\(\PartA+\PartB=\_\_\_\)}
\newcommand{\Answer}{\(\PartA+\PartB=\Sum\)}
\or
\newcommand{\Question}{\(\PartA+\_\_\_=\Sum\)}
\newcommand{\Answer}{\(\PartA+\PartB=\Sum\)}
\or
\newcommand{\Question}{\(\_\_\_+\PartB=\Sum\)}
\newcommand{\Answer}{\(\PartA+\PartB=\Sum\)}
\fi
}
\newcommand{\thismany}[1]
{\foreach \x in {1,2,...,#1} { \onefact \par \Question \par \Answer \par}}
\begin{document}
\thismany{10}
\end{document}
\xdef\answerlist{\answerlist \Answer \par}. I googled\xdefbut couldn't make sense of the results. – WeCanLearnAnything Sep 29 '16 at 07:30\pgfmathtruncatemacrobecause I was told to but I do not know why. Why not just use\pgfmathsetmacro? – WeCanLearnAnything Oct 02 '16 at 20:33