Debian Codegraph @

texmf-dist/doc/latex/xsim/examples/xsim.texwelt-23968.tex

raw
1 % http://texwelt.de/wissen/fragen/23968/
2 \documentclass{article}
3 \usepackage{xsim}
4
5 % new property:
6 \DeclareExerciseProperty{shortsolution}
7
8 % new environment:
9 \NewDocumentEnvironment{shortsolution}{+b}
10 {%
11 \edef\ExerciseType{\csname g_xsim_exercise_type_tl\endcsname}%
12 \edef\ExerciseID{\csname g_xsim_exercise_id_tl\endcsname}%
13 \SetExerciseProperty{shortsolution}{#1}%
14 }
15 {}
16
17 % we'll use a description list for the list of short solutions:
18 \newcommand\printshortsolutions{%
19 \begin{description}
20 \ForEachUsedExerciseByType{%
21 \GetExercisePropertyT{shortsolution}
22 {\item[Short Solution ##3]####1}%
23 }%
24 \end{description}
25 }
26
27 \begin{document}
28
29 \section{Problems}
30 % set shortsolution through option:
31 \begin{exercise}[subtitle=Pythagoras]
32 This is the first problem.
33 \end{exercise}
34 \begin{shortsolution}
35 This is a shortsolution to the first problem.
36 \end{shortsolution}
37 \begin{solution}
38 This is the solution to the first problem.
39 \end{solution}
40
41 \begin{exercise}[subtitle=Another Problem]
42 This is the second problem.
43 \end{exercise}
44 \begin{solution}
45 This is the solution to the second problem.
46 \end{solution}
47
48 % set shortsolution with custom command:
49 \begin{exercise}[subtitle=Yet Another Problem]
50 This is the third problem.
51 \end{exercise}
52 \begin{shortsolution}
53 This is a shortsolution to the third problem.
54 \end{shortsolution}
55 \begin{solution}
56 This is the solution to the third problem.
57 \end{solution}
58
59 \section{Shortsolutions}
60 \printshortsolutions
61
62 \section{Solutions}
63 \printsolutions[headings=false]
64
65 \end{document}