LaTeX forum ⇒ GeneralHow can I separate exercises from solutions?

LaTeX specific issues not fitting into one of the other forums of this category.
LaTexLearner
Posts: 139
Joined: Tue Mar 10, 2015 11:06 am

How can I separate exercises from solutions?

Postby LaTexLearner » Thu Aug 23, 2018 11:50 pm

I'm in the midst of creating introductory multiplication and division exercises, exemplified by the following, except that I would like to separate the exercises from the solutions.

PicForOnlinePost.PNG
PicForOnlinePost.PNG (55.6 KiB) Viewed 3698 times




I can almost do it now... but not quite.

I made the code below which compiles, but does not separate the exercises from the solutions. I commented out the way I thought I could separate solutions and exercises, but that did not work unless I remove \Diagram from the definition of \Solution, meaning that there is some tikZ problem with \xdef... I think.

All the pictures and files are in this Dropbox folder. https://www.dropbox.com/sh/04uujszim2jr ... 2tTBa?dl=0

[Side note: I do not know how to turn normal text into a link, so I pasted that huge URL instead...]

Sorry for the long MWE; I'm not sure what I could remove and still get the point across! If anyone needs me to comment on any of the code, I'm happy to. :)

  1. \documentclass{article}
  2.  
  3. \usepackage[margin = 1.5cm, landscape]{geometry}
  4. \usepackage{graphicx}
  5. \usepackage{pgf}
  6. \pgfmathsetseed{\number\pdfrandomseed}
  7. \usepackage{pgffor}
  8. \usepackage{tikz}
  9.  
  10. \setlength{\parindent}{0cm}
  11.  
  12.  
  13. \newcommand{\InitVariables}
  14. { \pgfmathrandominteger{\Sets}{1}{10}
  15. \pgfmathrandominteger{\PerSet}{1}{10}
  16. \pgfmathsetmacro{\Total}{int(\Sets*\PerSet)}
  17. }
  18.  
  19. \newcommand{\picturescale}{0.4}
  20.  
  21. \newcommand{\Diagram}{}
  22. \newcommand{\ChosenPic}{}
  23. \newcommand{\Exercise}{}
  24. \newcommand{\Solution}{}
  25.  
  26. \newcommand{\GenOneExerciseAndSolution}
  27. {\InitVariables
  28.  
  29. \renewcommand{\Diagram}
  30. {\ifcase\PerSet\relax
  31. \or \renewcommand{\ChosenPic}{SetOfOne}
  32. \or \renewcommand{\ChosenPic}{SetOfTwo}
  33. \or \renewcommand{\ChosenPic}{SetOfThree}
  34. \or \renewcommand{\ChosenPic}{SetOfFour}
  35. \or \renewcommand{\ChosenPic}{SetOfFive}
  36. \or \renewcommand{\ChosenPic}{SetOfSix}
  37. \or \renewcommand{\ChosenPic}{SetOfSeven}
  38. \or \renewcommand{\ChosenPic}{SetOfEight}
  39. \or \renewcommand{\ChosenPic}{SetOfNine}
  40. \or \renewcommand{\ChosenPic}{SetOfTen}
  41. \fi
  42.  
  43. \begin{tikzpicture}
  44. \foreach \x in {1,...,\Sets}
  45. {\node[anchor=center] at (2.3*\x,0) {\includegraphics[scale=\picturescale]{\ChosenPic}};}
  46. \end{tikzpicture}
  47. }
  48.  
  49. \renewcommand{\Exercise}
  50. {Exercise \x
  51.  
  52. \_\_\_\_ \ boats
  53.  
  54. \_\_\_\_ \ passengers in each boat
  55.  
  56. \_\_\_\_ \ passengers in all
  57.  
  58. \Diagram
  59. }
  60.  
  61.  
  62. \renewcommand{\Solution}
  63. {Solution \x
  64.  
  65. \Sets \ boats
  66.  
  67. \PerSet \ passengers in each boat
  68.  
  69. \Total \ passengers in all
  70.  
  71. \Diagram
  72. }
  73. }
  74.  
  75.  
  76. \newcommand{\ManySolutions}{}
  77.  
  78. %This worked but did not separate exercises from solutions.
  79.  
  80. \newcommand{\ManyExercises}
  81. {\foreach \x in {1,...,10}
  82. {\GenOneExerciseAndSolution \vskip 1cm \Exercise \vskip 1cm \Solution}
  83. }
  84.  
  85.  
  86. %This did not work, but would separate exercises from solutions if it did.
  87.  
  88. %\newcommand{\ManyExercises}
  89. %{\foreach \x in {1,...,10}
  90. % {\GenOneExerciseAndSolution \vskip 1cm \Exercise
  91. % \xdef\ManySolutions{\ManySolutions \Solution}
  92. % }
  93. % }
  94.  
  95.  
  96. \begin{document}
  97.  
  98. \Large
  99.  
  100. \ManyExercises
  101.  
  102. \end{document}

Tags:

Return to “General”

Who is online

Users browsing this forum: No registered users and 11 guests