summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/xsim/doc/examples/xsim.texwelt-23968.tex
blob: bf205bb7fb5580d02d71a5ead8cb623cf46b4bd0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
% http://texwelt.de/wissen/fragen/23968/
\documentclass{article}
\usepackage{xsim}

% new property:
\DeclareExerciseProperty{shortsolution}

% new environment:
\NewDocumentEnvironment{shortsolution}{+b}
  {%
    \edef\ExerciseType{\csname g_xsim_exercise_type_tl\endcsname}%
    \edef\ExerciseID{\csname g_xsim_exercise_id_tl\endcsname}%
    \SetExerciseProperty{shortsolution}{#1}%
  }
  {}

% we'll use a description list for the list of short solutions:
\newcommand\printshortsolutions{%
  \begin{description}
    \ForEachUsedExerciseByType{%
      \def\ExerciseType{##1}%
      \def\ExerciseID{##2}%
      \GetExercisePropertyT{shortsolution}
        {%
          \item[Short Solution ##3]
           ####1%
        }%
    }%
  \end{description}
}

\begin{document}

\section{Problems}
% set shortsolution through option:
\begin{exercise}[subtitle=Pythagoras]
  This is the first problem.
\end{exercise}
\begin{shortsolution}
  This is a shortsolution to the first problem.
\end{shortsolution}
\begin{solution}
  This is the solution to the first problem.
\end{solution}

\begin{exercise}[subtitle=Another Problem]
  This is the second problem.
\end{exercise}
\begin{solution}
  This is the solution to the second problem.
\end{solution}

% set shortsolution with custom command:
\begin{exercise}[subtitle=Yet Another Problem]
  This is the third problem.
\end{exercise}
\begin{shortsolution}
  This is a shortsolution to the third problem.
\end{shortsolution}
\begin{solution}
  This is the solution to the third problem.
\end{solution}

\section{Shortsolutions}
\printshortsolutions

\section{Solutions}
\printsolutions[headings=false]

\end{document}