Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- \documentclass{article}
- \usepackage{amsmath}
- \usepackage{mathtools}
- \usepackage{enumitem}
- \usepackage{tikz}
- \pgfmathsetseed{\number\pdfrandomseed}
- \usepackage{xlop}
- \usepackage[user]{zref}
- \usepackage{fancyhdr}
- \makeatletter
- %%=============================================================================
- %% \DefineVariableWithEachAndDo{<macro holding list of undelimited arguments>}%
- %% {<macro holding current element of list>}%
- %% {<tokens>}
- %%=============================================================================
- \newcommand\UD@Exchange[2]{#2#1}%
- \newcommand\UD@PassFirstToSecond[2]{#2{#1}}%
- \newcommand\UD@firstoftwo[2]{#1}%
- \newcommand\UD@secondoftwo[2]{#2}%
- \@ifdefinable\UD@stopromannumeral{\chardef\UD@stopromannumeral=`\^^00}%
- \newcommand\DefineVariableWithEachAndDo[3]{%
- \romannumeral
- \expandafter\UD@Exchange
- \expandafter{#1}{\DefineVariableWithEachAndDoloop{#2}{#3}{}}{\relax}%
- }%
- \newcommand\DefineVariableWithEachAndDoloop[4]{%
- \ifx\relax#4\expandafter\UD@firstoftwo\else\expandafter\UD@secondoftwo\fi
- {\UD@stopromannumeral#3}{%
- \DefineVariableWithEachAndDoloop{#1}{#2}{#3\def#1{#4}#2}%
- }%
- }%
- %%=============================================================================
- \zref@newprop{AddOnea}{0}%
- \zref@newprop{AddTwoa}{0}%
- \zref@newprop{range}{0}%
- \newcommand\undefinedstyle[1]{\nfss@text{\reset@font\bfseries ??}}%
- \newcommand\undefinedcarrystyle[1]{{\nfss@text{\reset@font\scriptsize\bfseries ??}}}%
- \newcommand\phantomcarrystyle[1]{\phantom{\scriptsize{#1}}}%
- \newcommand{\AddQuestions}[2]{%
- \zref@setcurrent{range}{#1}%
- \zref@labelbyprops{#2}{range}%
- \foreach \i in {1,...,#1}{%
- \par\ifnum\i=1 \else\medskip\fi\noindent\hbox{Question \i: }%
- \zref@ifrefundefined{#2.\i}{%
- \pgfmathtruncatemacro{\AddOnea}{random(\DifficultyOne)}%
- \pgfmathtruncatemacro{\AddTwoa}{random(\DifficultyTwo)}%
- \expandafter\UD@PassFirstToSecond\expandafter{\AddOnea}{\zref@setcurrent{AddOnea}}%
- \expandafter\UD@PassFirstToSecond\expandafter{\AddTwoa}{\zref@setcurrent{AddTwoa}}%
- }{]
- \expandafter\expandafter\expandafter\UD@PassFirstToSecond
- \expandafter\expandafter\expandafter{%
- \zref@extractdefault{#2.\i}{AddOnea}{0}%
- }{\zref@setcurrent{AddOnea}}%
- \expandafter\expandafter\expandafter\UD@PassFirstToSecond
- \expandafter\expandafter\expandafter{%
- \zref@extractdefault{#2.\i}{AddTwoa}{0}%
- }{\zref@setcurrent{AddTwoa}}%
- }%
- \zref@labelbyprops{#2.\i}{AddOnea, AddTwoa}%
- \zref@refused{#2.\i}%
- \zref@ifrefundefined{#2.\i}{%
- % actually setting carrystyle is not needed as there are no carries with defaults 0, but ...
- \opadd[carryadd=true, voperator=bottom, resultstyle=\undefinedstyle, operandstyle=\undefinedstyle, carrystyle=\undefinedcarrystyle]%
- }{%
- % Only operands shall be seen, so turn everything else into \phantom
- \opadd[carryadd=true, voperator=bottom, resultstyle=\phantom, carrystyle=\phantomcarrystyle]%
- }%
- {\zref@extractdefault{#2.\i}{AddOnea}{0}}%
- {\zref@extractdefault{#2.\i}{AddTwoa}{0}}%
- }%
- \par
- }%
- \newcommand{\AddAnswers}[1]{%
- \zref@ifrefundefined{#1}{%
- \zref@refused{#1}%
- \par\noindent
- {\normalfont\bfseries [Question-series ``#1'' undefined, probably re-run latex, see messages on console/in .log-file]}%
- \par
- }{%
- \expandafter\UD@PassFirstToSecond\expandafter{%
- \romannumeral
- \expandafter\expandafter\expandafter\UD@Exchange
- \expandafter\expandafter\expandafter{%
- \zref@extractdefault{#1}{range}{1}%
- }{\UD@stopromannumeral 1,...,}%
- }{\foreach \i in }{%
- \par\ifnum\i=1 \else\medskip\fi\noindent\hbox{\rlap{Answer \i: }\phantom{Question \i: }}%
- \zref@refused{#1.\i}%
- \opadd[carryadd=true, voperator=bottom]%
- {\zref@extractdefault{#1.\i}{AddOnea}{0}}%
- {\zref@extractdefault{#1.\i}{AddTwoa}{0}}%
- }%
- }%
- \par
- }%
- \newcommand*{\DifficultyOne}{999}%
- \newcommand*{\DifficultyTwo}{99}%
- %%=============================================================================
- %% A dirty hack for resetting page-numbers with each sheet
- \newcommand\resetpagezreflabelnamenumber{0}%
- \newcommand\resetpage{%
- \newpage
- \xdef\resetpagezreflabelnamenumber{\number\numexpr\resetpagezreflabelnamenumber+1\relax}%
- \zref@labelbyprops{pagereset-\resetpagezreflabelnamenumber}{page}%
- }%
- \newcommand\obtainlastresetpage{%
- \zref@extractdefault{pagereset-\resetpagezreflabelnamenumber}{page}{0}%
- }%
- \newcommand\ps@resetableplain{%
- \let\@mkboth\@gobbletwo
- \let\@oddhead\@empty
- \def\@oddfoot{\reset@font\hfil\@arabic{\number\numexpr\value{page}-\obtainlastresetpage+1\relax}\hfil}%
- \let\@evenhead\@empty
- \let\@evenfoot\@oddfoot
- }%
- \makeatother
- \pagestyle{resetableplain}
- \newcommand\ExamineeNameList{%
- {Coby}%
- {Johan}%
- {Rudy}%
- {Rodrigo}%
- {Alejandra}%
- {Oswaldo}%
- {Yusuf}%
- {Luz}%
- {Denzel}%
- {Abigayle}%
- {Bobby}%
- {Margaret}%
- {Eli}%
- {Billy}%
- {Jazmine}%
- {Miguel}%
- {Jon}%
- {Valentin}%
- {Lance}%
- {Skyler}%
- }%
- \newcommand\ThisExamimeesName{}% <- This raises an error if the macro is already in use by some package/by some other code.
- \begin{document}
- %%%%%%%
- %% Create a sheet of 15 ramdom questions for each examinee:
- \DefineVariableWithEachAndDo{\ExamineeNameList}{\ThisExamimeesName}{%
- \resetpage
- \section*{Question sheet without answers for \ThisExamimeesName}%
- \AddQuestions{15}{This question-series-sheet-\ThisExamimeesName-label}%
- }%
- %%%%%%%
- %% Re-create the sheets from above, this time with answers:
- \DefineVariableWithEachAndDo{\ExamineeNameList}{\ThisExamimeesName}{%
- \resetpage
- \section*{Question sheet with answers for \ThisExamimeesName}%
- \AddAnswers{This question-series-sheet-\ThisExamimeesName-label}%
- }%
- \end{document}
Advertisement
Add Comment
Please, Sign In to add comment