Debian Codegraph @

texmf-dist/doc/latex/xsim/examples/xsim.texsx-576998.tex

raw
1 % https://tex.stackexchange.com/q/576998
2 \documentclass[twocolumn]{book}
3 \usepackage{xsim}
4
5 \DeclareExerciseEnvironmentTemplate{number-only}{%
6 \par\noindent
7 \textbf{\GetExerciseProperty{counter}}%
8 \GetExercisePropertyT{subtitle}{ \textit{#1}} %
9 }{\par}
10
11 \newcommand\printsectionexercises{%
12 \ForEachUsedExerciseByType{%
13 \ifnum\ExercisePropertyGet{##1}{##2}{chapter-value}=\value{chapter}
14 \ifnum\ExercisePropertyGet{##1}{##2}{section-value}=\value{section}
15 \XSIMprint{exercise}{##1}{##2}%
16 \fi
17 \fi
18 }%
19 }
20
21 \renewcommand\printsolutions{%
22 \def\currentchapter{}%
23 \def\currentsection{}%
24 \def\lastchapter{}%
25 \def\lastsection{}%
26 \ForEachUsedExerciseByType{%
27 \let\lastchapter\currentchapter
28 \let\lastsection\currentsection
29 \edef\currentchapter{\ExercisePropertyGet{##1}{##2}{chapter-value}}%
30 \edef\currentsection{\ExercisePropertyGet{##1}{##2}{section-value}}%
31 \ifx\lastchapter\currentchapter\else
32 \section*{Chapter \ExercisePropertyGet{##1}{##2}{chapter}}
33 \fi
34 \ifx\lastsection\currentsection\else
35 \subsection*{Exercises \ExercisePropertyGet{##1}{##2}{section}}
36 \fi
37 \XSIMprint{solution}{##1}{##2}%
38 }%
39 }
40
41 \xsimsetup{
42 exercise/template = number-only ,
43 solution/template = number-only ,
44 exercise/within = section ,
45 exercise/the-counter = \arabic{exercise}. ,
46 exercise/print = false
47 }
48
49 \begin{document}
50
51 \setcounter{chapter}{13}
52 \chapter{}
53 \section{Cats as pets}
54 Text text text\dots
55 \begin{exercise}
56 Draw a cat.
57 \end{exercise}
58 \begin{solution}
59 Drawing a cat.
60 \end{solution}
61
62 Text text text\dots
63 \begin{exercise}
64 Bathe a cat.
65 \end{exercise}
66 \begin{solution}
67 Bathing a cat.
68 \end{solution}
69
70 Text text text\dots
71 \begin{exercise}
72 Trace the history of cats through time.
73 \end{exercise}
74 \begin{solution}
75 Tracing the history of cats through time.
76 \end{solution}
77
78 \subsection*{Exercises \thesection}
79 \printsectionexercises
80
81 \section{Frogs as pets}
82 Text text text\dots
83 \begin{exercise}
84 Lick a frog.
85 \end{exercise}
86 \begin{solution}
87 Licking a frog.
88 \end{solution}
89
90 Text text text\dots
91 \begin{exercise}
92 Bathe a frog.
93 \end{exercise}
94 \begin{solution}
95 Bathing a frog.
96 \end{solution}
97
98 Text text text\dots
99 \begin{exercise}
100 Feed a frog.
101 \end{exercise}
102 \begin{solution}
103 Feeding a frog.
104 \end{solution}
105
106 \subsection*{Exercises \thesection}
107 \printsectionexercises
108
109 \setcounter{chapter}{20}
110 \chapter{}
111
112 \section{The joys of fish}
113 Text text text\dots
114 \begin{exercise}
115 Catch a fish.
116 \end{exercise}
117 \begin{solution}
118 Catching a fish.
119 \end{solution}
120
121 Text text text\dots
122 \begin{exercise}
123 Draw a fish.
124 \end{exercise}
125 \begin{solution}
126 Drawing a fish.
127 \end{solution}
128
129 \subsection*{Exercises \thesection}
130 \printsectionexercises
131
132 \chapter*{Solutions to the exercises}
133 \printsolutions
134
135 \end{document}