summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/xsim/examples/xsim.multiplechoice.tex
blob: e0db3eb0c520c4eac830cbe560444dfa84f6961f (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
\documentclass{scrartcl}
\usepackage[clear-aux]{xsim}

\usepackage{enumitem,amssymb,fmtcount}
\newlist{choices}{itemize}{1}
\setlist[choices]{label=$\Box$}
\newcommand*\choice{\item}

\DeclareExerciseProperty{choices}
\DeclareExerciseProperty*{multiple}
\DeclareExerciseEnvironmentTemplate{mc}
  {%
    \UseExerciseTemplate{begin}{default}%
    \IfExerciseBooleanPropertyTF{multiple}
      {Select one or more correct answers}
      {%
        \GetExercisePropertyT{choices}
          {Select \numberstringnum{#1} correct answer\ifnum#1>1 s\fi.}%
      }%
    \begin{choices}
  }
  {%
    \end{choices}
    \UseExerciseTemplate{end}{default}%
  }

\DeclareExerciseType{mc}{
  exercise-env = multiplechoice ,
  solution-env = correctchoices ,
  exercise-name = Question ,
  solution-name = Solution ,
  exercise-template = mc ,
  solution-template = mc ,
  counter = exercise
}

\xsimsetup{
  exercise/name = Question ,
  solution/name = Solution
}

\begin{document}

\section{Questions}
\begin{multiplechoice}[choices=1]
  \choice one
  \choice two
  \choice three
  \choice four
\end{multiplechoice}

\begin{exercise}
  Answer this question on a separate sheet.  
\end{exercise}

\begin{multiplechoice}[multiple]
  \choice one
  \choice two
  \choice three
  \choice four
\end{multiplechoice}

\begin{multiplechoice}[choices=2]
  \choice one
  \choice two
  \choice three
  \choice four
\end{multiplechoice}

\end{document}