summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/ximera/src/choice.dtx
blob: 70770cd24e78afc8728de882cf380be4c548d6c1 (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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
% \subsubsection{Multiple choice and the like}
% \DescribeEnv{multipleChoice}{Multiple choice}
%    \begin{macrocode}
%<*classXimera>
% Jim: Originally this was \renewcommand{\theenumi}{$(\mathrm{\alph{enumi}})$}
% but that breaks tex4ht because mathmode can only be processed by mathjax.
% so now I made this just italicized.
%    \end{macrocode}
% \subsubsection{Options}
%    \begin{macrocode}
\define@key{choice}{value}[]{\def\choice@value{#1}}
%    \end{macrocode}
% This flags the answer as the correct answer
%    \begin{macrocode}
\define@boolkey{choice}{correct}[true]{\def\choice@correct{#1}}
%    \end{macrocode}
% Use an ID to refer to the choice.
%    \begin{macrocode}
\define@key{multipleChoice}{id}{\def\mc@id{#1}}
%    \end{macrocode}
% |\otherchoice| outputs the item if correct and nothing if incorrect.
%    \begin{macrocode}
\define@key{otherchoice}{value}[]{\def\otherchoice@value{#1}}
\define@boolkey{otherchoice}{correct}[true]{\def\otherchoice@correct{#1}}
%    \end{macrocode}
% Default key choices for multiple choice options.
% Default for choice pairs.
% Default: answers without the option "correct=true" is "incorrect".
%    \begin{macrocode}
\setkeys{choice}{correct=false,value=}
%    \end{macrocode}
% Defaults for multipleChoice pairs.
% Default to no id? -- Jason
%    \begin{macrocode}
\setkeys{multipleChoice}{id=}
%    \end{macrocode}
% Defaults for otherchoice pairs.
% Default "otherchoice" to behave like "choice" for error checking.
%    \begin{macrocode}
\setkeys{otherchoice}{correct=false,value=}
%</classXimera>
%    \end{macrocode}
%
% \subsubsection{Choices}
% \DescribeMacro{\choice}{Like |\item| but for choice environments.}
% choice command denotes a possible answer choice for the multiple choice question.
%    \begin{macrocode}
%<*classXimera>
\newcommand{\choice}[2][]{%
\setkeys{choice}{#1}%
\item{#2}
\ifthenelse{\boolean{\choice@correct}}
    {% Begin then result
    \ifhandout% if it's a handout do nothing.
    \else% otherwise place a checkmark when you select the "correct choice"... maybe? -- Jason
        \,\checkmark\,\setkeys{choice}{correct=false}
    \fi
    }% End then result
    {}% Begin/End else result.
}

%Define an expandable version of choice Not really meant to be used outside this package (used in wordChoice)
% Is there a reason we can't just always use this as default? -- Jason
\newcommand{\choiceEXP}[2][]{%
	\expandafter\setkeys\expandafter{choice}{#1}%
	\item{#2}
	\ifthenelse{\boolean{\choice@correct}}
		{% Begin then result
		\ifhandout 
		\else 
			\,\checkmark\,\setkeys{choice}{correct=false}
		\fi
		}% End then result
		{}% Begin/End else result.
	} %% note all the {} are needed in case the choice has [] in it.

% \otherchoice is the \choice used in wordChoice command.
\newcommand{\otherchoice}[2][]{%
\ignorespaces%
\setkeys{otherchoice}{#1}%
\ifthenelse{\boolean{\otherchoice@correct}}%
{% Start then result
#2\ignorespaces\setkeys{otherchoice}{correct=false}\ignorespaces%
}% End then result
{}% Start/End else result
\ignorespaces%
}%
\newcommand{\inlinechoice}[2][]{%
\setkeys{choice}{#1}%
\iffirstinlinechoice
(\hspace{-.25em}
\firstinlinechoicefalse
\else
/
\fi
#2
\ifthenelse{\boolean{\choice@correct}}%
{% Start then result
\ifhandout\else\checkmark\ignorespaces\setkeys{choice}{correct=false}\ignorespaces\fi%
}% End then result
{}% Start/End else result
\hspace{-.25em}\ignorespaces%
}

%</classXimera>
%    \end{macrocode}
% On the HTML side, |\choice| emits |<span>|s.
%    \begin{macrocode}
%<*htXimera>
\newcounter{choiceId}
\renewcommand{\choice}[2][]{%
\setkeys{choice}{correct=false}%
\setkeys{choice}{#1}%
\stepcounter{choiceId}\IgnorePar%
\HCode{<span class="choice }%
\ifthenelse{\boolean{\choice@correct}}{\HCode{correct}}{}
\HCode{" }
\ifthenelse{\equal{\choice@value}{}}{}{\HCode{data-value="\choice@value" }}
\HCode{id="choice\arabic{choiceId}">}%
#2\HCode{</span>}}
\let\inlinechoice\choice
%</htXimera>
%    \end{macrocode}

% \subsubsection{Environment(s)}
% The environment |multipleChoice@| is for internal use only. 
% \DescribeEnv{multipleChoice}{Wrap |\choice|s in a |multipleChoice| environment to make a multiple choice question.}
%    \begin{macrocode}
%<*classXimera>
\newenvironment{multipleChoice}[1][]
	{% Environment Start Code
	\setkeys{multipleChoice}{#1}%
	\recordvariable{\mc@id}%
	\begin{trivlist}
		\item[\hskip \labelsep\small\bfseries Multiple Choice:]\hfil
		\begin{enumerate}
	}% Note this means that \item has to be the first line after \begin{multipleChoice}.
	{% Environment End Code
		\end{enumerate}
	\end{trivlist}
	}

%multipleChoice@ is for internal use only! (used in wordChoice)
%this is simply a wrapper for the sole showing (other)choice.
\newenvironment{multipleChoice@}[1][]{}{)}
%</classXimera>
%    \end{macrocode}



% On the web, you might also expect these to be "problem environments"
% but they aren't -- they're respondables.  You might expect a
% |\setcounter{choiceId}{0}| here --- that would be wrong, because then
% the generated IDs would no longer be unique.
%    \begin{macrocode}
%<*htXimera>
\renewenvironment{multipleChoice}[1][]
{\setkeys{multipleChoice}{#1}%
\stepcounter{identification}\ifvmode \IgnorePar\fi \EndP\HCode{<div class="multiple-choice" }%
\ifthenelse{\equal{\mc@id}{}}{}{\HCode{data-id="\mc@id" }}%
\HCode{id="problem\arabic{identification}">}%
}{\HCode{</div>}\IgnoreIndent}
\ConfigureEnv{multipleChoice}{}{}{}{}
%</htXimera>
%    \end{macrocode}

% \subsection{Word choice}
% \DescribeMacro{\wordChoice}{An in-line version of multipleChoice:
% uses enumitem package note, it is coded as a single line to avoid
% unwanted spaces in ``given'' mode.}
%    \begin{macrocode}
%<*classXimera>
\newcommand{\wordChoice}[1]{%
\let\choicetemp\choice% Assign a "choicetemp" command to duplicate choice.
\ifwordchoicegiven% If wordchoice option is on, we need to juggle around some definitions.
\let\choice\otherchoice%
%\begin{multipleChoice@}% -unnecessary (REMOVE THIS LINE IF THE YEAR IS 2019 or Beyond)
#1
%\end{multipleChoice@}% -unnecessary (REMOVE THIS LINE IF THE YEAR IS 2019 or Beyond)
\else% If it isn't the regular "choice" command should work.
\let\choice\inlinechoice%
\begin{multipleChoice@}%
#1%
\end{multipleChoice@}%
\fi%
\let\choice\choicetemp% Now that choicetmp has been manipulated to what we want, replace choice with it.
}%


%</classXimera>
%    \end{macrocode}
% This is actually just word choice
%    \begin{macrocode}
%<*htXimera>
\renewenvironment{multipleChoice@}{\refstepcounter{problem}}{}%
\ConfigureEnv{multipleChoice@}{\stepcounter{identification}\IgnorePar\HCode{<span class="word-choice" id="word-choice\arabic{identification}">}}{\HCode{</span>}\IgnoreIndent}{}{}
%</htXimera>
%    \end{macrocode}

% \subsection{Select all}
% \DescribeEnv{selectAll}{A multiple-multiple choice question}
%    \begin{macrocode}
%<*classXimera>
\newenvironment{selectAll}[1][]
{\begin{trivlist}\item[\hskip \labelsep\small\bfseries Select All Correct Answers:]\hfil\begin{enumerate}}
    {\end{enumerate}\end{trivlist}}
%</classXimera>
%    \end{macrocode}

% In the future we need this to (optionally) be displayed in the
% problem, while the actual code lives in the solution. Here is how
% this could be implemented: Like the title/maketitle commands, the
% multiple-choice could be stored in |\themultiplechoice|, flip a
% boolean, and execute |\makemultiplechoice| at the |\end| of the
% problem.  We should also make a command called |\showchoices| that
% will show choices in the handout.

% On the web, |selectAll| is handled just like |multipleChoice|.
%    \begin{macrocode}
%<*htXimera>
\renewenvironment{selectAll}{\refstepcounter{problem}}{}%
\ConfigureEnv{selectAll}{\stepcounter{identification}\ifvmode \IgnorePar\fi \EndP\HCode{<div class="select-all" id="problem\arabic{identification}">}}{\HCode{</div>}\IgnoreIndent}{}{}
%</htXimera>
%    \end{macrocode}