ccd1pga

Untitled

Aug 13th, 2022
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.05 KB | None | 0 0
  1. \documentclass{article}
  2. \usepackage{amsmath}
  3. \usepackage{mathtools}
  4. \usepackage{enumitem}
  5. \usepackage{tikz}
  6. \pgfmathsetseed{\number\pdfrandomseed}
  7. \usepackage{xlop}
  8. \usepackage[user]{zref}
  9. \usepackage{fancyhdr}
  10.  
  11. \makeatletter
  12. %%=============================================================================
  13. %% \DefineVariableWithEachAndDo{<macro holding list of undelimited arguments>}%
  14. %% {<macro holding current element of list>}%
  15. %% {<tokens>}
  16. %%=============================================================================
  17. \newcommand\UD@Exchange[2]{#2#1}%
  18. \newcommand\UD@PassFirstToSecond[2]{#2{#1}}%
  19. \newcommand\UD@firstoftwo[2]{#1}%
  20. \newcommand\UD@secondoftwo[2]{#2}%
  21. \@ifdefinable\UD@stopromannumeral{\chardef\UD@stopromannumeral=`\^^00}%
  22. \newcommand\DefineVariableWithEachAndDo[3]{%
  23. \romannumeral
  24. \expandafter\UD@Exchange
  25. \expandafter{#1}{\DefineVariableWithEachAndDoloop{#2}{#3}{}}{\relax}%
  26. }%
  27. \newcommand\DefineVariableWithEachAndDoloop[4]{%
  28. \ifx\relax#4\expandafter\UD@firstoftwo\else\expandafter\UD@secondoftwo\fi
  29. {\UD@stopromannumeral#3}{%
  30. \DefineVariableWithEachAndDoloop{#1}{#2}{#3\def#1{#4}#2}%
  31. }%
  32. }%
  33. %%=============================================================================
  34. \zref@newprop{AddOnea}{0}%
  35. \zref@newprop{AddTwoa}{0}%
  36. \zref@newprop{range}{0}%
  37. \newcommand\undefinedstyle[1]{\nfss@text{\reset@font\bfseries ??}}%
  38. \newcommand\undefinedcarrystyle[1]{{\nfss@text{\reset@font\scriptsize\bfseries ??}}}%
  39. \newcommand\phantomcarrystyle[1]{\phantom{\scriptsize{#1}}}%
  40. \newcommand{\AddQuestions}[2]{%
  41. \zref@setcurrent{range}{#1}%
  42. \zref@labelbyprops{#2}{range}%
  43. \foreach \i in {1,...,#1}{%
  44. \par\ifnum\i=1 \else\medskip\fi\noindent\hbox{Question \i: }%
  45. \zref@ifrefundefined{#2.\i}{%
  46. \pgfmathtruncatemacro{\AddOnea}{random(\DifficultyOne)}%
  47. \pgfmathtruncatemacro{\AddTwoa}{random(\DifficultyTwo)}%
  48. \expandafter\UD@PassFirstToSecond\expandafter{\AddOnea}{\zref@setcurrent{AddOnea}}%
  49. \expandafter\UD@PassFirstToSecond\expandafter{\AddTwoa}{\zref@setcurrent{AddTwoa}}%
  50. }{]
  51. \expandafter\expandafter\expandafter\UD@PassFirstToSecond
  52. \expandafter\expandafter\expandafter{%
  53. \zref@extractdefault{#2.\i}{AddOnea}{0}%
  54. }{\zref@setcurrent{AddOnea}}%
  55. \expandafter\expandafter\expandafter\UD@PassFirstToSecond
  56. \expandafter\expandafter\expandafter{%
  57. \zref@extractdefault{#2.\i}{AddTwoa}{0}%
  58. }{\zref@setcurrent{AddTwoa}}%
  59. }%
  60. \zref@labelbyprops{#2.\i}{AddOnea, AddTwoa}%
  61. \zref@refused{#2.\i}%
  62. \zref@ifrefundefined{#2.\i}{%
  63. % actually setting carrystyle is not needed as there are no carries with defaults 0, but ...
  64. \opadd[carryadd=true, voperator=bottom, resultstyle=\undefinedstyle, operandstyle=\undefinedstyle, carrystyle=\undefinedcarrystyle]%
  65. }{%
  66. % Only operands shall be seen, so turn everything else into \phantom
  67. \opadd[carryadd=true, voperator=bottom, resultstyle=\phantom, carrystyle=\phantomcarrystyle]%
  68. }%
  69. {\zref@extractdefault{#2.\i}{AddOnea}{0}}%
  70. {\zref@extractdefault{#2.\i}{AddTwoa}{0}}%
  71. }%
  72. \par
  73. }%
  74. \newcommand{\AddAnswers}[1]{%
  75. \zref@ifrefundefined{#1}{%
  76. \zref@refused{#1}%
  77. \par\noindent
  78. {\normalfont\bfseries [Question-series ``#1'' undefined, probably re-run latex, see messages on console/in .log-file]}%
  79. \par
  80. }{%
  81. \expandafter\UD@PassFirstToSecond\expandafter{%
  82. \romannumeral
  83. \expandafter\expandafter\expandafter\UD@Exchange
  84. \expandafter\expandafter\expandafter{%
  85. \zref@extractdefault{#1}{range}{1}%
  86. }{\UD@stopromannumeral 1,...,}%
  87. }{\foreach \i in }{%
  88. \par\ifnum\i=1 \else\medskip\fi\noindent\hbox{\rlap{Answer \i: }\phantom{Question \i: }}%
  89. \zref@refused{#1.\i}%
  90. \opadd[carryadd=true, voperator=bottom]%
  91. {\zref@extractdefault{#1.\i}{AddOnea}{0}}%
  92. {\zref@extractdefault{#1.\i}{AddTwoa}{0}}%
  93. }%
  94. }%
  95. \par
  96. }%
  97. \newcommand*{\DifficultyOne}{999}%
  98. \newcommand*{\DifficultyTwo}{99}%
  99. %%=============================================================================
  100. %% A dirty hack for resetting page-numbers with each sheet
  101. \newcommand\resetpagezreflabelnamenumber{0}%
  102. \newcommand\resetpage{%
  103. \newpage
  104. \xdef\resetpagezreflabelnamenumber{\number\numexpr\resetpagezreflabelnamenumber+1\relax}%
  105. \zref@labelbyprops{pagereset-\resetpagezreflabelnamenumber}{page}%
  106. }%
  107. \newcommand\obtainlastresetpage{%
  108. \zref@extractdefault{pagereset-\resetpagezreflabelnamenumber}{page}{0}%
  109. }%
  110. \newcommand\ps@resetableplain{%
  111. \let\@mkboth\@gobbletwo
  112. \let\@oddhead\@empty
  113. \def\@oddfoot{\reset@font\hfil\@arabic{\number\numexpr\value{page}-\obtainlastresetpage+1\relax}\hfil}%
  114. \let\@evenhead\@empty
  115. \let\@evenfoot\@oddfoot
  116. }%
  117.  
  118. \makeatother
  119.  
  120. \pagestyle{resetableplain}
  121.  
  122. \newcommand\ExamineeNameList{%
  123. {Coby}%
  124. {Johan}%
  125. {Rudy}%
  126. {Rodrigo}%
  127. {Alejandra}%
  128. {Oswaldo}%
  129. {Yusuf}%
  130. {Luz}%
  131. {Denzel}%
  132. {Abigayle}%
  133. {Bobby}%
  134. {Margaret}%
  135. {Eli}%
  136. {Billy}%
  137. {Jazmine}%
  138. {Miguel}%
  139. {Jon}%
  140. {Valentin}%
  141. {Lance}%
  142. {Skyler}%
  143. }%
  144. \newcommand\ThisExamimeesName{}% <- This raises an error if the macro is already in use by some package/by some other code.
  145.  
  146. \begin{document}
  147.  
  148. %%%%%%%
  149. %% Create a sheet of 15 ramdom questions for each examinee:
  150. \DefineVariableWithEachAndDo{\ExamineeNameList}{\ThisExamimeesName}{%
  151. \resetpage
  152. \section*{Question sheet without answers for \ThisExamimeesName}%
  153. \AddQuestions{15}{This question-series-sheet-\ThisExamimeesName-label}%
  154. }%
  155. %%%%%%%
  156. %% Re-create the sheets from above, this time with answers:
  157. \DefineVariableWithEachAndDo{\ExamineeNameList}{\ThisExamimeesName}{%
  158. \resetpage
  159. \section*{Question sheet with answers for \ThisExamimeesName}%
  160. \AddAnswers{This question-series-sheet-\ThisExamimeesName-label}%
  161. }%
  162.  
  163. \end{document}
Advertisement
Add Comment
Please, Sign In to add comment