Debian Codegraph @

texmf-dist/doc/latex/ximera/src/choice.dtx

raw
1 % \subsubsection{Multiple choice and the like}
2 % \DescribeEnv{multipleChoice}{Multiple choice}
3 % \begin{macrocode}
4 %<*classXimera>
5 % Jim: Originally this was \renewcommand{\theenumi}{$(\mathrm{\alph{enumi}})$}
6 % but that breaks tex4ht because mathmode can only be processed by mathjax.
7 % so now I made this just italicized.
8 % \end{macrocode}
9 % \subsubsection{Options}
10 % \begin{macrocode}
11 \define@key{choice}{value}[]{\def\choice@value{#1}}
12 % \end{macrocode}
13 % This flags the answer as the correct answer
14 % \begin{macrocode}
15 \define@boolkey{choice}{correct}[true]{\def\choice@correct{#1}}
16 % \end{macrocode}
17 % Use an ID to refer to the choice.
18 % \begin{macrocode}
19 \define@key{multipleChoice}{id}{\def\mc@id{#1}}
20 % \end{macrocode}
21 % |\otherchoice| outputs the item if correct and nothing if incorrect.
22 % \begin{macrocode}
23 \define@key{otherchoice}{value}[]{\def\otherchoice@value{#1}}
24 \define@boolkey{otherchoice}{correct}[true]{\def\otherchoice@correct{#1}}
25 % \end{macrocode}
26 % Default key choices for multiple choice options.
27 % Default for choice pairs.
28 % Default: answers without the option "correct=true" is "incorrect".
29 % \begin{macrocode}
30 \setkeys{choice}{correct=false,value=}
31 % \end{macrocode}
32 % Defaults for multipleChoice pairs.
33 % Default to no id? -- Jason
34 % \begin{macrocode}
35 \setkeys{multipleChoice}{id=}
36 % \end{macrocode}
37 % Defaults for otherchoice pairs.
38 % Default "otherchoice" to behave like "choice" for error checking.
39 % \begin{macrocode}
40 \setkeys{otherchoice}{correct=false,value=}
41 %</classXimera>
42 % \end{macrocode}
43 %
44 % \subsubsection{Choices}
45 % \DescribeMacro{\choice}{Like |\item| but for choice environments.}
46 % choice command denotes a possible answer choice for the multiple choice question.
47 % \begin{macrocode}
48 %<*classXimera>
49 \newcommand{\choice}[2][]{%
50 \setkeys{choice}{#1}%
51 \item{#2}
52 \ifthenelse{\boolean{\choice@correct}}
53 {% Begin then result
54 \ifhandout% if it's a handout do nothing.
55 \else% otherwise place a checkmark when you select the "correct choice"... maybe? -- Jason
56 \,\checkmark\,\setkeys{choice}{correct=false}
57 \fi
58 }% End then result
59 {}% Begin/End else result.
60 }
61
62 %Define an expandable version of choice Not really meant to be used outside this package (used in wordChoice)
63 % Is there a reason we can't just always use this as default? -- Jason
64 \newcommand{\choiceEXP}[2][]{%
65 \expandafter\setkeys\expandafter{choice}{#1}%
66 \item{#2}
67 \ifthenelse{\boolean{\choice@correct}}
68 {% Begin then result
69 \ifhandout
70 \else
71 \,\checkmark\,\setkeys{choice}{correct=false}
72 \fi
73 }% End then result
74 {}% Begin/End else result.
75 } %% note all the {} are needed in case the choice has [] in it.
76
77 % \otherchoice is the \choice used in wordChoice command.
78 \newcommand{\otherchoice}[2][]{%
79 \ignorespaces%
80 \setkeys{otherchoice}{#1}%
81 \ifthenelse{\boolean{\otherchoice@correct}}%
82 {% Start then result
83 #2\ignorespaces\setkeys{otherchoice}{correct=false}\ignorespaces%
84 }% End then result
85 {}% Start/End else result
86 \ignorespaces%
87 }%
88 \newcommand{\inlinechoice}[2][]{%
89 \setkeys{choice}{#1}%
90 \iffirstinlinechoice
91 (\hspace{-.25em}
92 \firstinlinechoicefalse
93 \else
94 /
95 \fi
96 #2
97 \ifthenelse{\boolean{\choice@correct}}%
98 {% Start then result
99 \ifhandout\else\checkmark\ignorespaces\setkeys{choice}{correct=false}\ignorespaces\fi%
100 }% End then result
101 {}% Start/End else result
102 \hspace{-.25em}\ignorespaces%
103 }
104
105 %</classXimera>
106 % \end{macrocode}
107 % On the HTML side, |\choice| emits |<span>|s.
108 % \begin{macrocode}
109 %<*htXimera>
110 \newcounter{choiceId}
111 \renewcommand{\choice}[2][]{%
112 \setkeys{choice}{correct=false}%
113 \setkeys{choice}{#1}%
114 \stepcounter{choiceId}\IgnorePar%
115 \HCode{<span class="choice }%
116 \ifthenelse{\boolean{\choice@correct}}{\HCode{correct}}{}
117 \HCode{" }
118 \ifthenelse{\equal{\choice@value}{}}{}{\HCode{data-value="\choice@value" }}
119 \HCode{id="choice\arabic{choiceId}">}%
120 #2\HCode{</span>}}
121 \let\inlinechoice\choice
122 %</htXimera>
123 % \end{macrocode}
124
125 % \subsubsection{Environment(s)}
126 % The environment |multipleChoice@| is for internal use only.
127 % \DescribeEnv{multipleChoice}{Wrap |\choice|s in a |multipleChoice| environment to make a multiple choice question.}
128 % \begin{macrocode}
129 %<*classXimera>
130 \newenvironment{multipleChoice}[1][]
131 {% Environment Start Code
132 \setkeys{multipleChoice}{#1}%
133 \recordvariable{\mc@id}%
134 \begin{trivlist}
135 \item[\hskip \labelsep\small\bfseries Multiple Choice:]\hfil
136 \begin{enumerate}
137 }% Note this means that \item has to be the first line after \begin{multipleChoice}.
138 {% Environment End Code
139 \end{enumerate}
140 \end{trivlist}
141 }
142
143 %multipleChoice@ is for internal use only! (used in wordChoice)
144 %this is simply a wrapper for the sole showing (other)choice.
145 \newenvironment{multipleChoice@}[1][]{}{)}
146 %</classXimera>
147 % \end{macrocode}
148
149
150
151 % On the web, you might also expect these to be "problem environments"
152 % but they aren't -- they're respondables. You might expect a
153 % |\setcounter{choiceId}{0}| here --- that would be wrong, because then
154 % the generated IDs would no longer be unique.
155 % \begin{macrocode}
156 %<*htXimera>
157 \renewenvironment{multipleChoice}[1][]
158 {\setkeys{multipleChoice}{#1}%
159 \stepcounter{identification}\ifvmode \IgnorePar\fi \EndP\HCode{<div class="multiple-choice" }%
160 \ifthenelse{\equal{\mc@id}{}}{}{\HCode{data-id="\mc@id" }}%
161 \HCode{id="problem\arabic{identification}">}%
162 }{\HCode{</div>}\IgnoreIndent}
163 \ConfigureEnv{multipleChoice}{}{}{}{}
164 %</htXimera>
165 % \end{macrocode}
166
167 % \subsection{Word choice}
168 % \DescribeMacro{\wordChoice}{An in-line version of multipleChoice:
169 % uses enumitem package note, it is coded as a single line to avoid
170 % unwanted spaces in ``given'' mode.}
171 % \begin{macrocode}
172 %<*classXimera>
173 \newcommand{\wordChoice}[1]{%
174 \let\choicetemp\choice% Assign a "choicetemp" command to duplicate choice.
175 \ifwordchoicegiven% If wordchoice option is on, we need to juggle around some definitions.
176 \let\choice\otherchoice%
177 %\begin{multipleChoice@}% -unnecessary (REMOVE THIS LINE IF THE YEAR IS 2019 or Beyond)
178 #1
179 %\end{multipleChoice@}% -unnecessary (REMOVE THIS LINE IF THE YEAR IS 2019 or Beyond)
180 \else% If it isn't the regular "choice" command should work.
181 \let\choice\inlinechoice%
182 \begin{multipleChoice@}%
183 #1%
184 \end{multipleChoice@}%
185 \fi%
186 \let\choice\choicetemp% Now that choicetmp has been manipulated to what we want, replace choice with it.
187 }%
188
189
190 %</classXimera>
191 % \end{macrocode}
192 % This is actually just word choice
193 % \begin{macrocode}
194 %<*htXimera>
195 \renewenvironment{multipleChoice@}{\refstepcounter{problem}}{}%
196 \ConfigureEnv{multipleChoice@}{\stepcounter{identification}\IgnorePar\HCode{<span class="word-choice" id="word-choice\arabic{identification}">}}{\HCode{</span>}\IgnoreIndent}{}{}
197 %</htXimera>
198 % \end{macrocode}
199
200 % \subsection{Select all}
201 % \DescribeEnv{selectAll}{A multiple-multiple choice question}
202 % \begin{macrocode}
203 %<*classXimera>
204 \newenvironment{selectAll}[1][]
205 {\begin{trivlist}\item[\hskip \labelsep\small\bfseries Select All Correct Answers:]\hfil\begin{enumerate}}
206 {\end{enumerate}\end{trivlist}}
207 %</classXimera>
208 % \end{macrocode}
209
210 % In the future we need this to (optionally) be displayed in the
211 % problem, while the actual code lives in the solution. Here is how
212 % this could be implemented: Like the title/maketitle commands, the
213 % multiple-choice could be stored in |\themultiplechoice|, flip a
214 % boolean, and execute |\makemultiplechoice| at the |\end| of the
215 % problem. We should also make a command called |\showchoices| that
216 % will show choices in the handout.
217
218 % On the web, |selectAll| is handled just like |multipleChoice|.
219 % \begin{macrocode}
220 %<*htXimera>
221 \renewenvironment{selectAll}{\refstepcounter{problem}}{}%
222 \ConfigureEnv{selectAll}{\stepcounter{identification}\ifvmode \IgnorePar\fi \EndP\HCode{<div class="select-all" id="problem\arabic{identification}">}}{\HCode{</div>}\IgnoreIndent}{}{}
223 %</htXimera>
224 % \end{macrocode}
225
226