| 1 |
% \subsubsection{Feedback} |
| 2 |
% \DescribeEnv{feedback}{An initially hidden environment that uncovers itself at an appropriate time.} |
| 3 |
% New Validator rewrite code added by Jason Nowell. Original code |
| 4 |
% orovided by Jim Fowler Validator is an environment designed to run a |
| 5 |
% custom check on answers (usually) using javascript code. |
| 6 |
% |
| 7 |
% Define a placeholder command for validator and feedback. |
| 8 |
% \begin{macrocode} |
| 9 |
%<*classXimera> |
| 10 |
\newcommand{\PH@Command}{} |
| 11 |
% \end{macrocode} |
| 12 |
% Validator should take an argument and detokenize it and display it |
| 13 |
% at the start of the environment. The original Validator environment |
| 14 |
% had everything framed in an mbox; presumably to make the text look |
| 15 |
% a bit nicer, although this seems redundant with |texttt|. It |
| 16 |
% shouldn't cause any harm so I have left it in for now. |
| 17 |
% \begin{macrocode} |
| 18 |
\newenvironment{validator}[1][]{ |
| 19 |
\def\PH@Command{#1}% Use PH@Command to hold the content and be a target for "\expandafter" to expand once. |
| 20 |
\mbox{\texttt{\detokenize\expandafter{\PH@Command}}}% Now expand PH@Command once and then detokenize. |
| 21 |
}{} |
| 22 |
% \end{macrocode} |
| 23 |
% First, if it's a handout, we want feedback to eat everything and |
| 24 |
% then disappear entirely. So we do this: |
| 25 |
% \begin{macrocode} |
| 26 |
\ifhandout% |
| 27 |
\newenvironment{feedback} |
| 28 |
{% |
| 29 |
\setbox0\vbox\bgroup |
| 30 |
} |
| 31 |
{% |
| 32 |
\egroup |
| 33 |
} |
| 34 |
% \end{macrocode} |
| 35 |
% If this isn't a handout, then we want to display the Feedback by |
| 36 |
% using a label, positioned and formated as a |\item| in a |
| 37 |
% trivlist. It is important that we also detokenize the content of |
| 38 |
% the optional argument, as it is likely to contain javascript or |
| 39 |
% other code that latex won't be able to make sense of. |
| 40 |
% \begin{macrocode} |
| 41 |
\else |
| 42 |
% \end{macrocode} |
| 43 |
% \begin{macrocode} |
| 44 |
\newenvironment{feedback}[1][attempt]{ |
| 45 |
|
| 46 |
\def\PH@Command{#1}% Use PH@Command to hold the content and be a target for "\expandafter" to expand once. |
| 47 |
|
| 48 |
\begin{trivlist}% Begin the trivlist to use formating of the "Feedback" label. |
| 49 |
\item[\hskip \labelsep\small\slshape\bfseries Feedback% Format the "Feedback" label. Don't forget the space. |
| 50 |
(\texttt{\detokenize\expandafter{\PH@Command}}):% Format (and detokenize) the condition for feedback to trigger |
| 51 |
\hspace{2ex}]\small\slshape% Insert some space before the actual feedback given. |
| 52 |
}{ |
| 53 |
\end{trivlist} |
| 54 |
} |
| 55 |
|
| 56 |
\fi |
| 57 |
%</classXimera> |
| 58 |
% \end{macrocode} |
| 59 |
% Feedback environments take an optional parameter (which describes |
| 60 |
% when the feedback is to be provided) |
| 61 |
% \begin{macrocode} |
| 62 |
%<*htXimera> |
| 63 |
\def\feedback{\@ifnextchar[{\@feedbackcode}{\@feedbackattempt}} |
| 64 |
\def\@feedbackattempt{\@feedbackcode[attempt]} |
| 65 |
\def\@feedbackcode[#1]{\stepcounter{identification}% |
| 66 |
\ifvmode \IgnorePar\fi \EndP% |
| 67 |
\ifthenelse{\equal{#1}{attempt}}{\HCode{<div class="feedback" data-feedback="attempt" id="feedback\arabic{identification}">}}% |
| 68 |
{\ifthenelse{\equal{#1}{correct}}{\HCode{<div class="feedback" data-feedback="correct" id="feedback\arabic{identification}">}}% |
| 69 |
{\HCode{<div class="feedback" data-feedback="script" id="feedback\arabic{identification}"><script type="text/javascript">function feedback\arabic{identification}() }\{\HCode{ return \detokenize{#1}; }\}\HCode{</script>}}}} |
| 70 |
\def\endfeedback{\HCode{</div>}\IgnoreIndent} |
| 71 |
%</htXimera> |
| 72 |
% \end{macrocode} |