| 1 |
% https://tex.stackexchange.com/q/498299 |
| 2 |
\documentclass{article} |
| 3 |
\usepackage[no-files]{xsim} |
| 4 |
\usepackage{tasks} |
| 5 |
|
| 6 |
\DeclareExerciseEnvironmentTemplate{item} |
| 7 |
{\item[\GetExerciseProperty{counter}]} |
| 8 |
{} |
| 9 |
|
| 10 |
\DeclareExerciseProperty{answer} |
| 11 |
|
| 12 |
\newcommand*\answer[1]{% |
| 13 |
\XSIMexpandcode{% |
| 14 |
\SetExerciseProperty{answer} |
| 15 |
{ (\noexpand\textit{\alph{task}}) \unexpanded{#1}}}% |
| 16 |
#1% |
| 17 |
} |
| 18 |
|
| 19 |
\newcommand*\getanswers{% |
| 20 |
\def\betweenanswers{\def\betweenanswers{\hspace{2em}}}% |
| 21 |
\ForEachUsedExerciseByID{% |
| 22 |
\betweenanswers##3\ExercisePropertyGet{##1}{##2}{answer}% |
| 23 |
}% |
| 24 |
} |
| 25 |
|
| 26 |
\xsimsetup{ |
| 27 |
exercise/template = item, |
| 28 |
exercise/the-counter = \arabic{exercise}. |
| 29 |
} |
| 30 |
|
| 31 |
\NewTasksEnvironment[ |
| 32 |
label = (\textit{\alph*}) , |
| 33 |
label-width = 14pt |
| 34 |
]{choice}[\choice] |
| 35 |
|
| 36 |
\newenvironment{questions} |
| 37 |
{\itemize} |
| 38 |
{\enditemize} |
| 39 |
|
| 40 |
\begin{document} |
| 41 |
|
| 42 |
\section{Problems} |
| 43 |
\begin{questions} |
| 44 |
\begin{exercise} |
| 45 |
What is the product of $-2$ and $3$? |
| 46 |
\begin{choice}(4) |
| 47 |
\choice \answer{$-6$} |
| 48 |
\choice $6$ |
| 49 |
\choice $5$ |
| 50 |
\choice $-5$ |
| 51 |
\end{choice} |
| 52 |
\end{exercise} |
| 53 |
\begin{exercise} |
| 54 |
What is the sum of the sides of a polygon called? |
| 55 |
\begin{choice}(2) |
| 56 |
\choice Leg |
| 57 |
\choice \answer{Perimeter} |
| 58 |
\choice Area |
| 59 |
\choice Volume |
| 60 |
\end{choice} |
| 61 |
\end{exercise} |
| 62 |
\begin{exercise} |
| 63 |
What is the sum of $-2$ and $-3$? |
| 64 |
\begin{choice}(4) |
| 65 |
\choice $-6$ |
| 66 |
\choice $6$ |
| 67 |
\choice $5$ |
| 68 |
\choice \answer{$-5$} |
| 69 |
\end{choice} |
| 70 |
\end{exercise} |
| 71 |
\end{questions} |
| 72 |
|
| 73 |
\section{Answers} |
| 74 |
\getanswers |
| 75 |
|
| 76 |
\end{document} |