| 1 |
\documentclass{article} |
| 2 |
\usepackage{xsim,tcolorbox,needspace} |
| 3 |
|
| 4 |
% declare a boolean property: |
| 5 |
\DeclareExerciseProperty*{short} |
| 6 |
% declare a tag like property: |
| 7 |
\DeclareExerciseTagging{level} |
| 8 |
|
| 9 |
% declare a template which typesets exercises differently according to given |
| 10 |
% properties: |
| 11 |
\DeclareExerciseEnvironmentTemplate{exercise} |
| 12 |
{% |
| 13 |
\renewcommand*\theenumi{\theexercise.\arabic{enumi}}% |
| 14 |
\par\addvspace{\baselineskip} |
| 15 |
\Needspace*{2\baselineskip} |
| 16 |
\noindent |
| 17 |
\GetExercisePropertyT{level}{\marginpar{\sffamily Level: #1}}% |
| 18 |
\textbf{\XSIMmixedcase{\GetExerciseName}~\GetExerciseProperty{counter}.} % |
| 19 |
\GetExercisePropertyT{subtitle}{\textit{#1}}% |
| 20 |
\IfExerciseBooleanPropertyF{short}{\par\noindent}% |
| 21 |
} |
| 22 |
{} |
| 23 |
|
| 24 |
% declare a tcolorbox template for the solutions: |
| 25 |
\DeclareExerciseEnvironmentTemplate{solution} |
| 26 |
{\tcolorbox[colback=yellow,colframe=red]} |
| 27 |
{\endtcolorbox} |
| 28 |
|
| 29 |
% declare a user command for short answers: |
| 30 |
\NewDocumentCommand\answer{m}{% |
| 31 |
\IfSolutionPrintT{% |
| 32 |
\UseExerciseTemplate{begin}{solution}% |
| 33 |
#1% |
| 34 |
\UseExerciseTemplate{end}{solution}% |
| 35 |
}{}% |
| 36 |
} |
| 37 |
|
| 38 |
% setup exercises and solutions: |
| 39 |
\SetExerciseParameters{exercise}{ |
| 40 |
exercise-template = exercise , |
| 41 |
solution-template = solution |
| 42 |
} |
| 43 |
|
| 44 |
% remove this option to hide the answers: |
| 45 |
\xsimsetup{solution/print=true} |
| 46 |
|
| 47 |
\usepackage{lipsum} |
| 48 |
|
| 49 |
\begin{document} |
| 50 |
|
| 51 |
\begin{exercise}[level=hard,short] |
| 52 |
Just a short exercise |
| 53 |
\end{exercise} |
| 54 |
\begin{solution} |
| 55 |
The somewhat longer solution to the short exercise. \lipsum[1] |
| 56 |
\end{solution} |
| 57 |
|
| 58 |
\begin{exercise}[subtitle=This one has a title,level=easy] |
| 59 |
Answer the following questions. |
| 60 |
\begin{enumerate} |
| 61 |
\item question \answer{answer} |
| 62 |
\item question \answer{answer} |
| 63 |
\end{enumerate} |
| 64 |
\end{exercise} |
| 65 |
|
| 66 |
\begin{exercise} |
| 67 |
A long exercise. \lipsum[4]\answer{The answer} |
| 68 |
\end{exercise} |
| 69 |
|
| 70 |
\begin{exercise}[level=medium,short] |
| 71 |
Another short exercise.\answer{The answer} |
| 72 |
\end{exercise} |
| 73 |
|
| 74 |
\end{document} |