Debian Codegraph @

texmf-dist/source/latex/moodle/moodle.dtx

raw
1 % \iffalse meta-comment
2 %
3 % moodle.dtx
4 % Copyright 2016 by Anders O.F. Hendrickson (anders.o.f.hendrickson AT gmail DOT com)
5 % and 2019-2021 by Matthieu Guerquin-Kern (guerquin-kern AT crans DOT org).
6 %
7 % This work may be distributed and/or modified under the
8 % conditions of the LaTeX Project Public License, either version 1.3
9 % of this license or (at your option) any later version.
10 % The latest version of this license is in
11 % http://www.latex-project.org/lppl.txt
12 % and version 1.3 or later is part of all distributions of LaTeX
13 % version 2005/12/01 or later.
14 %
15 % This work has the LPPL maintenance status `maintained'.
16 %
17 % The Current Maintainer of this work is Matthieu Guerquin-Kern.
18 %
19 % This work consists of the files moodle.dtx and moodle.ins
20 % and the derived file moodle.sty.
21 %
22 % \fi
23 %
24 % \iffalse
25 %<*driver>
26 \ProvidesFile{moodle.dtx}
27 %</driver>
28 %<package>\NeedsTeXFormat{LaTeX2e}[1999/12/01]
29 %<package>\ProvidesPackage{moodle}
30 %<*package>
31 [2023/01/28 v1.0 Moodle quiz XML generation]
32 %</package>
33 %
34 %<*driver>
35 \documentclass[10pt,a4paper]{ltxdoc}
36 %\usepackage[draft]{moodle}
37 \usepackage{iftex}
38 \ifPDFTeX
39 \usepackage[utf8]{inputenc} % necessary
40 \usepackage[T1]{fontenc} % necessary
41 \usepackage{libertine}
42 \usepackage[scaled=0.83]{beramono}
43 \else % assuming LuaLaTeX or XeLaTeX
44 \usepackage{fontspec}
45 \setmainfont{Linux Libertine O}
46 \fi
47 \usepackage{microtype}
48 \usepackage{dtxdescribe,varioref}
49 \addtolength\marginparwidth{30pt}
50 \addtolength\oddsidemargin{20pt}
51 \addtolength\evensidemargin{20pt}
52 \usepackage[main=english,french,german]{babel}
53 \usepackage{amssymb,threeparttable,booktabs}
54 \usepackage{eurosym,longtable,tikz,minted,changelog}
55 %\usepackage[pdfpagelabels]{hyperref}% now loaded by ltxdoc
56 \usetikzlibrary{arrows,positioning,decorations.text,calc}
57 %\usemintedstyle{Wombat}
58 \EnableCrossrefs
59 \CodelineIndex
60 \OnlyDescription
61 \RecordChanges
62 \setcounter{IndexColumns}{2}
63 \begin{document}
64 \DocInput{moodle.dtx}
65 \end{document}
66 %</driver>
67 % \fi
68 %
69 % \CheckSum{10269} ^^A Comment \OnlyDescription above to adjust
70 %
71 % \CharacterTable
72 % {Upper-case \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
73 % Lower-case \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z
74 % Digits \0\1\2\3\4\5\6\7\8\9
75 % Exclamation \! Double quote \" Hash (number) \#
76 % Dollar \$ Percent \% Ampersand \&
77 % Acute accent \' Left paren \( Right paren \)
78 % Asterisk \* Plus \+ Comma \,
79 % Minus \- Point \. Solidus \/
80 % Colon \: Semicolon \; Less than \<
81 % Equals \= Greater than \> Question mark \?
82 % Commercial at \@ Left bracket \[ Backslash \\
83 % Right bracket \] Circumflex \^ Underscore \_
84 % Grave accent \` Left brace \{ Vertical bar \|
85 % Right brace \} Tilde \~}
86 %
87 %
88 % \GetFileInfo{\jobname.dtx}
89 %
90 % \DoNotIndex{\newcommand,\newenvironment,\def}
91 %
92 % \providecommand\TikZ{\mbox{Ti\emph{k}Z}}%
93 % \providecommand\Moodle{\mbox{\brand{Moodle}}}%
94 % \providecommand\LMS{\mbox{\acro{LMS}}}%
95 % \providecommand\XML{\mbox{\acro{XML}}}%
96 %
97 % \title{%
98 % The \pkg{moodle} package: \\
99 % generating \Moodle\ quizzes via \LaTeX%
100 % \thanks{This document corresponds to \pkg{moodle.sty}~\fileversion, dated \filedate.}
101 % }%
102 %
103 % \author{%
104 % Anders Hendrickson\footnote{original author of the package (\texttt{v0.5}), inactive.}\\
105 % \texttt{anders.o.f.hendrickson AT gmail DOT com} \and
106 % Matthieu Guerquin-Kern\footnote{current maintainer, %
107 % author of the updates (\texttt{v0.6} to \texttt{\fileversion}).}\\
108 % \href{mailto:guerquin-kernATcransDOTorg}{\texttt{guerquin-kern AT crans DOT org}}%
109 % }%
110 %
111 % \date{\today}
112 %
113 % \maketitle
114 %
115 % \begin{abstract}
116 % This document describes the \pkg{moodle} package, made for writing \Moodle\
117 % quizzes in \LaTeX. In addition to typesetting the quizzes for proofreading or
118 % giving to students as handout, the package generates an \XML\ file to be uploaded
119 % to a \Moodle\ server.
120 % \end{abstract}
121 %
122 % \tableofcontents
123 %
124 % \section{Introduction}
125 % \subsection{Motivation}
126 %
127 % The acronym \acro{Moodle} stands for ``Modular Object-Oriented Dynamic Learning Environment.''
128 % It is an open source learning management system (\LMS) employed by many universities,
129 % colleges, and high schools to provide digital access to course materials, such as
130 % notes, video lectures, forums, and the like; see
131 % \url{https://moodle.com/moodle-lms/} for more information.
132 % One of the many useful
133 % features of \Moodle\ is that mathematical and scientific notation can be entered in
134 % \LaTeX\ or \TeX\ code, which will be typeset either through a built-in \TeX\ filter
135 % or by invoking MathJax.
136 %
137 % For instructors who want to give students frequent feedback,
138 % but lack the time to do so, a particularly valuable module in \Moodle\
139 % is the \emph{quiz}. A \Moodle\ quiz can consist of several different types of
140 % questions---not only multiple choice or true/false questions, but also
141 % questions requiring a short phrase or numerical answer, and even essay
142 % questions. All but the essay questions are automatically graded by the
143 % system, and the instructor has full control over how often the quiz may be
144 % attempted, its duration, and so forth. Feedback can be tailored to specific
145 % mistakes the student makes.
146 %
147 % All these features make \Moodle\ quizzes very useful tools for instructors
148 % who have access to them.
149 % Unfortunately, the primary way to create or edit a \Moodle\ quiz
150 % is through a web-based interface that can be slow to operate.
151 % To users of \LaTeX, accustomed to the speed of typing source code on
152 % a keyboard alone, the agonizing slowness of switching between mouse and keyboard
153 % to navigate a web form with its myriad dropdown boxes, radio buttons,
154 % compounded with a perceptible time lag as one's \Moodle\ server responds to requests,
155 % can produce a very frustrating experience. Moreover, editing is entirely
156 % impossible without network access.
157 %
158 % Once the quiz is written, there is no easy way to view and proofread all the
159 % information of which it is made. Each question is edited on a separate webpage,
160 % which is so full of options that it cannot be viewed on a single screen.
161 % An instructor has to spend much time checking over the newly created quiz in
162 % order to be confident there are no errors.
163 %
164 % Added to all this is the frustration of managing graphics.
165 % If a question requires an image---say, asking a calculus student to interpret
166 % the graph of a function---the image must first be produced as a standalone file
167 % (e.g., in \JPG\ or \PNG\ format), uploaded to \Moodle, and then chosen in a web-based
168 % \HTML\ editor. Great is the vexation of the instructor who decided to alter a
169 % question, as there are more and more possibilities of error whenever multiple
170 % files must be kept synchronized.
171 %
172 % Users of \LaTeX\ are also accustomed to the speed and flexibility that
173 % comes from defining their own macros, which may be as brief as writing
174 % \cmd{\R} instead of |\mathbb{R}|
175 % or as complex as macros that generate entire paragraphs of text.
176 % The \Moodle\ editor, by contrast, requires you to type |\mathbb{R}|
177 % every single time you want $\mathbb{R}$.
178 %
179 % Finally, there is the question of archiving and reusing one's work.
180 % Much, much work goes into creating \Moodle\ quizzes, which then reside
181 % on a \Moodle\ server somewhere in the cloud in a format neither easily browsable
182 % nor easily modifiable.
183 %
184 % \LaTeX\ itself has the power to solve all these difficulties:
185 % it is swift to edit and swifter to compile a \LaTeX\ document,
186 % and the \PDF\ may be previewed onscreen or printed out for ease of proofreading.
187 % Mathematical graphics can be integrated within the main file through \TikZ,
188 % and of course \LaTeX\ macros can be customized.
189 % Using the present \pkg{moodle} package,
190 % a quiz author can type a quiz using familiar \LaTeX\ syntax and document
191 % structure. Upon compilation, \LaTeX\ will generate both a well-organized
192 % \PDF\ that is easy to proofread and an \XML\ file that can be uploaded directly
193 % to \Moodle. The entire process is far faster than using \Moodle's own
194 % web-based editor, makes it easier to catch one's mistakes,
195 % and the ultimate source code of one's work is a human-readable \filenm{.tex} file
196 % that can be archived, versioned, browsed, and edited offline.
197 %
198 % Strictly speaking, the \pkg{moodle} package does not generate quizzes:
199 % it generates question banks that can be imported in the \LMS. The teacher
200 % still needs to compose manually a quiz from the question banks. Hopefully,
201 % two \Moodle\ features supported by the package make this task easier:
202 % categories and tags.
203 %
204 % In this documentation the \LMS\ is referred to as \Moodle\
205 % (uppercase letters and roman font) while the \LaTeX\ package
206 % is referred to as \pkg{moodle} (lower case and sans serif font).
207 %
208 % \subsection{Workflow}
209 %
210 %% \begin{figure}[bp]
211 % \centering
212 % \begin{tikzpicture}[node distance=1,auto,bend
213 % angle=45,box/.style={rectangle,draw=blue!50,rounded corners=3,top
214 % color=white,bottom color=black!20,thick,align=center,text
215 % width=2.5cm},elmt/.style={font=\itshape,align=left},
216 % cmnt/.style={font=\footnotesize,align=center},
217 % bigcmnt/.style={font=\normalsize,align=center},pre/.style={<-,>=stealth',thick},
218 % post/.style={->,>=stealth',thick}, prepost/.style={<->,>=stealth',thick}]
219 % \draw[white,fill=orange!20,rounded corners=10]
220 % (-1.5,-.7)--++(0,1.4)--++(10.3,0)--++(0,-2.3)--++(-6.7,0)--++(-.25,.725)--cycle;
221 % \node[orange!80!black,above] (dev) at (7.5,-1.6) {\textit{Development}};
222 % \fill[green,fill opacity=.2,rounded corners=10]
223 % (-1.5,.7)--++(3,0)--++(0.5,-2.4)--++(6.8,0)--++(0,-3)--++(-10.3,0)--cycle;
224 % \node[green!80!black,below] (dev) at (7.5,-1.7) {\textit{Publishing}};
225 % \node[box,text width=2cm] (tex) {\filenm{.tex} source file};
226 % \node[rectangle,fill=white,draw,align=center,text
227 % width=1.5cm,below=of tex] (compfinal) {\LaTeX{}\\ engine};
228 % \node[rectangle,fill=white,draw,align=center,text width=1.5cm,right=of tex,xshift=4.5cm]
229 % (compdraft) {\LaTeX{}\\ engine};
230 % \draw ($(tex)!.5!(compdraft)+(0,-.7)$) node[box] (pdf) {\filenm{.pdf} file for proofreading};
231 % \node[box,below=of pdf,yshift=.1cm] (pdfhandout) {\filenm{.pdf} file for students};
232 % \node[rectangle,fill=white,draw,align=center,text width=2cm,below=of compfinal] (extern)
233 % {Picture\\processing};
234 % \draw (pdf|-extern) node[box,anchor=center] (xml) {\filenm{.xml} file\\\footnotesize(pictures embedded)};
235 % \draw (compdraft|-pdfhandout)
236 % node[rectangle,fill=white,draw,align=center,text width=1.5cm,anchor=center] (students)
237 % {Students};
238 % \draw (compdraft|-xml)
239 % node[rectangle,fill=white,draw,align=center,text width=1.5cm,anchor=center] (moodle)
240 % {\Moodle\ \\Server};
241 % \draw (tex) edge [post,bend right=10] node[cmnt,pos=.5,left] {\optn{final}}
242 % node[cmnt,pos=.5,right] {\optn{handout}} (compfinal);
243 % \draw (tex) edge [post,bend left=10] node[cmnt,pos=.5,below] {\optn{draft}} (compdraft);
244 % \draw (compdraft) edge [post,bend left=10] (pdf);
245 % \draw (compfinal) edge [post] node[cmnt,pos=.5,above,sloped]
246 % {\footnotesize(\optn{handout})} (pdfhandout);
247 % \draw[dashed] (compfinal) edge [post] (pdf);
248 % \draw (compfinal) edge [post,bend left=0] node[cmnt,pos=.55,below,sloped]
249 % {\footnotesize(\optn{final})} (xml);
250 % \draw (compfinal) edge [post,bend right=15] node[cmnt,black!40,pos=.5,text width=1cm,left]
251 % {\optn{tikz}, \filenm{.png}, \filenm{.jpg}} (extern);
252 % \draw (extern) edge [post,green,bend right=15] node[cmnt,black!40,pos=.5,below,right]
253 % {\prog{base64}} (compfinal);
254 % \draw (pdf) edge [post,red,bend left=15] node[sloped,cmnt,pos=.5,above] {improve} (tex);
255 % \draw (pdfhandout) edge [post,red] node[cmnt,pos=.5,below] {distribute} (students);
256 % \draw (xml) edge [post,red] node[cmnt,pos=.5,below] {import} (moodle);
257 % \end{tikzpicture}
258 % \caption{Block diagram describing a typical workflow using the \pkg{moodle} package.}
259 % \label{fig:workflow}
260 % \end{figure}
261 %
262 % The process of creating a quiz in \Moodle\ using this package is depicted in
263 % Figure~\vref{fig:workflow}. It follows a few
264 % steps:
265 % \begin{enumerate}
266 % \item Write a \LaTeX\ document using |\usepackage{moodle}| as described
267 % below.
268 % \item Compile the document to \PDF\ using pdf\LaTeX\ (\acro{ASCII} characters only),
269 % \XeLaTeX, or \LuaLaTeX.
270 % This will also produce the file \meta{jobname}\filenm{-moodle.xml}.
271 % \item navigate to your course on \Moodle\ and, under ``Question bank'', select ``Import.''
272 % \item Select ``Moodle \XML\ format,'' choose the \XML\ file to upload, and press ``Import.''
273 % \item After \Moodle\ verifies that the questions have been imported correctly,
274 % you may add them to your quizzes.
275 % \end{enumerate}
276 %
277 % \section{Usage}\label{sect:usage}
278 % The following pages presume the reader already has some familiarity with creating
279 % and editing \Moodle\ quizzes through the web interface.
280 % Users that are not familiar with \Moodle\ quizzes can learn more in the \Moodle\
281 % documentation. For instance, \url{https://docs.moodle.org/en/Question_types}.
282 %
283 % The \pkg{xkeyval} package is used to provide a key-value interface.
284 %
285 % \subsection{Example Document}
286 %
287 % Here is a simple example document:
288 % \begin{VerbatimOut}[gobble=1]{minted.doc.out}
289 % \documentclass[12pt]{article}
290 % \usepackage[section]{moodle}
291 % \moodleregisternewcommands
292 % \newcommand\monomial[1]{x^{#1}}
293 % \newcommand\sillyanswer{What!?}
294 % \begin{document}
295 % Quiz generated \LaTeX's \textsf{moodle} (\moodleversion, \moodledate).
296 % Import the derived file \texttt{\jobname-moodle.xml} on Moodle.
297 % \begin{quiz}{My first quiz}
298 % \begin{numerical}[points=2]{Basic addition}
299 % What is $8+3$?
300 % \item 11
301 % \end{numerical}
302 % \begin{shortanswer}[usecase]{Newton's name}
303 % What was Newton's first name?
304 % \item Isaac
305 % \item[fraction=0, feedback={\sillyanswer}] Fig
306 % \item[fraction=0] Sir
307 % \end{shortanswer}
308 % \begin{multi}[points=3]{A first derivative}
309 % What is the first derivative of $\monomial{3}$?
310 % \item $\frac{1}{4}\monomial{4}+C$
311 % \item[feedback={yes!}]* $3\monomial{2}$
312 % \item[feedback={\sillyanswer}] $51$
313 % \end{multi}
314 % \end{quiz}
315 % \end{document}
316 % \end{VerbatimOut}
317 % \inputminted[gobble=2,frame=lines]{latex}{minted.doc.out}
318 % Key features to note in this first example are that a \env{quiz} environment
319 % contains several question environments.
320 % Each question takes a name as a mandatory argument,
321 % and it may also take optional key-value arguments within brackets.
322 % The question environments resemble list environments
323 % such as \env{itemize} or \env{enumerate}, in that answers are set off by
324 % \cmd{\item}'s, but the question itself is the text that occurs before
325 % the first \cmd{\item}.
326 %
327 %^^A \DescribeMacro[moodle]{\moodleregisternewcommands}
328 %^^A \DescribeMacro[moodle]{\htmlregister}
329 %^^A Calling \cmb{\moodleregisternewcommands} tells the package to treat
330 %^^A specifically the macros defined subsequently.
331 %^^A This way, the macros that \Moodle's \LaTeX\ renderer does not know
332 %^^A about can be properly expanded in the \XML\ file.
333 %^^A This mechanism applies only to the macros defined using \cmd{\newcommand}
334 %^^A and \emph{without} optional argument.
335 %^^A Using \cmd{\htmlregister}\marg{macroname}, lets you declare a specific
336 %^^A macro for expansion. This mechanism, instead, also applies to the
337 %^^A macros defined using \TeX's primitive \cmd{\def}.
338 %
339 % \subsection{Package Options}
340 %
341 % \DescribeOption[moodle]{draft} If the package option \optn{draft} is invoked,
342 % by calling |\usepackage[draft]{moodle}| or |\documentclass[draft]{...}|,
343 % then no \XML\ file will be generated. This is especially useful while
344 % editing a quiz containing graphics, so as to avoid the time spent
345 % converting image files.
346 % \DescribeOption[moodle]{final} The package option \optn{final} might be
347 % useful if one wants to avoid the option \optn{draft} to be inherited from
348 % the \cmd{\documentclass}.
349 %
350 % \DescribeOption[moodle]{handout}
351 % If the package option \optn{handout} is invoked (|\usepackage[handout]{moodle}|),
352 % the \PDF\ file is generated clean from teacher-only information (answers,
353 % points, penalty, feedback, tags) and, hence, can be given to students
354 % for classroom work. In particular, as would \Moodle\ do, answers in
355 % \env{matching} questions are shuffled and the option \optn{shuffle}
356 % triggers the shuffling of choices offered (\env{multi} and
357 % \env{matching}). This is achieved thanks to the package
358 % \pkg{randomlist}, loaded if the option is invoked. The seed of its
359 % random generator is controlled by the macro \cmd{\RLsetrandomseed}\marg{integer}
360 % \DescribeMacro[randomlist]{\RLsetrandomseed}.
361 % This option does not interfere with the generation of the \XML\ file.
362 %
363 % \DescribeOption[moodle]{samepage}^^A\watchout[experimental]
364 % If the package option \optn{samepage} is invoked, preferably used together
365 % with \optn{handout} (|\usepackage[handout,samepage]{moodle}|), the package
366 % will try to keep every question on the same page. Very bad spacing
367 % can result from this.
368 % This option is experimental. Subquestions inside a \env{cloze} question
369 % are protected but the \env{cloze} question itself is not protected.
370 %
371 % \DescribeOption[moodle]{nostamp}
372 % By default, the package will output a stamp as a comment in the XML
373 % file. This stamp contains information gathered about the \TeX\ engine,
374 % the platform used and the package version. For instance:%
375 % \begin{quote}\small
376 % \makeatletter\def\today{\the\year-\two@digits\month-\two@digits\day}\makeatother
377 % \newcount\hour\hour=\time
378 % \divide\hour by 60\relax
379 % \newcount\minute\minute=\hour
380 % \multiply\minute by -60\relax
381 % \advance\minute by \time\relax
382 % |<!-- This XML file is a question bank made for Moodle. -->|\\
383 % |<!-- It was generated on |\texttt{\today\space\the\hour:\the\minute}| by LuaLaTeX running -->|\\
384 % |<!-- on Linux with the package moodle |\texttt{\fileversion}| (|\texttt{\filedate}|) -->|
385 % \end{quote}
386 % The package option |nostamp| prevents this
387 % stamp from being written in the \XML\ file.
388 %
389 % \DescribeOption[moodle]{section}\DescribeOption[moodle]{subsection}
390 % \DescribeOption[moodle]{section*}\DescribeOption[moodle]{subsection*}
391 % The package options \optn{section} and \optn{subsection} place each quiz as a
392 % new section or subsection, respectively. Starred variants
393 % correspond to unnumbered sections or subsections. To preserve
394 % compatibility with Version 0.5 of this package, the default is
395 % \optn{subsection*}. Consequently, |\usepackage[subsection*]{moodle}| is equivalent
396 % to |\usepackage{moodle}| .
397 %
398 % \DescribeOption[moodle]{tikz}
399 % The package option \optn{tikz} is described in Section~\vref{subsec:tikz}.
400 %
401 % \DescribeOption[moodle]{svg}^^A\watchout[experimental]
402 % The package option \optn{svg} is described in Section~\vref{subsec:svg}.
403 %
404 % \DescribeOption[moodle]{LMS}\texttt{=}\meta{\texttt{X.Y}}
405 % \DescribeDefault{warn only} lets you specify version numbers
406 % for the target \Moodle\ LMS instance (\texttt{X} and \texttt{Y} are
407 % major and minor version integers). When version numbers are provided,
408 % the use of recent quiz features is secured by a compatibility
409 % check and \pkg{moodle} raises relevant errors. The XML stamp
410 % (see \optn{nostamp} above) also mentions \Moodle's target version.
411 % By default, \pkg{moodle} will just issue warnings when recent quiz
412 % features are used.
413 %
414 % \subsection{Quiz and Question Environments}
415 %
416 % A \filenm{.tex} document to generate \Moodle\ quizzes contains one or more
417 % \env{quiz} environments.
418 %
419 % \DescribeEnv[moodle]{quiz}\oarg{common options}\marg{category name}
420 % defines a quiz, within which various question environments are nested.
421 % The mandatory argument, \meta{category name}, names a category for \Moodle's
422 % ``question bank'': after import, the questions defined in this environment
423 % will be gathered in this category.
424 % Using the optional argument, options can be set at the quiz level.
425 % Although there are no \env{quiz}-specific options, any \meta{common options} set
426 % with the quiz will be inherited by all questions contained within that environment.
427 %
428 % \DescribeMacro[moodle]{\moodleset}\marg{options}
429 % is to be used to set options outside question environments; the option
430 % settings are local to \TeX-groups.
431 %
432 % \DescribeMacro[moodle]{\setcategory}\marg{category name}
433 % is to be used to change the current category inside a quiz environment and
434 % in between questions. Note that the \env{quiz} environment defines a category
435 % by its own.
436 %
437 % \DescribeMacro[moodle]{\setsubcategory}\marg{subcategory name}
438 % does the same with subcategories.
439
440 % The categories and subcategories are reflected in the \PDF\ file as sections, subsections, or
441 % subsubsections, in accordance to the package setting \optn{section}, \optn{section*},
442 % \optn{subsection}, or \optn{subsection*}.
443 %
444 % The syntax for each question environment is
445 % \begin{quote}
446 % |\begin|\marg{question type}\oarg{question options}\marg{question name} \\
447 % \rule{2em}{0pt}\meta{question text} \\
448 % \rule{2em}{0pt}|\item|\oarg{item options} \meta{item} \\
449 % \rule{2em}{0pt}\quad$\vdots$ \\
450 % \rule{2em}{0pt}|\item|\oarg{item options} \meta{item} \\
451 % |\end|\marg{question type}
452 % \end{quote}
453 % The meaning of the \meta{item}s varies depending on the question type,
454 % but they usually are answers to the question.
455 % Details will be given below.
456 %
457 % The following key-value options may be set for all questions:
458 %
459 % \DescribeKey[quiz,question]{points}\DescribeDefault{1}
460 % \DescribeKey[quiz,question]{default grade}
461 % By default, each question is worth 1 point on the quiz.
462 % This setting may be changed with the \optn{points} key or its synonym, \optn{default grade}.
463 % For example, \optn{points=2} makes that question worth two points.
464 %
465 % \DescribeKey[quiz,question]{penalty}\DescribeDefault{0.1}
466 % The \optn{penalty} is the fraction of points that is taken off for each wrong attempt;
467 % it may be set to any value between 0 and 1.
468 %
469 % \DescribeKey[answer]{fraction}^^A\DescribeDefault{0}
470 % In most question types, it is possible to designate some answers as being
471 % worth partial credit---that is, some fraction of a completely correct answer.
472 % The \optn{fraction} key may be set to any of the values given in Table~\vref{tab:fraction},
473 % from \texttt{0} (entirely wrong) to \texttt{100} (entirely correct).
474 %
475 % \begin{table}[tbp]
476 % \centering
477 % \caption{\href{https://github.com/moodle/moodle/blob/MOODLE\_310\_STABLE/question/engine/bank.php\#L339}
478 % {Admissible positive values} for the \optn{fraction} key outside \env{cloze} environments: $100\cdot(p/q)$.}
479 % \label{tab:fraction}
480 % \footnotesize
481 % \begin{tabular}{l*{10}{l}}
482 % \toprule
483 % Denominator $q$ & \multicolumn{10}{c}{Numerator $p$}\\
484 % \cmidrule{2-11}
485 % & 0 & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9\\
486 % \cmidrule(lr){1-1}\cmidrule(lr){2-2}\cmidrule(lr){3-3}\cmidrule(lr){4-4}
487 % \cmidrule(lr){5-5}\cmidrule(lr){6-6}\cmidrule(lr){7-7}\cmidrule(lr){8-8}
488 % \cmidrule(lr){9-9}\cmidrule(lr){10-10}\cmidrule(lr){11-11}
489 % 20 & 0&5&&&&&&&&\\\cmidrule(lr){1-1}
490 % 10 & &10&20&30&40&50&60&70&80&90\\\cmidrule(lr){1-1}
491 % 9 & &11.11111&&&&&&&&100\\\cmidrule(lr){1-1}
492 % 8 & &12.5&&&&&&&100&\\\cmidrule(lr){1-1}
493 % 7 & &14.28571&&&&&&100&&\\\cmidrule(lr){1-1}
494 % 6 & &16.66667&&&&83.33333&100&&&\\\cmidrule(lr){1-1}
495 % 5 & &20&&&80&100&&&&\\\cmidrule(lr){1-1}
496 % 4 & &25&&75&100&&&&&\\\cmidrule(lr){1-1}
497 % 3 & &33.33333&66.66667&100&&&&&&\\\cmidrule(lr){1-1}
498 % 2 & &50&100&&&&&&&\\\cmidrule(lr){1-1}
499 % 1 & 0&100&&&&&&&&\\\cmidrule(lr){1-1}
500 % \bottomrule
501 % \end{tabular}
502 % \end{table}
503 %
504 % In questions where several choices can be selected (see \env{multi} with option
505 % \optn{multiple}), positive fractions must add up to exactly 100. It is also possible to set
506 % negative fractions (from -100 to 0) for wrong choices, in order to prevent the
507 % selection of all choices from leading to a good grade.
508 % In this case, the value ranging from -100 to 0 must be the opposite of one of the
509 % values listed in Table~\vref{tab:fraction}.
510 %
511 % \DescribeKey[answer]{fractiontol}\DescribeDefault{0.01}
512 % The package tries to match the \optn{fraction} key to one of the admissible values.
513 % To this end, the tolerance is controlled by the \optn{fractiontol} key. The default
514 % value, \texttt{0.01}, may be changed. When no admissible fraction value is matched, the
515 % package raises an error.
516 %
517 % \DescribeKey{feedback}
518 % The \optn{feedback} key sets text that will appear to the student after completing the quiz.
519 % For example, one might set
520 % \begin{center}
521 % |feedback={This question might show up in the final exam.}|
522 % \end{center}
523 % The desired feedback should be included in braces.
524 %
525 % \DescribeKey[question]{feedback}If the \optn{feedback} key is set for a question,
526 % then that feedback will appear to each student regardless of the student's answer.
527 %
528 % \DescribeKey[answer]{feedback}
529 % Answer-specific feedback (perhaps explaining a common mistake)
530 % may also be given by setting the \optn{feedback} key \emph{at the individual answer}.
531 %
532 % \DescribeKey{tags}
533 % The \optn{tags} key sets a list of keywords for the question that will be taken into account
534 % by \Moodle\ for filtering purposes or classification of questions inside the question bank.
535 % It is possible for instance to build a quiz with questions cherry-picked among the set of
536 % questions holding a particular tag.
537 % For example, one might set
538 % \begin{center}
539 % |tags={easy}|
540 % \end{center}
541 % The desired tag should be specified in between braces. Multiple tags can be set as a
542 % comma-separated list:
543 % \begin{center}
544 % |tags={tag1,tag2,{ leading whitespace},{including, comma}}|
545 % \end{center}
546 %
547 % \DescribeKey[quiz]{tags}
548 % If the \optn{tags} key is set at the quiz level,
549 % then that tag list will serve as a default for each question of the quiz.
550 %
551 % \DescribeKey[question]{tags}
552 % Question-specific tags can be assigned by setting the \optn{tags} key \emph{at the question level}.
553 % The question-level \optn{tags} key overrides eventual quiz-level tags.
554 %
555 % Users willing to specify a same tag for all questions of the quiz could
556 % also consider relying on \Moodle's category mechanism.
557 %
558 % \subsection{\href{https://docs.moodle.org/en/Question_types}{Question Types}}
559 %
560 % We next discuss the various question types supported by \pkg{moodle}
561 % and the options that may be set.
562 %
563 %\subsubsection{\href{https://docs.moodle.org/en/True/False_question_type}{True/False}}
564 %
565 % \DescribeEnv[quiz]{truefalse}\oarg{question options}\marg{question name}
566 % is an environment that defines a \emph{True/False} question.
567 %
568 % The syntax for a True/False question is as follows:
569 % \begin{quote}
570 % |\begin{truefalse}|\oarg{question options}\marg{question name} \\
571 % \rule{2em}{0pt}\meta{question text} \\
572 % \rule{2em}{0pt}|\item*| \meta{feedback when ``true" is chosen} \\
573 % \rule{2em}{0pt}|\item| \meta{feedback when ``false" is chosen} \\
574 % |\end{truefalse}|
575 % \end{quote}
576 % The correct answer is designated by the asterisk \texttt{*} after the \cmd{\item};
577 % it need not appear first in the list.
578 %
579 % Answer-specific feedback can also be defined as an item option, similarly to
580 % other types.
581 % \begin{quote}
582 % |\begin{truefalse}|\oarg{question options}\marg{question name} \\
583 % \rule{2em}{0pt}\meta{question text} \\
584 % \rule{2em}{0pt}|\item[feedback={|\meta{When ``true" is chosen}|}]*| \\
585 % |\end{truefalse}|
586 % \end{quote}
587 % Note that, in this example, no feedback is defined for the incorrect answer
588 % ``False": the corresponding item can be omitted.
589 %
590 % With the True/False question type, the |penalty| key has no effect.
591 %
592 % \subsubsection{\href{https://docs.moodle.org/en/Multiple_Choice_question_type}{Multiple Choice}}
593 % \label{subsec:multi}
594 %
595 % \DescribeEnv[quiz]{multi}\oarg{question options}\marg{question name}
596 % is an environment that defines a \emph{Multiple Choice} question.
597 %
598 % The syntax for a classic multiple choice question,
599 % with only one correct answer, is as follows:
600 % \begin{quote}
601 % |\begin{multi}|\oarg{question options}\marg{question name} \\
602 % \rule{2em}{0pt}\meta{question text} \\
603 % \rule{2em}{0pt}|\item|\oarg{answer options}|*| \meta{correct answer} \\
604 % \rule{2em}{0pt}|\item|\oarg{answer options} \meta{wrong answer} \\
605 % \rule{2em}{0pt}\quad$\vdots$ \\
606 % \rule{2em}{0pt}|\item|\oarg{answer options} \meta{wrong answer} \\
607 % |\end{multi}|
608 % \end{quote}
609 % The correct answer is designated by the asterisk \texttt{*} after the \cmd{\item};
610 % it need not appear first in the list.
611 %
612 %
613 % \DescribeBoolean[multi]{shuffle}\DescribeDefault{true}
614 % The Boolean key \optn{shuffle} determines whether \Moodle\ will
615 % rearrange the possible answers in a random order.
616 % Setting \optn{shuffle=false} will guarantee that the answers will
617 % be presented to the student in the order they were typed.
618 %
619 % \DescribeKey[multi]{numbering}\DescribeDefault{abc}
620 % \Moodle\ offers different options for numbering the possible answers.
621 % You may set the \optn{numbering} key to any of the values listed in
622 % Table~\vref{tab:numbering_options}.
623 % \begin{table}[tbp]
624 % \centering
625 % \caption{Numbering modalities offered for \env{multi} questions.}
626 % \label{tab:numbering_options}
627 % \begin{tabular}{rllllll}
628 % \toprule
629 % Sample & a., b., \dots & A., B., \dots & 1., 2., \dots & i., ii., \dots &
630 % I., II., \dots & $\bullet$ \\
631 % \cmidrule(lr){2-2}\cmidrule(lr){3-3}\cmidrule(lr){4-4}\cmidrule(lr){5-5}\cmidrule(lr){6-6}
632 % \cmidrule(lr){7-7}
633 % \LaTeX\ syntax & \optn{alph} & \optn{Alph} & \optn{arabic} & \optn{roman} & \optn{Roman} & \optn{none}\\
634 % \Moodle\ syntax & \optn{abc} & \optn{ABCD} & \optn{123} & \optn{iii} & \optn{IIII} & \optn{none} \\
635 % \bottomrule
636 % \end{tabular}
637 % \end{table}
638 % \optn{numbering=none} produces an unnumbered list of answers.
639 % Note the \emph{four} capital letters required by \Moodle's syntax
640 % to obtain upper-case Roman or alphabetic numerals.
641 %
642 % \DescribeKey[item]{fraction}\DescribeDefault{0}
643 % \DescribeKey[item*]{fraction}\DescribeDefault{100}
644 % The \optn{fraction} key may be automatically set depending on the
645 % presence of an asterisk \texttt{*} right after the \cmd{\item}. By default,
646 % Starred items designate correct answers (\optn{fraction=100}) while
647 % bare items designate incorrect answers (\optn{fraction=0}).
648 % The key can be used to designate some wrong answers as being worth
649 % partial credit or sanction. For example, a question might read
650 % \begin{VerbatimOut}[gobble=1]{minted.doc.out}
651 % \begin{multi}{my question}
652 % Compute $\int 4x^3\,dx$.
653 % \item* $x^4+C$
654 % \item[fraction=50] $x^4$
655 % \item $12x^2$
656 % \end{multi}
657 % \end{VerbatimOut}
658 % \inputminted[gobble=2,frame=lines]{latex}{minted.doc.out}
659 %
660 % \DescribeBoolean[multi]{single}\DescribeDefault{true}
661 % By default, the \env{multi} environment produces a multiple choice
662 % question where only one answer can be selected. This is called
663 % \optn{single} mode.
664 %^^A On \Moodle, the choices are displayed with radio
665 %^^A buttons and only one of them can be selected by the student.
666 %
667 % In \optn{single} mode, the teacher can set negative fractions for
668 % incorrect choices. This way, the expected grade of a student
669 % picking up choices randomly across a quiz is lowered.
670 % By default, incorrect answers that do not have a fraction
671 % specified correspond to \optn{fraction=0}.
672 % \DescribeKey[quiz,multi]{sanction}\DescribeDefault{0} However,
673 % if the \optn{sanction} key is set to a positive value, at quiz or
674 % question levels, such incorrect answers are sanctioned as if
675 % \optn{fraction=-}\meta{sanction value} was set for each of them.
676 %
677 % \DescribeKey[multi]{multiple}
678 % It is also possible to write questions with possibly more than
679 % one correct answer, asking the user to check all correct answers.
680 % To do this, use the key \optn{multiple} or \optn{single=false}.
681 % For this kind of question, the student gets a grade that
682 % corresponds to the total of the weights of the answers selected.
683 % Users may rely on two modalities to set the weights of the answers:
684 % \begin{enumerate}
685 % \item the \emph{advanced mode} applies whenever a \optn{fraction} key
686 % is set among the proposed answers. In this case, it is recommended
687 % that the user sets manually everything. Answers that are left with
688 % no fraction set are considered as neutral, selecting them will
689 % not change the grade. If \cmd{\item*} is used to designate some correct
690 % answers, \pkg{moodle} will distribute equally among those answers
691 % the points that are left for a total of 100\% (only positive
692 % fractions count here). Note that doing so will easily yield
693 % situations where the weights are inadmissible (see
694 % Table~\vref{tab:fraction}).
695 % \item the \emph{automatic mode} applies when correct answers are
696 % designated using \cmd{\item*} and no answer has a \optn{fraction} key set.
697 % In this case, each correct answer is weighted to bring the same
698 % fraction of the maximum grade and each incorrect answer is
699 % weighted to cancel the benefits of the selection of one correct
700 % answer.
701 % \end{enumerate}
702 % For example, the following two examples are equivalent:
703 % \begin{VerbatimOut}[gobble=1]{minted.doc.out}
704 % \begin{multi}[multiple]{Automatic Mode}
705 % Which numbers are prime?
706 % \item 2
707 % \item* 5
708 % \item* 7
709 % \item 1
710 % \item 6
711 % \end{multi}
712 % \begin{multi}[multiple]{Advanced Mode}
713 % Which numbers are prime?
714 % \item[fraction=-50] 2
715 % \item[fraction=50] 5
716 % \item[fraction=50] 7
717 % \item[fraction=-50] 1
718 % \item[fraction=-50] 6
719 % \end{multi}
720 % \end{VerbatimOut}
721 % \inputminted[gobble=2,frame=lines]{latex}{minted.doc.out}
722 % Note that, in this example, negative fractions are set for wrong
723 % choices. This prevents students from obtaining a good grade with
724 % no merit if they select all answers.
725 %
726 % Contrarily to the \optn{single} mode where questions with negative fractions may
727 % lead to a overall negative grade, when multiple choices can be selected, the
728 % lowest grade \Moodle\ will take into account for the question is 0.
729 %
730 % \DescribeKey[multi]{allornothing}
731 % There also exists a \href{https://moodle.org/plugins/qtype_multichoiceset}
732 % {``All-or-Nothing Multiple Choice''} plugin for \Moodle\ that introduces a
733 % question type similar to a multiple choice with multiple correct answers,
734 % with the specificity that the points are given if and only if the student
735 % selects all correct answers. This kind of question is set up using the
736 % \optn{allornothing} key.
737 % The recommended way for designating correct answers is with \cmd{\item*}. If instead
738 % the \optn{fraction} is used, \pkg{moodle} will consider that non-negative
739 % fractions ($>0$) designate correct answers and negative fractions ($\leq 0$)
740 % designate incorrect choices.
741 % The option \optn{allornothing} supersedes the options \optn{multiple} and \optn{single}.
742 % To the best of our knowledge, \Moodle\ does not offer the all-or-nothing behavior
743 % for multiple choice questions embedded inside a \env{cloze} question.
744 %
745 % \subsubsection{\href{https://docs.moodle.org/en/Numerical_question_type}{Numerical}}
746 %
747 % \DescribeEnv[quiz]{numerical}\oarg{question options}\marg{question name}
748 % is an environment that defines a \emph{Numerical} question which, in \Moodle, requires the student
749 % to input a real number in decimal form.
750 %
751 % The typical format for this question type is:
752 % \begin{quote}
753 % |\begin{numerical}|\oarg{question options}\marg{question name} \\
754 % \rule{2em}{0pt}\meta{question text} \\
755 % \rule{2em}{0pt}|\item|\oarg{answer options} \meta{correct answer} \\
756 % |\end{numerical}|
757 % \end{quote}
758 % If there is more than one correct answer, additional \cmd{\item}'s may be included.
759 % Because this is not a multiple choice question, there is no need to provide
760 % incorrect answers. There may nevertheless be reasons to include incorrect answers.
761 % For example, partially correct answers may be specified by setting the \optn{fraction} key.
762 % Feedback for a common mistake may be given by including the incorrect answer like this:
763 % \begin{quote}\footnotesize
764 % |\item[fraction=0,feedback={Forgot to antidifferentiate?}]| \meta{incorrect answer}
765 % \end{quote}
766 %
767 % \DescribeKey[numerical]{tolerance}\DescribeDefault{0}
768 % The \optn{tolerance} key can be used to specify the validity of answers within some margin.
769 % This key can be set at different levels: quiz, question, item.
770 % For example, with the question
771 % \begin{VerbatimOut}[gobble=1]{minted.doc.out}
772 % \begin{numerical}[tolerance=0.01]{my question}
773 % Approximate value of $\sqrt{2}$?
774 % \item[tolerance={1e-1}] 1.4142
775 % \item[fraction=20,feedback={twice this!}] 7.0711e-1
776 % \item[fraction=0,feedback={Wrong!}] *
777 % \end{numerical}
778 % \end{VerbatimOut}
779 % \inputminted[gobble=2,frame=lines]{latex}{minted.doc.out}
780 % In this example,
781 % \begin{itemize}
782 % \item any answer in the range $[1.4042,1.4242]$ will be validated,
783 % \item any answer in the range $[0.69711,0.71711]$ will get the specific feedback
784 % \emph{twice this!} and 20\% of points,
785 % \item any other answer is incorrect and will get the specific feedback
786 % \emph{Wrong!}.
787 % \end{itemize}
788 %
789 % When feedback is to be given for any non-specified answer, one can add a \emph{last} answer
790 % item containing the wildcard character \texttt{*} only. In this case, the \optn{tolerance} key is irrelevant.
791 %
792 % Both answers and tolerance can be specified with the comma (\texttt{,}) as a decimal separator.
793 % Exponent notation is accepted. After import, \Moodle\ will recognize indifferently \texttt{0.000165},
794 % \texttt{0,000165}, \texttt{1.65E-4}, \texttt{1.65e-4}, \texttt{1,65E-4}, and \texttt{1,65e-4}.
795 %
796 % If the \pkg{siunitx} package is loaded, \pkg{moodle} will detect it and
797 % numbers will be rendered nicely in the \PDF\ output.
798 %
799 % Units, unit-handling and multipliers are currently unsupported.\watchout
800 %
801 % \subsubsection{\href{https://docs.moodle.org/en/Short-Answer_question_type}{Short Answer}}
802 %
803 % \DescribeEnv[quiz]{shortanswer}\oarg{question options}\marg{question name}
804 % is an environment that defines a \emph{Short Answer} question. It resembles
805 % a \env{numerical} question: the student is to fill in a text box with a
806 % missing word or phrase.
807 % \begin{quote}
808 % |\begin{shortanswer}|\oarg{question options}\marg{question name} \\
809 % \rule{2em}{0pt}\meta{question text} \\
810 % \rule{2em}{0pt}|\item|\oarg{answer options} \meta{correct answer} \\
811 % \rule{2em}{0pt}\quad$\vdots$ \\
812 % \rule{2em}{0pt}|\item|\oarg{answer options} \meta{correct answer} \\
813 % |\end{shortanswer}|
814 % \end{quote}
815 % You can make the text box appear as part of the question with the
816 % control sequence \cmd{\blank}. For example,
817 % your question might read
818 % \begin{VerbatimOut}[gobble=1]{minted.doc.out}
819 % \begin{shortanswer}{Leibniz}
820 % Newton's rival was Gottfried Wilhelm \blank.
821 % \item Leibniz
822 % \item Leibniz.
823 % \end{shortanswer}
824 % \end{VerbatimOut}
825 % \inputminted[gobble=2,frame=lines]{latex}{minted.doc.out}
826 % Note that as the blank occurred at the end of a sentence,
827 % we included two answers,
828 % lest students get the question wrong merely by
829 % including or omitting a period.
830 %
831 % \DescribeBoolean[shortanswer]{case sensitive}\DescribeDefault{false}
832 % The default setting when creating a Short Answer question in \Moodle\
833 % is to ignore the distinction between upper- and lower-case letters
834 % when grading a short answer question. This default is preserved by
835 % \pkg{moodle}.
836 % You can make a question case-sensitive with the Boolean key
837 % \optn{case sensitive} or its shorter synonym \optn{usecase}\DescribeBoolean[shortanswer]{usecase}.
838 %
839 % The \href{https://docs.moodle.org/en/Short-Answer_question_type#Wildcard_usage}%
840 % {wildcard character} \texttt{*} can used to grab answers that match
841 % a specific pattern. Following the order of answers, the first match will lead
842 % to the corresponding score and eventual feedback. As an example, take the
843 % following question
844 % \begin{VerbatimOut}[gobble=1]{minted.doc.out}
845 % \begin{shortanswer}[usecase]{Newton's name}
846 % What was Newton's first name?
847 % \item Isaac
848 % \item[fraction=0,feedback={Simply Isaac!}] Isaa*
849 % \item[fraction=0,feedback={This one is Leibniz!}] *Gottfried*
850 % \item[fraction=0,feedback={First name, not title!}] Sir*
851 % \item[fraction=0,feedback={No\dots}] *
852 % \end{shortanswer}
853 % \end{VerbatimOut}
854 % \inputminted[gobble=2,frame=lines]{latex}{minted.doc.out}
855 % \begin{itemize}\def\answ#1{\framebox{\texttt{#1}}}%
856 % \item the answer \answ{Isaac} is the only one that gets rewarded,
857 % \item answers \answ{Isaac Leibniz}, \answ{Isaac Newton}, and \answ{Isaak} yield
858 % the feedback \emph{Simply Isaac!},
859 % \item answers \answ{Sir Gottfried Wilhelm}, \answ{Sir Gottfried},
860 % \answ{Gottfried Wilhem}, and \answ{Gottfried} yield
861 % the feedback \emph{This one is Leibniz!},
862 % \item answers \answ{Sir Isaac}, and \answ{Sir} yield
863 % the feedback \emph{First name, not title!},
864 % \item any answer that does not match the previous patterns
865 % yields the feedback \emph{No\dots}.
866 % \end{itemize}
867 %
868 % \subsubsection{\href{https://docs.moodle.org/en/Essay_question_type}{Essay}}\label{subsubsect:essay}
869 %
870 % \DescribeEnv[quiz]{essay}\oarg{question options}\marg{question name}
871 % is an environment that defines an \emph{Essay} question.
872 %
873 % Instructors may ask essay questions on a \Moodle\ quiz,
874 % although \Moodle's software is not up to the task of grading them!
875 % Instead, each essay question answer must be graded manually by the
876 % instructor or a teaching assistant.
877 % \begin{quote}
878 % |\begin{essay}|\oarg{question options}\marg{question name} \\
879 % \rule{2em}{0pt}\meta{question text} \\
880 % \rule{2em}{0pt}|\item| \meta{information 1 for grader} \\
881 % \rule{2em}{0pt}\quad$\vdots$ \\
882 % \rule{2em}{0pt}|\item| \meta{information $n$ for grader} \\
883 % |\end{essay}|
884 % \end{quote}
885 % Instead of containing answers, the \cmd{\item} entries included in the \env{essay}
886 % question contain notes that will appear to whoever is grading the question manually.
887 % Contrarily to other question types, \cmd{\item} in \env{essay} questions
888 % do not take options.
889 %
890 % \DescribeBoolean[essay]{response required}\DescribeDefault{false}
891 % Although \Moodle\ cannot grade the content of an essay question,
892 % it can at least determine whether the question has been left blank.
893 % If the \optn{response required} key is set, \Moodle\ will insist that the student
894 % enter something in the blank before accepting the quiz as completed.
895 %
896 % \DescribeKey[essay]{response format}\DescribeDefault{html}
897 % \Moodle\ offers five different ways for students to enter and/or upload their
898 % answers to an essay question. You may choose one of these five options:
899 % \begin{description}
900 % \ItemDescribeOther[response format]{html} An editor with the ability to format \HTML\ responses
901 % including markup for italics, boldface, etc. This is the default.
902 % \ItemDescribeOther[response format]{file} A file picker allowing the student to upload a
903 % file, such as a \PDF\ or DOC file, containing the essay.
904 % \ItemDescribeOther[response format]{html+file} The same \HTML\ editor as above, but with the
905 % ability to upload files as well. This permits some students to type
906 % answers directly into the web form, and others to compose their
907 % essays in another program first.
908 % \ItemDescribeOther[response format]{text} This editor allows only for entering plain text
909 % without any markup.
910 % \ItemDescribeOther[response format]{monospaced} This yields a plain text editor, without any
911 % markup, and with a fixed-width font. This could be useful for
912 % entering code snippets, for example.
913 % \end{description}
914 %
915 % \DescribeKey[essay]{response field lines}\DescribeDefault{15}
916 % The key \optn{response field lines} controls the height of the input box.
917 % For \Moodle, the admissible values are: 5, 10, 15, 20, 25, 30, 35, and 40.
918 % If the value set is not admissible, \pkg{moodle} will approximate the value:
919 % \begin{itemize}
920 % \item with either 5 or 40 if the value set was out of range, or
921 % \item with the next multiple of 5 otherwise.
922 % \end{itemize}
923 %
924 % \DescribeKey[essay]{attachments allowed}\DescribeDefault{0}
925 % The \optn{attachments allowed} key controls \emph{how many} attachments a student is
926 % allowed to upload. Admissible values are \texttt{0}, \texttt{1}, \texttt{2},
927 % \texttt{3}, or \texttt{unlimited}.
928 %
929 % \DescribeKey[essay]{attachments required}\DescribeDefault{0}
930 % You may also require the student to upload a certain number of attachments
931 % by setting \optn{attachments required} to \texttt{0}, \texttt{1}, \texttt{2}, or \texttt{3}.
932 %
933 % \DescribeKey[essay]{template}
934 % Finally, you may preload the essay question with a template that the student
935 % will edit and/or type over, with the key \optn{template=}\marg{template}.
936 % The \meta{template} should be enclosed in braces.
937 %
938 % \subsubsection{\href{https://docs.moodle.org/en/Matching_question_type}{Matching}}
939 %
940 % \DescribeEnv[quiz]{matching}\oarg{question options}\marg{question name}
941 % is an environment that defines a \emph{Matching} question. It typically
942 % looks like this:
943 % \begin{quote}
944 % |\begin{matching}|\oarg{question options}\marg{question name} \\
945 % \rule{2em}{0pt}\meta{question text} \\
946 % \rule{2em}{0pt}|\item| \meta{item 1} |\answer| \meta{match 1}\\
947 % \rule{2em}{0pt}|\item| \meta{item 2} |\answer| \meta{match 2}\\
948 % \rule{2em}{0pt}\quad$\vdots$ \\
949 % \rule{2em}{0pt}|\item| \meta{item $m$} |\answer| \meta{match $m$}\\
950 % \rule{2em}{0pt}|\item| |\answer| \meta{no match $1$}\\
951 % \rule{2em}{0pt}\quad$\vdots$ \\
952 % \rule{2em}{0pt}|\item| |\answer| \meta{no match $n$}\\
953 % |\end{matching}|
954 % \end{quote}
955 % \meta{match}es $1$ through $m$ are separated from their corresponding
956 % \meta{item}s by the command \cmd{\answer}\DescribeMacro[matching]{\answer}.
957 % Answers that match no item can be proposed at the end of the list,
958 % preceded by an empty item.
959 %
960 % After import, \Moodle\ will recognize matches that are \emph{exact}
961 % duplicates. If you intend multiple questions to have the same match,
962 % make sure that they are entered identically.
963 %
964 % \DescribeBoolean[matching]{shuffle}\DescribeDefault{true}
965 % When students take a matching question, \Moodle\ always displays
966 % the proposed matches in random order.
967 % The \env{matching} question accepts the option |shuffle| to also
968 % randomly permute the items.
969 %
970 % \DescribeBoolean[matching]{drag and drop}\DescribeDefault{false}
971 % The standard matching question offered by \Moodle\ corresponds to
972 % a dropdown box for choosing the match for each item.
973 % There also exists a \href{https://docs.moodle.org/en/Drag_and_drop_matching_question_type}
974 % {``drag and drop matching''} plugin for \Moodle\ that
975 % shows all items in a column (left), all proposed matches in a second column
976 % (right), and asks students to drag the correct
977 % match to each item with the mouse.
978 % In this package, to enable drag-and-drop matching, use the key
979 % \optn{drag and drop} or \optn{dd}\DescribeKey[matching]{dd}\ for short.
980 % Beware that, with the standard format (\optn{drag and drop=false}), due
981 % to the limitations of dropdown boxes, \Moodle\ will not render \LaTeX\
982 % or \HTML\ code passed in the answers.
983 %
984 % \subsubsection{\href{https://docs.moodle.org/en/Embedded_Answers_(Cloze)_question_type}
985 % {Cloze Questions and Subquestions}}
986 %
987 % \DescribeEnv[quiz]{cloze}\oarg{question options}\marg{question name}
988 % is an environment that defines a \emph{Cloze} question.
989 %
990 % A ``cloze question'' has one or more subquestions embedded within a passage of text.
991 % For example, you might ask students to fill in several missing words within
992 % a sentence, or calculate several coefficients of a polynomial.
993 % To encode cloze questions in \LaTeX\ using this package is easy:
994 % you simply nest one or more \env{multi}, \env{numerical}, or \env{shortanswer} environments
995 % within a \env{cloze} environment, as in the following example:
996 % \begin{VerbatimOut}[gobble=1]{minted.doc.out}
997 % \begin{cloze}{my cloze question}
998 % Thanks to calculus, invented by Isaac
999 % \begin{shortanswer}[usecase]
1000 % \item Newton
1001 % \end{shortanswer},
1002 % we know that the derivative of $x^2$ is
1003 % \begin{multi}[horizontal]
1004 % \item $2x$
1005 % \item* $\frac{1}{3} x^3 + C$
1006 % \item $0$
1007 % \end{multi}
1008 % and that $\int_0^2 x^2\,dx$ equals
1009 % \begin{numerical}
1010 % \item[tolerance={4e-4}] 2.667
1011 % \end{numerical}.
1012 % Thanks, Isaac!
1013 % \end{cloze}
1014 % \end{VerbatimOut}
1015 % \inputminted[gobble=2,frame=lines]{latex}{minted.doc.out}
1016 %
1017 % Note that, when used as a subquestion within a \env{cloze} question,
1018 % the question environments are \emph{not} followed by a question
1019 % name in braces.
1020 % \begin{description}
1021 % \ItemDescribeEnv[cloze]{multi}\oarg{subquestion options} defines a
1022 % Multiple Choice question inside a Cloze question,
1023 % \ItemDescribeEnv[cloze]{numerical}\oarg{subquestion options} defines a
1024 % Numerical question inside a Cloze question, and
1025 % \ItemDescribeEnv[cloze]{shortanswer}\oarg{subquestion options} defines a
1026 % Shortanswer question inside a Cloze question,
1027 % \end{description}
1028 %
1029 % \DescribeKey[cloze]{points}\DescribeDefault{1}
1030 % \DescribeKey[cloze]{default grade}
1031 % Inside \env{cloze} environments, the \optn{points} or \optn{default grade}
1032 % keys can be used to weight the worth of each subquestion. A specific
1033 % constraint applies: the values should be positive integers.
1034 %
1035 % \DescribeKey[cloze]{fraction}
1036 % Inside \env{cloze} environments, the \optn{fraction} key can be used to give
1037 % partial credit or sanction for certain answers. The values
1038 % specified must be integers and are independent of the admissible
1039 % values listed in Table~\vref{tab:fraction}.
1040 %
1041 % \DescribeBoolean[cloze]{single}\DescribeDefault{true}
1042 % \DescribeKey[cloze]{multiple}
1043 % Prior to \Moodle\ version 3.5, within a \env{cloze} question, a multiple choice question
1044 % was necessarily of type \optn{single}, i.e. with a single good answer. If you intend
1045 % to export your quiz to \Moodle\ 3.5+, the option \optn{multiple} can be used for
1046 % questions where students must be able to select several answers.
1047 % The modalities described in Section~\vref{subsec:multi} for setting the
1048 % weight of answers apply. The only difference occurs in \emph{advanced mode}:
1049 % the sum of positive fractions may not be 100\%. In this case, after
1050 % importing the \XML\ file, \Moodle\ will automatically scale the positive
1051 % fractions for a total of 100\% and leave intact the negative fractions.
1052 % ^^A\footnote{\url{https://tracker.moodle.org/browse/MDL-3782?focusedCommentId=421564\#comment-421564}}.
1053 %
1054 % ^^A\DescribeKey[cloze]{vertical}\DescribeKey[cloze]{horizontal}\DescribeKey[cloze]{inline}
1055 % ^^A\DescribeDefault{inline}
1056 % Within a \env{cloze} question, a multiple choice question may be displayed in three
1057 % different modes:
1058 % \begin{description}
1059 % \ItemDescribeKey[cloze]{inline} The inline dropdown box is the default choice
1060 % when only one answer is to be selected (option \optn{single}). The dropdown box
1061 % is visually compact, but also prevents the use of mathematical or \HTML\ formatting.
1062 % This option is incompatible\watchout\ with \optn{multiple} or \optn{single=false}
1063 % (dropdown boxes don't let you pick up several answers!).
1064 % \ItemDescribeKey[cloze]{vertical} displays the subquestion as a vertical column
1065 % of radio buttons instead. This is the default when several items can
1066 % be selected (options \optn{multiple} or \optn{single=false}).
1067 % \ItemDescribeKey[cloze]{horizontal} creates a horizontal row of radio buttons.
1068 % This option works well when the possible answers are short. The result is more
1069 % compact than what \optn{vertical} gives.
1070 % \end{description}
1071 %
1072 % \DescribeBoolean[cloze]{shuffle}
1073 % Starting from \Moodle\ version 3.0, within a \env{cloze} question, the items of a
1074 % multiple choice question can be shuffled. Setting \optn{shuffle=false} will
1075 % guarantee that the answer appear in the order they were typed; the
1076 % default is \optn{shuffle=true}.
1077 %
1078 % \DescribeBoolean[cloze]{case sensitive}\DescribeDefault{false}
1079 % \DescribeBoolean[cloze]{usecase}
1080 % Within a \env{cloze} question, the \env{shortanswer} question can be made case sensitive.
1081 % This option, disabled by default, is selected with \optn{case sensitive} or \optn{usecase}.
1082 %
1083 %\subsubsection{\href{https://docs.moodle.org/en/Description_question_type}{Description}}
1084 %
1085 % \DescribeEnv[quiz]{description}\oarg{question options}\marg{question name}
1086 % is an environment that defines a so-called \emph{Description} question.
1087 %
1088 % The \Moodle\ description type is not really a question. It is more like a label.
1089 % One can set a \optn{feedback} that the student gets when reviewing the submission.
1090 % Tags can be set as well.
1091 %
1092 % For descriptions, \pkg{moodle} redefines \LaTeX's \env{description} environment.
1093 % The scope of this redefinition is limited to the \env{quiz} environment.
1094 %
1095 % The syntax for a Description question is as follows:
1096 % \begin{quote}
1097 % |\begin{description}|\oarg{question options}\marg{question name} \\
1098 % \rule{2em}{0pt}\meta{question text} \\
1099 % |\end{description}|
1100 % \end{quote}
1101 %
1102 % \subsection{Summary of the Key Options}
1103 %
1104 % Table~\vref{tab:key-options}, summarizes
1105 % the key options available at the question and answer levels depending on the
1106 % question type. For the essay questions, please refer to Section~\vref{subsubsect:essay}.
1107 %
1108 % \begin{table}[tbp]
1109 % \centering
1110 % \caption{Options offered at the question and answer levels for each question type.}
1111 % \label{tab:key-options}
1112 % \small
1113 % \begin{tabular}{*{15}{l}}
1114 % \toprule
1115 % & \multicolumn{11}{l}{Question} & \multicolumn{3}{l}{Answer}\\
1116 % \cmidrule(lr){2-12}\cmidrule(lr){13-15}
1117 % Question type & \rotatebox{90}{points} &
1118 % \rotatebox{90}{penalty} & \rotatebox{90}{feedback} & \rotatebox{90}{tags} &
1119 % \rotatebox{90}{shuffle} & \rotatebox{90}{numbering} & \rotatebox{90}{multiple} &
1120 % \rotatebox{90}{allornothing} &\rotatebox{90}{usecase} & \rotatebox{90}{tolerance} &
1121 % \rotatebox{90}{dd} & \rotatebox{90}{fraction} & \rotatebox{90}{feedback} &
1122 % \rotatebox{90}{tolerance}\\\cmidrule(lr){1-1}\cmidrule(lr){2-2}\cmidrule(lr){3-3}
1123 % \cmidrule(lr){4-4}\cmidrule(lr){5-5}\cmidrule(lr){6-6}\cmidrule(lr){7-7}
1124 % \cmidrule(lr){8-8}\cmidrule(lr){9-9}\cmidrule(lr){10-10}\cmidrule(lr){11-11}
1125 % \cmidrule(lr){12-12}\cmidrule(lr){13-13}\cmidrule(lr){14-14}\cmidrule(lr){15-15}
1126 % \href{https://docs.moodle.org/35/en/Multiple_Choice_question_type}
1127 % {Multichoice} & $\bullet$ & $\bullet$ & $\bullet$ & $\bullet$ &
1128 % $\bullet$ & $\bullet$ & $\bullet$ & $\bullet$ & & & & $\bullet$ & $\bullet$ \\
1129 % \href{https://docs.moodle.org/35/en/Numerical_question_type}{Numerical}
1130 % & $\bullet$ & $\bullet$ & $\bullet$ & $\bullet$ & & & &
1131 % & & $\bullet$ & & $\bullet$ & $\bullet$ & $\bullet$ \\
1132 % \href{https://docs.moodle.org/35/en/Short-Answer_question_type}{Short
1133 % Answer} & $\bullet$ & $\bullet$ & $\bullet$ & $\bullet$ & & & &
1134 % & $\bullet$ & & & $\bullet$ & $\bullet$ \\
1135 % \href{https://docs.moodle.org/35/en/Matching_question_type}{Matching}
1136 % & $\bullet$ & $\bullet$ & $\bullet$ & $\bullet$ & $\bullet$ & & &
1137 % & & & $\bullet$ & & \\
1138 % \href{https://docs.moodle.org/35/en/True/False_question_type}
1139 % {True/False} & $\bullet$ & & $\bullet$ & $\bullet$ & & & &
1140 % & & & & & $\bullet$ \\
1141 % \href{https://docs.moodle.org/35/en/Description_question_type}
1142 % {Description} & & & $\bullet$ & $\bullet$ & & & &
1143 % & & & & & \\
1144 % ^^A\href{https://docs.moodle.org/35/en/Essay_question_type}{Essay} & \\\hline%
1145 % \href{https://docs.moodle.org/35/en/Embedded_Answers_(Cloze)_question_type}{Cloze}
1146 % & & $\bullet$ & $\bullet$ & $\bullet$ & & & &
1147 % & & & & & \\\cmidrule(lr){1-1}
1148 % \hspace{1em}Numerical & $\bullet$ & & & & & & &
1149 % & &$\bullet$ & & $\bullet$ & $\bullet$ & $\bullet$ \\
1150 % \hspace{1em}Short Answer & $\bullet$ & & & & & & &
1151 % & $\bullet$ & & & $\bullet$ & $\bullet$ \\
1152 % \hspace{1em}Multi (inline) & $\bullet$ & & & & $\bullet$ & & &
1153 % & & & & $\bullet$ & $\bullet$ \\
1154 % \hspace{1em}Multi (horiz.) & $\bullet$ & & & & $\bullet$ & & $\bullet$
1155 % & & & & & $\bullet$ & $\bullet$ \\
1156 % \hspace{1em}Multi (vert.) & $\bullet$ & & & & $\bullet$ & & $\bullet$
1157 % & & & & & $\bullet$ & $\bullet$ \\
1158 % \bottomrule
1159 % \end{tabular}
1160 % \end{table}
1161 %
1162 % \subsection{Automated Generation of Questions}
1163 %
1164 % \Moodle's \href{https://docs.moodle.org/en/Calculated_question_type}
1165 % {Calculated Questions} types are not supported by this package.
1166 %
1167 % However, much more flexibly, a scripting language can be used in
1168 % combination with \pkg{moodle} to generate a large set of questions,
1169 % based on a prototype.
1170 %
1171 % In this case, the teacher building a quiz often wants one of the questions
1172 % to be randomly picked up and presented to the student. To achieve this,
1173 % we suggest to apply a specific tag to the questions sharing the same prototype.
1174 % After import in \Moodle, when creating a quiz, this tag can be selected to
1175 % narrow down a random selection of questions.
1176 %
1177 % This way, the feature of calculated questions can be reproduced, while
1178 % benefiting from the flexibility given by your favorite scripting language.
1179 %
1180 % In this Section, two possible approaches are presented.
1181 %
1182 % \subsubsection{Script Generating \TeX\ Code}
1183 %
1184 % Here are two examples inspired from the work of
1185 % \href{https://github.com/avohns/python-latex-moodle-quiz}{A. Vohns}.
1186 % The first one relies on the
1187 % native \prog{Lua} capabilities of \LuaLaTeX.
1188 % \begin{VerbatimOut}[gobble=1]{minted.doc.out}
1189 % \begin{quiz}[tags={calculated}]{Example Quiz}
1190 % \directlua{
1191 % \end{VerbatimOut}
1192 % \inputminted[gobble=2,frame=topline]{latex}{minted.doc.out}
1193 % \vspace{-.7cm}
1194 % \begin{VerbatimOut}[gobble=1]{minted.doc.out}
1195 % function clozenum_print(pair,op,result)
1196 % tex.print("\\begin{numerical}$"..pair[1].." "..op.." "..pair[2].."
1197 % =$".."\\item ",result,"\\end{numerical}")
1198 % end
1199 % function cloze_print(pair,points)
1200 % tex.print("\\begin{cloze}[points="..points.."]{Arithmetic Quiz
1201 % ("..pair[1]..", "..pair[2]..")}Solve the following tasks!\\\\")
1202 % clozenum_print(pair,"+",pair[1]+pair[2])
1203 % clozenum_print(pair,"-",pair[1]-pair[2])
1204 % clozenum_print(pair,"*",pair[1]*pair[2])
1205 % if pair[1]/pair[2]==math.floor(pair[1]/pair[2]) then
1206 % clozenum_print(pair,":",math.floor(pair[1]/pair[2]))
1207 % end
1208 % tex.print("\\end{cloze}")
1209 % end
1210 % for x = 2,4 do
1211 % for y = 2,4 do
1212 % if x>y then
1213 % if x/y==math.floor(x/y) then points=1 else points=2 end
1214 % cloze_print({x,y},points)
1215 % end
1216 % end
1217 % end
1218 % \end{VerbatimOut}
1219 % \inputminted[]{lua}{minted.doc.out}
1220 % \vspace{-.7cm}
1221 % \begin{VerbatimOut}[gobble=1]{minted.doc.out}
1222 % }
1223 % \end{quiz}
1224 % \end{VerbatimOut}
1225 % \inputminted[gobble=2,frame=bottomline]{latex}{minted.doc.out}
1226 % The second example makes use of the \pkg{python} package (|\usepackage{python}|).
1227 % \begin{VerbatimOut}[gobble=1]{minted.doc.out}
1228 % \begin{quiz}[tags={calculated}]{Example Quiz}
1229 % \begin{python}
1230 % \end{VerbatimOut}
1231 % \inputminted[gobble=2,frame=topline]{latex}{minted.doc.out}
1232 % \vspace{-.7cm}
1233 % \begin{VerbatimOut}[gobble=1]{minted.doc.out}
1234 % def clozenum_print(pair,op,result):
1235 % print(rf"""\begin{{numerical}}
1236 % ${pair[0]} {op} {pair[1]} =$\item {result}
1237 % \end{{numerical}}""")
1238 % def cloze_print(pair,points):
1239 % print(rf"""\begin{{cloze}}[points={points}]{{Arithmetic Quiz
1240 % {(pair[0],pair[1])}}}Solve the following tasks!\\""")
1241 % clozenum_print([x,y],"+",x+y)
1242 % clozenum_print([x,y],"-",x-y)
1243 % clozenum_print([x,y],"*",x*y)
1244 % if pair[0]/pair[1] == pair[0]//pair[1]:
1245 % clozenum_print([x,y],":",x//y)
1246 % print("\end{cloze}")
1247 % for x in range(2,5):
1248 % for y in range(2,5):
1249 % if x > y:
1250 % if x/y == x//y:
1251 % points=1
1252 % else:
1253 % points=2
1254 % cloze_print([x,y],points)
1255 % \end{VerbatimOut}
1256 % \inputminted[]{python}{minted.doc.out}
1257 % \vspace{-.7cm}
1258 % \begin{VerbatimOut}[gobble=1]{minted.doc.out}
1259 % \end{python}
1260 % \end{quiz}
1261 % \end{VerbatimOut}
1262 % \inputminted[gobble=2,frame=bottomline]{latex}{minted.doc.out}
1263 % These two example codes yield the same \XML\ content.
1264 %
1265 % \subsubsection{\TeX\ Code As a Template}
1266 %
1267 % Instead of mixing \TeX\ and scripting code into the same file, it is probably
1268 % a better practice to write a |.tex| template file with predefined variables and
1269 % manipulate the latter using an external script.
1270 %
1271 % The \pkg{moodle} package facilitates the development of question templates.
1272 % Specific control sequences (e.g.~\TeX\ commands) can be used in place of answers
1273 % or other parameters to the questions. In \optn{draft} mode, this should be
1274 % possible even where \pkg{moodle} expects numerical values (e.g.~answers of
1275 % numerical questions).
1276 % After drafting and question development, the control sequences can then be
1277 % substituted, by means of a scripting language, with instances of the variables
1278 % pulled from a database (e.g. |*.csv| file).
1279 % This way, complex quizzes, with parameterized TikZ pictures for instance, can be produced.
1280 %
1281 % This approach, briefly presented in the rest of this section, is demonstrated by
1282 % C. Caprani in \href{https://github.com/ccaprani/genquiz}{genquiz},
1283 % with Python for scripting and Jinja as a templating engine.
1284 %
1285 % The specific control sequence of the template is the \TeX\ command |\VAR|, taking
1286 % the variable name to be substituted from the database as an argument. In order to
1287 % highlight the fields for template development, in \optn{draft} mode, this command is
1288 % defined to typeset the variable name in bold red font. When generating the \XML\
1289 % question bank, in \optn{final} mode, the variable values are substituted for the
1290 % specific control sequence. Variables can be used to define numerical answers,
1291 % tolerances, and even parameterize TikZ pictures.
1292 %
1293 % \begin{VerbatimOut}[gobble=1]{minted.doc.out}
1294 % \documentclass{article}
1295 % \usepackage[draft]{moodle}
1296 % \usepackage{tikz}
1297 % \newcommand*{\VAR}[1]{\textcolor{red}{\textbf{#1}}}
1298 % \begin{document}
1299 % \begin{quiz}{Disk or Square}
1300 % \begin{cloze}[tags={disk area}]
1301 % {Area of the Disk QID00\VAR{qidx}}
1302 % \begin{tikzpicture}
1303 % \draw[fill=black!20] circle[radius=1];
1304 % \draw[<->] (0,0)--(1,0)node[above,midway]{\VAR{radius}};
1305 % \end{tikzpicture}
1306 % A disk has radius \VAR{radius}, what is its area?
1307 % \begin{numerical}[points=1,penalty=0]
1308 % \item[tolerance = \VAR{areatol}] \VAR{area}
1309 % \item[fraction=0,feedback={Note the units.}] * % incorrect
1310 % \end{numerical}
1311 % Provide your answers to 3 significant digits.
1312 % \end{cloze}
1313 % \end{quiz}
1314 % \end{document}
1315 % \end{VerbatimOut}
1316 % \inputminted[gobble=1,frame=lines]{latex}{minted.doc.out}
1317 %
1318 % A small python code that reads the template and renders the actual |*.tex| file
1319 % is shown below. In this example, the template file is called |quiz_template.tex| and
1320 % the variables are hard-coded as a list of Python dictionaries. But nothing prevents
1321 % you from generating them on-the-fly or picking them from a database.
1322 % It is worth noting that \prog{jinja2} will process all |\VAR{|\meta{name}|}| occurrences,
1323 % regardless of \TeX\ comments.
1324 %
1325 % \begin{VerbatimOut}[gobble=1]{minted.doc.out}
1326 % import os
1327 % import jinja2
1328 %
1329 % # Tell jinja what to look for in the template
1330 % # (from web.archive.org/web/20121024021221/http://e6h.de/post/11/)
1331 % latex_jinja_env = jinja2.Environment(
1332 % variable_start_string=r"\VAR{",
1333 % variable_end_string=r"}",
1334 % comment_start_string=r"\#{",
1335 % comment_end_string="}",
1336 % loader=jinja2.FileSystemLoader(os.path.abspath(".")),
1337 % )
1338 %
1339 % # Load the template
1340 % template = latex_jinja_env.get_template("quiz_template.tex")
1341 %
1342 % # Prepare the variables or read from a database
1343 % database = [
1344 % {"qidx": 1, "radius": 2, "areatol": 0.1, "area": 12.57},
1345 % {"qidx": 2, "radius": 3, "areatol": 0.2, "area": 28.27},
1346 % {"qidx": 3, "radius": 4, "areatol": 0.4, "area": 50.26},
1347 % ]
1348 %
1349 % for row in database:
1350 % # combine template and variables
1351 % document = template.render(**row)
1352 %
1353 % # XML files are generated by moodle.sty in "final" mode
1354 % document = document.replace(r"\usepackage[draft]{moodle}",
1355 % r"\usepackage{moodle}")
1356 %
1357 % # write document
1358 % with open(f"{row['qidx']}.tex","w",encoding="utf-8") as outfile:
1359 % outfile.write(document)
1360 % \end{VerbatimOut}
1361 % \inputminted[gobble=1,frame=lines]{python}{minted.doc.out}
1362 %
1363 % Executing this Python code will result in three new |.tex| files in the current directory.
1364 % These can then be compiled with a \TeX\ engine to produce the individual \XML\ files.
1365 % Of course, for a large number of quizzes it is preferable to automate this compilation,
1366 % and to combine the large number of resulting \XML\ files into a single \XML\ file for upload
1367 % to Moodle. See \href{https://github.com/ccaprani/genquiz}{genquiz} for more details.
1368 %
1369 % Naturally, the concept of templating, demonstrated here with Python, may be orchestrated
1370 % using other scripting languages.
1371 %
1372 % \section{Conversion to HTML}
1373 %
1374 % \subsection{Level of Support}
1375 %
1376 % The package \pkg{moodle.sty} tries to automatically
1377 % convert the \LaTeX\ code included in the questions
1378 % into \HTML\ for web display.
1379 %
1380 % With this aim, a number of \TeX\ and \LaTeX\ macros,
1381 % commands, and environments undergo a tailored treatment
1382 % when \pkg{moodle} generates the \XML\ file. A few tables
1383 % describe the current level of support:
1384 % \begin{enumerate}
1385 % \item text mode diacritic macros (e.g.~|\"u|) in Table~\vref{tab:diacritics},
1386 % \item text mode macros for ligatures (e.g.~\cmd{\oe}) and other glyphs (e.g.~\cmd{\aa}) in
1387 % Table~\vref{tab:ligatures_and_glyphs},
1388 % \item horizontal spacing (e.g.~\cmd{\quad}) and line breaking (e.g.~\cmd{\\}) macros in
1389 % Table~\vref{tab:spacing},
1390 % \item text mode symbols (e.g.~\cmd{\$}) and punctuation (e.g.~\cmd{\textexclamdown}) macros in
1391 % Table~\vref{tab:symbols_and_punctuation}, and finally
1392 % \item other \LaTeX\ commands (e.g.~\cmd{\emph}) and environments (e.g.~\env{center})
1393 % in Table~\vref{tab:commands_and_environments}.
1394 % \end{enumerate}
1395 %^^A \pagebreak
1396 %
1397 %^^A Inspired by https://tex.stackexchange.com/a/163717/228515
1398 % \begin{table}[tbp]
1399 % \centering
1400 % \caption{Text mode diacritic macros undergoing a tailored conversion to \HTML.}
1401 % \label{tab:diacritics}
1402 % \begin{threeparttable}
1403 % \begin{tabular}{clll}
1404 % \toprule
1405 % Definition & Letter List\tnote{1} & Description & Samples\\
1406 % \cmidrule(lr){1-1}\cmidrule(lr){2-2}\cmidrule(lr){3-3}\cmidrule(lr){4-4}
1407 % \cmd{\"}\marg{letter} & a, e, i, o, u, y &
1408 % \href{https://en.wikipedia.org/wiki/Diaeresis_(diacritic)}{umlaut or diaeresis}
1409 % & \"{a} \"{A} \"{e} \"{E} \"{i} \"{I} \"{o} \"{O} \dots\ \"{Y}\\
1410 % \cmd{\'}\marg{letter} & a, e, i, o, u &
1411 % \href{https://en.wikipedia.org/wiki/Acute\_accent}{acute accent}
1412 % & \'{a} \'{A} \'{e} \'{E} \'{i} \'{I} \'{o} \'{O} \'{u} \'{U}\\
1413 % \cmd{\.}\marg{letter} & c, e, g, i, z &
1414 % \href{https://en.wikipedia.org/wiki/Dot_(diacritic)#Overdot}{overdot}
1415 % & \.{c} \.{C} \.{e} \.{E} \.{g} \.{G} \.{i} \.{I} \.{z} \.{Z}\\
1416 % \cmd{\=}\marg{letter} & a, e, g, i, o, u, y &
1417 % \href{https://en.wikipedia.org/wiki/Macron_(diacritic)}{macron}
1418 % & \={a} \={A} \={e} \={E} \={g} \={G} \={i} \={I} \dots\ \={Y}\\
1419 % \cmd{\^}\marg{letter} & a, e, i, o, u &
1420 % \href{https://en.wikipedia.org/wiki/Circumflex}{circumflex} &
1421 % \^{a} \^{A} \^{e} \^{E} \^{i} \^{I} \^{o} \^{O} \^{u} \^{U}\\
1422 % \cmd{\`}\marg{letter} & a, e, i, o, u &
1423 % \href{https://en.wikipedia.org/wiki/Grave\_accent}{grave accent}
1424 % & \`{a} \`{A} \`{e} \`{E} \`{i} \`{I} \`{o} \`{O} \`{u} \`{U}\\
1425 % \cmd{\~}\marg{letter} & a, n, o &
1426 % \href{https://en.wikipedia.org/wiki/Tilde}{tilde}
1427 % & \~{a} \~{A} \~{n} \~{N} \~{o} \~{O}\\
1428 % \cmd{\b}\marg{letter} & b, d, k, l, n, t, z &
1429 % \href{https://en.wikipedia.org/wiki/Macron_below}{macron below}
1430 % & \b{b} \b{B} \b{d} \b{D} \b{k} \b{K} \b{l} \dots\ \b{Z}\\
1431 % \cmd{\c}\marg{letter} & c, s, t &
1432 % \href{https://en.wikipedia.org/wiki/Cedilla}{cedilla}
1433 % & \c{c} \c{C} \c{s} \c{S} \c{t} \c{T}\\
1434 % \cmd{\d}\marg{letter} & a, b &
1435 % \href{https://en.wikipedia.org/wiki/Dot_(diacritic)#Underdot}{underdot}
1436 % & \d{a} \d{A} \d{b} \d{B}\\
1437 % \cmd{\H}\marg{letter} & o, u &
1438 % \href{https://en.wikipedia.org/wiki/Double\_acute\_accent}{double acute accent}
1439 % & \H{o} \H{O} \H{u} \H{U}\\
1440 % \cmd{\k}\marg{letter} & a, e, i, o, u &
1441 % \href{https://en.wikipedia.org/wiki/Ogonek}{ogonek}
1442 % & \k{a} \k{A} \k{e} \k{E} \k{i} \k{I} \k{o} \k{O} \k{u} \k{U}\\
1443 % \cmd{\r}\marg{letter} & a, u &
1444 % \href{https://en.wikipedia.org/wiki/Ring_(diacritic)#Overring}{overring}
1445 % & \r{a} \r{A} \r{u} \r{U} \\
1446 %^^A \cmd{\t}\marg{letter} & a, b, c & tie-after accent & \t{oo}\\
1447 % \cmd{\u}\marg{letter} & a, e, g, i\tnote{2}, \i, o, u &
1448 % \href{https://en.wikipedia.org/wiki/Breve}{breve}
1449 % & \u{a} \u{A} \u{e} \u{E} \u{i} \u{\i} \u{I} \u{o} \u{O} \u{u} \u{U}\\
1450 % \cmd{\v}\marg{letter} & c, d, e, l, n, r, s, t, z &
1451 % \href{https://en.wikipedia.org/wiki/Caron}{caron or h\'a\v{c}ek}
1452 % & \v{c} \v{C} \v{d} \v{D} \v{e} \v{E} \v{l} \dots\ \v{Z}\\
1453 % \bottomrule
1454 % \end{tabular}
1455 % \begin{tablenotes}
1456 % \item[1] The lowercase letters listed also stand for their uppercase
1457 % equivalent.
1458 % \item[2] pdf\TeX\ v3.14159265 typesets |\u{i}| with an objectionable tittle.
1459 % Use |\u{\i}|.
1460 % \end{tablenotes}
1461 % \end{threeparttable}
1462 % \end{table}
1463 %
1464 % \begin{table}[tbp]
1465 % \centering
1466 % \caption{Text mode ligature and glyph macros undergoing a tailored conversion
1467 % to \HTML.}
1468 % \label{tab:ligatures_and_glyphs}
1469 % \begin{threeparttable}
1470 % \begin{tabular}{cccc}
1471 % \toprule
1472 % \multicolumn{2}{c}{Lowercase} & \multicolumn{2}{c}{Uppercase} \\
1473 % \cmidrule(lr){1-2}\cmidrule(lr){3-4}
1474 % Definition & Sample & Definition & Sample \\
1475 % \cmidrule(lr){1-1}\cmidrule(lr){2-2}\cmidrule(lr){3-3}\cmidrule(lr){4-4}
1476 % \cmd{\aa} & \aa & \cmd{\AA} & \AA \\
1477 % \cmd{\ae} & \ae & \cmd{\AE} & \AE \\
1478 % \cmd{\dh} & \dh & \cmd{\DH} & \DH \\
1479 % \cmd{\dj} & \dj & \cmd{\DJ} & \DJ \\
1480 % \cmd{\i} & \i & & \\
1481 % \cmd{\ij} & \ij & \cmd{\IJ} & \IJ \\
1482 % \cmd{\j} & \j & & \\
1483 % \cmd{\l} & \l & \cmd{\L} & \L \\
1484 % \cmd{\ng} & \ng & \cmd{\NG} & \NG \\
1485 % \cmd{\o} & \o & \cmd{\O} & \O \\
1486 % \cmd{\oe} & \oe & \cmd{\OE} & \OE \\
1487 % \cmd{\ss} & \ss & \cmd{\SS}\tnote{1} & \SS\tnote{2} \\
1488 % \cmd{\th} & \th & \cmd{\TH} & \TH \\
1489 % \bottomrule
1490 % \end{tabular}
1491 % \begin{tablenotes}
1492 % \item[1] Contrarily to most fonts, Libertine, used in this documentation and
1493 % available for instance via the package \pkg{libertine}, defines the glyph
1494 % \SS.
1495 % \item[2] \LaTeX\ defines the \cmd{\SS} macro but pdf\TeX\ renders it as a
1496 % doubled capital S.
1497 % \end{tablenotes}
1498 % \end{threeparttable}
1499 % \end{table}
1500 %
1501 % \begin{table}[tbp]
1502 % \centering
1503 % \caption{Text mode horizontal spacing and line breaking macros undergoing a
1504 % tailored conversion to \HTML.}
1505 % \label{tab:spacing}
1506 %^^A Inspired by https://tex.stackexchange.com/a/74354/228515
1507 % \begin{threeparttable}
1508 % \begin{tabular}{ll}
1509 % \toprule
1510 % Definition & Description \\
1511 % \cmidrule(lr){1-1}\cmidrule(lr){2-2}
1512 % \cmd{\,} or \cmd{\thinspace} & narrow non-breaking space \\
1513 % |~| or \texttt{\textbackslash\textvisiblespace} & non-breaking space \\
1514 % \cmd{\>}\tnote{1},{ } \cmd{\:}{}\tnote{2}{ } or \cmd{\medspace}\tnote{2} & mid space \\
1515 % \cmd{\;}\tnote{2}{ } or \cmd{\thickspace}\tnote{2} & thick space \\
1516 % \cmd{\enspace} & nut (1en wide space)\\
1517 % \cmd{\quad} & mutton (1em wide space)\\
1518 % \cmd{\qquad} & doubled mutton (2em wide space)\\
1519 % \cmd{\textvisiblespace} & sample: \textvisiblespace \\
1520 % \cmd{\\} or \cmd{\newline} & start a new line \\
1521 % |\par| or \meta{blank line} & start a new paragraph \\
1522 % \bottomrule
1523 % \end{tabular}
1524 % \begin{tablenotes}
1525 % \item[1] \cmd{\>} is defined in math-mode only.
1526 % \item[2] \cmd{\:}, \cmd{\medspace}, \cmd{\;}, and \cmd{\thickspace} require the package
1527 % \pkg{amsmath}.
1528 % \end{tablenotes}
1529 % \end{threeparttable}
1530 % \end{table}
1531 %
1532 % \begin{table}[tbp]
1533 % \centering
1534 % \caption{Text mode punctuation marks and symbol macros undergoing a tailored
1535 % conversion to \HTML. A baseline is represented in the samples of quotations
1536 % marks, in order to draw attention to their vertical positioning.}
1537 % \label{tab:symbols_and_punctuation}
1538 % \newsavebox\textbox
1539 % \newcommand\showbaseline[1]{\leavevmode\sbox\textbox{#1}
1540 % \rlap{\rule{\wd\textbox}{.1pt}}\usebox\textbox}
1541 % \begin{threeparttable}
1542 % \begin{tabular}{llc}
1543 % \toprule
1544 % Package & Definition & Sample \\
1545 % \cmidrule(lr){1-1}\cmidrule(lr){2-2}\cmidrule(lr){3-3}
1546 % \LaTeX\ base & \cmd{\%} & \% \\
1547 % & \cmd{\#} & \# \\
1548 % & \cmd{\_} & \_ \\
1549 % & \cmd{\textbackslash} & \textbackslash \\
1550 % & \cmd{\$} & \$ \\
1551 % & \cmd{\&} & \& \\
1552 % & \cmd{\S} & \S \\
1553 % & |\{| & \{ \\
1554 % & |\}| & \} \\
1555 % & \cmd{\texteuro} & \texteuro \\
1556 % & \cmd{\dots} or \cmd{\ldots} & \dots \\
1557 % & \cmd{\textexclamdown} & \textexclamdown \\
1558 % & \cmd{\textquestiondown} & \textquestiondown \\
1559 % & |--| & -- \\
1560 % & |=| & = \\
1561 % & |`| and |'|\tnote{1} & \showbaseline{` '} \\
1562 % & \cmd{\textquoteleft} and \cmd{\textquoteright}
1563 % & \showbaseline{\textquoteleft\ \textquoteright} \\
1564 % & |``| and |''|\tnote{1,2} & \showbaseline{`` ''} \\
1565 % & \cmd{\textquotedblleft} and \cmd{\textquotedblright}
1566 % & \showbaseline{\textquotedblleft\ \textquotedblright} \\
1567 % & \cmd{\textquotesingle} & \showbaseline{\textquotesingle\ } \\
1568 % & |"| & \showbaseline{" }\tnote{2} \\
1569 % & \cmd{\textquotedbl} & \showbaseline{\textquotedbl\ }\\
1570 % & \cmd{\guilsinglleft} and \cmd{\guilsinglright}
1571 % & \showbaseline{\guilsinglleft\ \guilsinglright} \\
1572 % & \cmd{\guillemotleft} and \cmd{\guillemotright}
1573 % & \showbaseline{\guillemotleft\ \guillemotright}\\
1574 % & \cmd{\quotesinglbase} & \showbaseline{\quotesinglbase\ }\\
1575 % & \cmd{\quotedblbase} & \showbaseline{\quotedblbase\ } \\
1576 % \cmidrule(lr){1-1}
1577 % \pkg{eurosym} & \cmd{\euro} & \euro\\
1578 % \cmidrule(lr){1-1}
1579 % \pkg{babel} & \cmd{\flq} and \cmd{\frq} & \showbaseline{\flq\ \frq} \\
1580 % & \cmd{\flqq} and \cmd{\frqq} & \showbaseline{\flqq\ \frqq} \\
1581 % \cmidrule(lr){1-1}
1582 % \pkg{babel}, opt. \optn{french} & \cmd{\og} and \cmd{\fg}\tnote{3}
1583 % & \showbaseline{\flqq\ \frqq} \\
1584 % \cmidrule(lr){1-1}
1585 % \pkg{babel}, opt. \optn{german} & \cmd{\glq} and \cmd{\grq}
1586 % & \showbaseline{\glq\ \grq} \\
1587 % & \cmd{\dq} & \showbaseline{\dq\ }\tnote{2} \\
1588 % & \cmd{\glqq} and \cmd{\grqq} & \showbaseline{\glqq\ \grqq} \\
1589 % \bottomrule
1590 % \end{tabular}
1591 % \begin{tablenotes}
1592 % \item[1] When placed in math mode, the single straight quote (\texttt{'}) is
1593 % passed as-is to the \XML, even when doubled (double prime symbol).
1594 % \item[2] In roman type, \LuaLaTeX\ and \XeLaTeX\ typeset the double straight
1595 % quote symbol (\texttt{"}) and the command \cmd{\dq} as a double right quote
1596 % (\textquotedblright). Instead, \pkg{moodle} follows pdf\LaTeX: whatever
1597 % the \TeX\ engine used, the double straight quote (\texttt{"}) is passed to the \XML.
1598 % \item[3] The way \cmd{\og} and \cmd{\fg} are typeset in the \PDF\ depends on the
1599 % current babel language. Regardless, \pkg{moodle} passes the symbols
1600 % \texttt{\guillemotleft} and \texttt{\guillemotright} to the \XML.
1601 % \end{tablenotes}
1602 % \end{threeparttable}
1603 % \end{table}
1604 %
1605 % \begin{table}[tbp]
1606 % \centering
1607 % \caption{\LaTeX\ commands and environments undergoing a tailored conversion
1608 % to \HTML.}
1609 % \label{tab:commands_and_environments}
1610 % \begin{tabular}{lll}
1611 % \toprule
1612 % Package & Commands & Environments \\
1613 % \cmidrule(lr){1-1}\cmidrule(lr){2-2}\cmidrule(lr){3-3}
1614 % \LaTeX\ base & |{}|& |$|$\cdots$|$| (inline math) \\
1615 % & \cmd{\relax} & |\(|$\cdots$|\)| (inline math) \\
1616 % & \cmd{\LaTeX} & |$$|$\cdots$|$$| (display math) \\
1617 % & \cmd{\TeX} & \cmd{\[}$\cdots$\cmd{\]} (display math) \\
1618 % & \cmd{\emph}\marg{\dots} & \env{center} \\
1619 % & \cmd{\textbf}\marg{\dots} & \env{enumerate} \\
1620 % & \cmd{\textit}\marg{\dots} & \env{itemize} \\
1621 % & \cmd{\textsc}\marg{\dots} & \env{quote} \\
1622 % & \cmd{\textsuperscript}\marg{\dots} & \env{quotation}\\
1623 % & \cmd{\textsubscript}\marg{\dots} &\\
1624 % & \cmd{\texttt}\marg{\dots} &\\
1625 % & \cmd{\underline}\marg{\dots} &\\
1626 % \cmidrule(lr){1-1}
1627 % \pkg{hyperref} & \cmd{\href}\marg{\dots}\marg{\dots} &\\
1628 % \pkg{url} or \pkg{hyperref} & \cmd{\url}\marg{\dots} &\\
1629 % \cmidrule(lr){1-1}
1630 % \pkg{babel}, opt. \optn{french} & \cmd{\fup}\marg{\dots} &\\
1631 % & \cmd{\up}\marg{\dots} &\\
1632 % \cmidrule(lr){1-1}
1633 % \pkg{graphics} or \pkg{graphicx} &
1634 % \cmd{\includegraphics}\oarg{\dots}\marg{\dots} \\
1635 % \cmidrule(lr){1-1}
1636 % \pkg{tikz} & \cmd{\tikz}\oarg{\dots}\marg{\dots} & \env{tikzpicture}\oarg{\dots} \\
1637 % \cmidrule(lr){1-1}
1638 % \pkg{verbatim} & \cmd{\verbatiminput}\marg{\dots} &\\
1639 % \cmidrule(lr){1-1}
1640 % \pkg{fancyverb} or
1641 % \pkg{fvextra}& \cmd{\VerbatimInput}\oarg{\dots}\marg{\dots} &\\
1642 % & \cmd{\LVerbatimInput}\oarg{\dots}\marg{\dots} &\\
1643 % & \cmd{\BVerbatimInput}\oarg{\dots}\marg{\dots}& \\
1644 % \cmidrule(lr){1-1}
1645 % \pkg{minted} & \cmd{\inputminted}\oarg{\dots}\marg{\dots}\marg{\dots} &\\
1646 % \bottomrule
1647 % \end{tabular}
1648 % \end{table}
1649 %
1650 % In addition, |<| and |>| will be converted to their HTML equivalents |&lt;|
1651 % and |&gt;| in the \XML\ file. This prevents portions of the code to be
1652 % interpreted by \Moodle\ as \HTML\ tags.
1653 %
1654 % A doubled dash will be converted to en-dash |&ndash;| \emph{outside math mode}.
1655 % Empty groups |{}| will be passed to the XML only \emph{in math mode}.
1656 %
1657 % Be aware that, apart what is described previously, \pkg{moodle} \emph{does
1658 % not know how to convert any other \TeX\ or \LaTeX\ commands to \HTML.}
1659 % If other sequences are used, they may be passed verbatim to the \XML\ file
1660 % or may cause unpredicted results.
1661 %
1662 % If you think of another \LaTeX\ command that should be changed to an HTML
1663 % equivalent, please have a look at Section~\vref{sec:dev}.
1664 %
1665 % \DescribeMacro[question,answer,feedback]{\htmlonly}\oarg{Content for traditional output}
1666 % \marg{HTML content} is a command to be used inside question environments (text,
1667 % answers, or feedback). It lets you pass directly code to the \XML\ file while being
1668 % ignored for the traditional output (\PDF). The \HTML\ content passed as an argument
1669 % is subject to no particular processing and users should not expect to be able to
1670 % pass dangerous characters like |\|, |%|, or |#|. An optional argument allows to
1671 % pass contents to be processed for the traditional output. This argument is
1672 % ignored for the \XML\ output.
1673 % For instance, one can write code like this in a question environment
1674 % \begin{quote}
1675 % |\htmlonly[\fbox{PDF contents}]{|\\
1676 % |<div style="border: 1px solid; display: inline-block;">|\\
1677 % \rule{10em}{0pt}|HTML contents</div>|\\
1678 % |}|
1679 % \end{quote}
1680 %
1681 % \DescribeMacro[moodle]{\htmlregister}\marg{command} is a command that lets you
1682 % specify a macro that must be expanded in the \XML\ file. It works only when
1683 % the macro is defined without optional argument.\watchout
1684 %
1685 % \DescribeMacro[moodle]{\moodleregisternewcommands}
1686 % When the list of user-defined macros is long, it becomes cumbersome to
1687 % record them individually for expansion. Calling \cmd{\moodleregisternewcommands}
1688 % watches for subsequent calls to \cmd{\newcommand}, \cmd{\renewcommand},
1689 % \cmd{\providecommand}, and their starred variants such that the corresponding
1690 % commands are automatically expanded by \pkg{moodle}.
1691 % Again, this works only if the macros are defined \emph{without} optional
1692 % argument.\watchout
1693 %
1694 % \subsection{Graphics}
1695 % The \pkg{moodle} package can handle two kinds of graphics seamlessly.
1696 % External graphics files may be included with the \cmd{\includegraphics} command
1697 % from the \pkg{graphicx} package, and graphics may be generated internally using \TikZ.
1698 % In either case, the graphics will be embedded in base-64 encoding directly within
1699 % the \Moodle\ \XML\ produced. This prevents the hassle of managing separate
1700 % graphics files on the \Moodle\ server, as \Moodle\ will store the picture
1701 % within the question in the question bank.
1702 %
1703 % \subsubsection{Default \texttt{includegraphics}}
1704 %
1705 % \DescribeMacro[graphics,graphicx]{\includegraphics}\oarg{options}\marg{file} can be used to
1706 % include graphic files in both \PDF\ and the \XML\ outputs.
1707 % The only options currently supported are \optn{height}\DescribeKey[includegraphics]{height}\
1708 % and \optn{width}\DescribeKey[includegraphics]{width}. Attempts to use other
1709 % \cmd{\includegraphics} options, such as \optn{scale} or \optn{angle}, will affect the \PDF\
1710 % but not the \XML\ output.
1711 % The dimensions set by \optn{height} and \optn{width} are \TeX\ dimensions such as
1712 % \texttt{4\,in} or \texttt{2.3\,cm}.
1713 % In order to prepare the image for web viewing, this package converts those
1714 % dimensions to pixels using a default of
1715 % 103 pixels per inch.\footnote{This
1716 % number was selected because an image with
1717 % |<IMG HEIGHT=103 WIDTH=103 SRC="...">| showed up as almost exactly 1 inch
1718 % tall and 1 inch wide on several of this author's devices and browsers
1719 % as of January 2016.}
1720 % \DescribeKey[includegraphics]{ppi}
1721 % That value may be changed by setting the \optn{ppi} key (e.g., \texttt{ppi=72});
1722 % this is probably best done for the entire document with a \cmd{\moodleset} command,
1723 % rather than image-by-image.
1724 %
1725 % \DescribeMacro[graphics,graphicx]{\graphicspath}|{{|\meta{path1}|},{|\meta{path2}|},...}| can be
1726 % used to specify the locations of the pictures to be included.
1727 %
1728 % A special rule was added for the inclusion of \GIF\ pictures (\filenm{.gif} extension).
1729 % These files are passed as-is to the \XML, preserving potential animations.
1730 % However, as pdf\TeX\ engines do not support the \GIF\ format, the picture is
1731 % passed to the \PDF\ output after a conversion to the \PNG\ format. When the \GIF\
1732 % file is animated, only its first frame is passed to the \PDF.
1733 %
1734 %^^A \DescribeMacro[moodle]{\DeclareGraphicsAlien} Users may declare other graphic
1735 %^^A formats with the command \cmd{\DeclareGraphicsAlien}\marg{alien extension}
1736 %^^A \marg{native extension}\marg{command line for conversion}.
1737 %
1738 % \subsubsection{\TikZ\ Pictures}
1739 % \TikZ\ is a user-friendly syntax layer for \acro{PGF}, the macro \LaTeX\ package for creating
1740 % graphics. More information on \TikZ\ can be found at \url{https://ctan.org/pkg/pgf}.
1741 %
1742 % When \TikZ\ is loaded and used to define pictures, \pkg{moodle} invokes
1743 % the \pkg{external} \TikZ\ library, so that each \env{tikzpicture} environment is compiled
1744 % to a freestanding \PDF\ file.
1745 %
1746 % \subsubsection{Package Option \optn{tikz}}\label{subsec:tikz}
1747 % \DescribeOption[moodle]{tikz}
1748 % The \pkg{moodle} package admits a \optn{tikz} option which has the following effects:
1749 % \begin{itemize}
1750 % \item the package \pkg{tikz} is loaded.
1751 % \item \DescribeMacro[tikz]{\includegraphics}\cmd{\includegraphics} embeds graphics in a \TikZ\ picture. Consequences are that
1752 % \begin{itemize}
1753 % \item the pictures encoded in the \XML\ file are resampled. This prevents encoding
1754 % images at a higher resolution than rendered by \Moodle.
1755 % \item the full set of \cmd{\includegraphics} options is accessible,
1756 % e.g.~\optn{scale=.5}, \optn{angle=90}, or |width=.2\textwidth|.
1757 % \end{itemize}
1758 % \item \DescribeMacro[tikz]{\embedaspict} a macro \cmd{\embedaspict}\marg{\LaTeX\ contents}
1759 % is provided for the conversion of inline \LaTeX\ material as images. This can serve
1760 % as a workaround to overcome limitations of this package---like the conversion of
1761 % \emph{tabular}s to HTML--- or limitations of \Moodle\ itself.
1762 % For the definition of this macro, the package \pkg{varwidth} is loaded.
1763 % \item optimizations of the \TikZ-external library are disabled: compilation might get
1764 % sensibly slower.
1765 % \end{itemize}
1766 %
1767
1768 % \subsubsection{External Tools}
1769 % The mechanisms used for handling graphics are somewhat fragile and rely upon
1770 % three free external programs.
1771 % \begin{enumerate}
1772 % \item \prog{GhostScript} (\url{www.ghostscript.com}) is used to convert the \PDF\ output
1773 % from \TikZ\ into a \PNG\ raster graphics file.
1774 % The default command line is presumed to be \prog{gswin64c.exe}
1775 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1776 % (if |\ifwindows| from the \pkg{ifplatform} package returns true)
1777 % or \prog{gs} (if |\ifwindows| returns false).
1778 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1779 % If your system requires a different command line to invoke \prog{Ghostscript},
1780 % \DescribeMacro[moodle]{\ghostscriptcommand}
1781 % you may change it by invoking:
1782 % \begin{quote}
1783 % |\ghostscriptcommand|\marg{executable filename}
1784 % \end{quote}
1785 % \item When external graphics files such as \PDF\ are included,
1786 % the \prog{ImageMagick} software (\url{www.imagemagick.org})
1787 % converts each file to \PNG\ format.
1788 % The command line for \prog{ImageMagick} is the nondescript word \progcode{convert},
1789 % \DescribeMacro[moodle]{\imagemagickcommand}
1790 % but may be changed by invoking \cmd{\imagemagickcommand}\marg{executable filename}.
1791 % \item \prog{OptiPNG} (\url{http://optipng.sourceforge.net/}) is used to optimize the \PNG\ images.
1792 % The command line is presumed to be \prog{optipng}, but can be changed with
1793 % \DescribeMacro[moodle]{\optipngcommand}\cmd{\optipngcommand}\marg{executable filename}.
1794 % \end{enumerate}
1795
1796 %
1797 % Please note the following vital points to make the graphics handling work:
1798 % \begin{itemize}
1799 % \item As of now, graphics are only supported when compiling directly to a \PDF\
1800 % with (\prog{pdf}$\mid$\prog{xe}$\mid$\prog{lua})\prog{latex}. Including \acro{PS} graphics or using \TikZ\ with the \DVI$\to$\acro{PS} workflow is not
1801 % yet supported.
1802 %^^A \item Filenames should not contains spaces or, under windows, special characters like |_| or |\|.
1803 % \item You must have \prog{Ghostscript} and \prog{ImageMagick} installed on your system
1804 % to fully use the graphics-handling capabilities of \pkg{moodle}.
1805 % \item If \prog{OptiPNG} is not installed, the corresponding system calls will fail with otherwise no
1806 % impact on the compilation process: \PNG\ files are passed unoptimized to the \XML\ output.
1807 % \item \LaTeX\ must be able to call system commands; that is, \cmd{\write18} must be enabled.
1808 % For Mik\TeX, this means adding \progcode{--enable-write18} to the command line of
1809 % (\prog{pdf}$\mid$\prog{xe}$\mid$\prog{lua})\prog{latex}; for \TeX\ Live, this means adding \progcode{--shell-escape=true}.
1810 % \item Due to security issues with old versions of \prog{Ghostcript}, some systems default to a
1811 % policy that prevents the conversion of \PDF\ and \acro{PS} to \PNG. Assuming that, as a user of
1812 % \pkg{moodle} which requires shell escape capabilities, you either use a sandboxed
1813 % environment or trust the files handled at the system-level, you may want to disable this
1814 % over-zealous security policy. For example,
1815 % \href{https://stackoverflow.com/a/52661288/14608059}{see this}.
1816 % \item Users of the \pkg{circuitikz} package (\url{https://www.ctan.org/pkg/circuitikz}) must
1817 % enclose their circuits' \TikZ\ code in the |tikzpicture| environment instead of
1818 % the historical \env{circuitikz} environment. That is required, as of \TikZ\ 2.1,
1819 % by the \pkg{external} library.
1820 % \end{itemize}
1821 %
1822 % \subsubsection{Package Option \optn{svg}}\label{subsec:svg}
1823 %
1824 % \paragraph{Important Notice}\watchout[experimental] \emph{The \optn{svg} option is
1825 % an experimental feature introduced in \pkg{moodle} v0.8. It has been tested only
1826 % under Linux and Windows, with TeX Live 2020, Inkscape v1.0.1 and Scour 0.38.2.}
1827 %
1828 % \DescribeOption[moodle]{svg} The \pkg{moodle} package admits an experimental
1829 % \optn{svg} option which has the following effects:
1830 % \begin{itemize}
1831 % \item \DescribeMacro[svg]{\includegraphics}\cmd{\includegraphics} can be used to import
1832 % \SVG\ graphic files directly (extension \filenm{.svg} or \filenm{.SVG}). In this case, the \SVG\ file
1833 % is passed as-is to the \XML\ output and is converted using \href{https://inkscape.org/}
1834 % {\prog{Inkscape}} (must be installed) for inclusion in the \PDF\ output.
1835 % \item the graphic files in \PDF\ format are converted to the \SVG\ format using
1836 % \href{https://inkscape.org/}{Inkscape} (must be installed), rather than being
1837 % rasterized. Before inclusion to the \XML\ output, the \SVG\ file is optimized using
1838 % the \href{https://github.com/scour-project/scour}{Scour} utility. This
1839 % optimization step is optional in the sense that, if the Scour call fails,
1840 % the un-optimized \SVG\ file will be passed to the \XML\ output.
1841 % Two processes benefit from this \PDF$\to$\SVG\ conversion:
1842 % \begin{itemize}
1843 % \item inclusion of \PDF\ graphics with \cmd{\includegraphics}, and
1844 % \item \TikZ\ pictures that are externalized.
1845 % \end{itemize}
1846 % \end{itemize}
1847 %
1848 %
1849 % The call of external \SVG\ manipulation utilities can be modified using the macros:
1850 % \begin{description}
1851 % \item \ItemDescribeMacro[svg]{\PDFtoSVGcommand}\ for conversion
1852 % from \PDF\ to \SVG,
1853 % \item \ItemDescribeMacro[svg]{\SVGtoPDFcommand}\ for conversion
1854 % from \SVG\ to \PDF, and
1855 % \item \ItemDescribeMacro[svg]{\optiSVGcommand}\ for the
1856 % optimization of \SVG\ files.
1857 % \end{description}
1858 %
1859 % \subsection{Verbatim Code}
1860 %
1861 % Because, for \HTML\ translation, \pkg{moodle} parses the body of questions, the use of
1862 % verbatim code results in compilation errors. This is why the use of |\verb|,
1863 % \env{verbatim} and other standard utilities is not supported.
1864 %
1865 % However, using the following three utilities, verbatim code can be imported from an external file:
1866 % \begin{enumerate}
1867 % \item \cmd{\verbatiminput}\marg{filename}\DescribeMacro[verbatim]{\verbatiminput}\
1868 % from the \pkg{verbatim} package inserts verbatim code in both the \PDF\ and the
1869 % \acro{XML} for \Moodle, without fancy additions.
1870 % \item The macro \cmd{\VerbatimInput}\marg{options}\marg{filename}
1871 % \DescribeMacro[fancyvrb,fvextra]{\VerbatimInput}\ from
1872 % \pkg{fancyvrb} or \pkg{fvextra} does more, with several options and settings
1873 % offered (see below).
1874 % The variants \DescribeMacro[fancyvrb,fvextra]{\BVerbatimInput}\cmd{\VBerbatimInput} and
1875 % \DescribeMacro[fancyvrb,fvextra]{\LVerbatimInput}\cmd{\LVerbatimInput} are also supported,
1876 % with no difference on the \XML\ output.
1877 % The variants with a star are unsupported and result in errors when used.
1878 % \item On top of that \cmd{\inputminted}\oarg{options}\marg{lang}\marg{filename}\
1879 % \DescribeMacro[minted]{\inputminted} from the \pkg{minted} package offers syntax
1880 % highlighting tailored to the specified language.
1881 % \end{enumerate}
1882 % The \pkg{moodle} package handles these three commands to pass the code in the output \XML.
1883 % With \cmd{\inputminted}, an external Python tool, \prog{pygmentize}, performs syntax analysis and
1884 % its \HTML\ formatter is used to populate the \XML. With the other commands, the contents of the
1885 % file is passed almost as-is to the XML: in order to survive \Moodle\ import and \HTML\ rendering,
1886 % characters |<|, |>|, |&|, |'|, and |"| are converted to \HTML\ equivalents.
1887 %
1888 % With \cmd{\VerbatimInput} and \cmd{\inputminted}, the options that are taken care of for XML
1889 % generation are listed in Table~\vref{tab:verbatim-options}.
1890 % Using \cmd{\fvset}\marg{key=value,\dots}, options can be set globally. Equivalently, with \pkg{minted},
1891 % \cmd{\setminted}\oarg{lang}\marg{key=value,\dots} is available.
1892 %
1893 % \begin{table}[tbp]
1894 % \centering
1895 % \begin{threeparttable}[b]
1896 % \caption{Options and corresponding values considered for \XML\ generation of verbatim material
1897 % with \cmd{\VerbatimInput} and \cmd{\inputminted}.}
1898 % \label{tab:verbatim-options}
1899 % \begin{tabular}{ll}
1900 % \toprule
1901 % Option keys & Possible values\\\cmidrule(lr){1-1}\cmidrule(lr){2-2}
1902 % ^^A\optn{commentchar} & \meta{character}\\
1903 % \optn{gobble} & \meta{integer}\\
1904 % \optn{autogobble}\tnote{1} & \texttt{true} or \texttt{false}\\
1905 % \optn{tabsize} & \meta{integer}\\
1906 % \optn{numbers} & \texttt{none}, \texttt{left}, \texttt{right}, or \texttt{both}\tnote{2}\\
1907 % \optn{firstnumber} & \texttt{auto}, \texttt{last}, or \meta{integer}\\
1908 % \optn{firstline} & \meta{integer}\\
1909 % \optn{lastline} & \meta{integer}\\
1910 % \optn{numberblanklines} & \texttt{true} or \texttt{false}\\
1911 % \optn{highlightlines}\tnote{2} & \marg{coma-separated list of integers or ranges}\\
1912 % \optn{style}\tnote{1} & \meta{string}\\
1913 % \bottomrule
1914 % \end{tabular}
1915 %\begin{tablenotes}
1916 %\item[1] \optn{autogobble}, \optn{numbers=both}, and \optn{style} are from \pkg{minted}.
1917 %\item[2] line highlighting is offered only with \pkg{fvextra} or \pkg{minted} loaded.
1918 %\end{tablenotes}
1919 %\end{threeparttable}
1920 %\end{table}
1921 %
1922 % In order to define the verbatim code from the \LaTeX\ document itself, it is still possible
1923 % to use, outside the scope of the \pkg{moodle} questions, the environments \env{filecontents*}
1924 % (from the \pkg{filecontents} package or \LaTeX\ kernel itself since 2019) or \env{VerbatimOut}
1925 % (from the \pkg{fancyvrb} and \pkg{fvextra} packages).
1926 %
1927 % Here is an example:
1928 % \begin{VerbatimOut}[gobble=2]{minted.doc.out}
1929 % \documentclass[12pt,a4paper]{article}
1930 % \usepackage[section]{moodle}
1931 % \usepackage{minted}
1932 % \begin{document}
1933 % \begin{quiz}[tags={minted}]{LaTeX Quiz}
1934 % \begin{filecontents*}{excerpt.tex}
1935 % % !TeX encoding = UTF-8
1936 % % !TeX spellcheck = en_US
1937 % % !TEX TS-program = lualatex
1938 % \documentclass{article}
1939 % \usepackage[nostamp]{moodle}
1940 % \ifPDFTeX % FOR LATEX and PDFLATEX
1941 % \usepackage[utf8]{inputenc} % necessary
1942 % \usepackage[T1]{fontenc} % necessary
1943 % \else % assuming XELATEX or LUALATEX
1944 % \usepackage{fontspec}
1945 % \fi
1946 % \end{filecontents*}
1947 % \begin{numerical}[tolerance=0]{Loading a Class}
1948 % Consider the following \LaTeX\ code excerpt.\\
1949 % \inputminted[numbers=left]{latex}{excerpt.tex}
1950 % On which line is the class loaded?
1951 % \item[feedback={
1952 % yes! \inputminted[highlightlines={4}]{latex}{excerpt.tex} }] 4
1953 % \item[feedback={Line 3 is just a comment.},fraction=0] 3
1954 % \item[feedback={Line 5 loads the package \texttt{moodle}},fraction=0] 5
1955 % \end{numerical}
1956 % \begin{multi}[single]{IDE}
1957 % Consider the following \LaTeX\ code excerpt.\\
1958 % \inputminted[numbers=left]{latex}{excerpt.tex}
1959 % Which \TeX\ engine will be used by the IDE for compilation.
1960 % \item[feedback={Have a closer look at line 3}] \texttt{tex}
1961 % \item[feedback={Have a closer look at line 3}] \texttt{latex}
1962 % \item[feedback={Have a closer look at line 3}] \texttt{pdflatex}
1963 % \item[feedback={Have a closer look at line 3}] \texttt{xelatex}
1964 % \item* \texttt{lualatex}
1965 % \end{multi}
1966 % \end{quiz}
1967 % \end{document}
1968 % \end{VerbatimOut}
1969 % \inputminted[gobble=2,frame=lines]{latex}{minted.doc.out}
1970 %
1971 % When code decorated with left-side line numbers is placed in question items, the output \PDF\ could
1972 % show a collision between numbers of the item and the first line. To avoid this, \cmd{\LVerbatimInput} or
1973 % \cmd{\BVerbatimInput} can be used. Instead, when \pkg{minted} is used, the ``left-right'' mode can be
1974 % enforced with the \LaTeX\ command:
1975 % \begin{quote}
1976 % |\RecustomVerbatimEnvironment{Verbatim}{LVerbatim}{}|
1977 % \end{quote}
1978 %
1979 % When using utilities from \pkg{fancyvrb}, \pkg{fvextra}, or \pkg{minted}, \pkg{moodle}
1980 % sets framing options for the display of code in the output \PDF:
1981 % \begin{quote}
1982 % |\fvset{frame=lines,label={[Beginning of code]End of code},|\\
1983 % | framesep=3mm,numbersep=9pt}|
1984 % \end{quote}
1985 % These settings can be overridden using \cmd{\fvset} after the preamble.
1986 %
1987 % \section{Internationalization}
1988 %
1989 % This section is intended for authors of \Moodle\ quizzes writing in one or several
1990 % languages other than English. It seems reasonable to assume that those users have heard
1991 % of the packages \pkg{babel} or \pkg{polyglossia} (\XeTeX\ or \LuaTeX\ only), that
1992 % both aim at enforcing language-related rules to \LaTeX\ documents.
1993 %
1994 % The contents of the \XML\ file that is generated by \pkg{moodle} depends entirely
1995 % on the user input and \Moodle's \XML\ syntax: there is little room for \pkg{moodle} to
1996 % internationalize something here. Instead, the focus of this section is the \PDF\
1997 % typesetting that is determined by \pkg{moodle}, where some internalization
1998 % efforts can be of help.
1999 %
2000 % Both \pkg{babel} and \pkg{polyglossia} provide ways of specifiying a language for
2001 % the document or a part of it. If one of these packages is loaded in the preamble,
2002 % \pkg{moodle} will automatically load the package \pkg{translator} and rely on it
2003 % to provide translations of its keys (see Table~\vref{tab:language_keys}) in
2004 % different languages, with some knowledge on aliases. The package
2005 % \pkg{translations} does a very similar job and can be loaded in the preamble
2006 % to serve, if desired, as a replacement for \pkg{translator}.
2007 %
2008 % Currently, full-support is provided for English, French, German, Italian, and
2009 % Spanish. Very limited support is provided for Catalan, Croatian, Czech, Danish, Dutch,
2010 % Estonian, Finnish, Hungarian, Icelandic, Lithuanian, Norsk, Polish, Portuguese,
2011 % Romanian, Swedish, and Turkish.
2012 %
2013 % Users may define their own translations in the preamble. For instance
2014 % \begin{quote}
2015 % |\AfterEndPreamble{|\\
2016 % | \DeclareTranslation|\marg{babel language name}|{True}{Foo}%|\\
2017 % | \DeclareTranslation|\marg{babel language name}|{False}{Bar}%|\\
2018 % |}|
2019 % \end{quote}
2020 % Note that, when the package \pkg{translations} is loaded,
2021 % \cmd{\AfterEndPreamble} must not be used.
2022 %
2023 % Contributions to improve or broaden the linguistic support are very welcome.
2024 %
2025 % \begin{center}
2026 % \begin{longtable}{ l p{.55\textwidth} }
2027 % \caption{\pkg{moodle}'s language keys for internationalization of the \PDF\ typesetting.}
2028 % \label{tab:language_keys}\\
2029 % \toprule
2030 % Key & Context\\
2031 % \cmidrule(lr){1-1}\cmidrule(lr){2-2}
2032 % \endfirsthead
2033 % \multicolumn{2}{c}%
2034 % {\tablename\ \thetable\ -- \textit{Continued from previous page}} \\
2035 % \hline
2036 % Key & Context\\
2037 % \cmidrule(lr){1-1}\cmidrule(lr){2-2}
2038 % \endhead
2039 % \hline\multicolumn{2}{r}{\textit{Continued on next page}} \\
2040 % \endfoot
2041 % \bottomrule
2042 % \endlastfoot
2043 % \optn{True} & indicates option ``True'' in a True/False question.\\
2044 % \optn{False} & indicates option ``False'' in a True/False question.\\
2045 % \optn{cloze} & tag indicating a ``cloze'' question.\\
2046 % \optn{description} & tag indicating a ``description'' question.\\
2047 % \optn{essay} & tag indicating an ``essay'' question.\\
2048 % \optn{matching} & tag indicating a ``matching'' question.\\
2049 % \optn{multi} & tag indicating a ``multichoice'' question.\\
2050 % \optn{numerical} & tag indicating a ``numerical'' question.\\
2051 % \optn{shortanswer} & tag indicating a ``shortanswer'' question.\\
2052 % \optn{truefalse} & tag indicating a ``true/false'' question.\\
2053 % \optn{Shuffle} & tag indicating that options offered will be shuffled in a
2054 % ``multichoice'' or ``matching'' question.\\
2055 % \optn{Single} & tag indicating that only one option can be selected in a
2056 % ``multichoice'' question.\\
2057 % \optn{Multiple} & tag indicating that several options can be selected in a
2058 % ``multichoice'' question.\\
2059 % \optn{marked out of} & tag indicating the weight of the question (maximum
2060 % number of points), followed by a number.\\
2061 % \optn{penalty} & tag indicating the penalty factor applied for each wrong
2062 % attempt in adaptive mode.\\
2063 % \optn{tags} & indicates the beginning of a tag list characterizing the
2064 % question.\\
2065 % \optn{All-or-nothing} & tag indicating that all correct options must be
2066 % selected to get credited a good answer.\\
2067 % \optn{Case-Sensitive} & tag indicating that the case of characters matters
2068 % for a ``Shortanswer'' question.\\
2069 % \optn{Case-Insensitive} & tag indicating that the case of characters
2070 % does not matter for a ``Shortanswer'' question.\\
2071 % \optn{Drag and drop} & tag indicating that a ``matching'' question relies
2072 % on the Drag-and-drop plugin.\\
2073 % \optn{Information for graders} & indicates the beginning of a paragraph
2074 % where instructions for the graders of an ``essay'' question are given.\\
2075 % \optn{Response template} & indicates the beginning of a paragraph where
2076 % the answer template of an ``essay'' question is represented.\\
2077 % \optn{editor} & tag indicating that, for answering an essay question, an
2078 % editor with \HTML\ support will be proposed.\\
2079 % \optn{editorfilepicker} & tag indicating that, for answering an essay question,
2080 % an editor with \HTML\ support and a file picker will be proposed.\\
2081 % \optn{plain} & tag indicating that, for answering an essay question, an
2082 % editor with no markup support will be proposed.\\
2083 % \optn{monospaced} & tag indicating that, for answering an essay question,
2084 % an editor with fixed-width font and no markup support will be proposed.\\
2085 % \optn{noinline} & tag indicating that, for answering an essay question, a file
2086 % picker will be proposed.\\
2087 % \optn{Total of marks} & at the end of the quiz, indicates the sum of the
2088 % weights of all questions, followed by a colon and a number. \\
2089 % \end{longtable}
2090 % \end{center}
2091 %
2092 % \section{Package Development}\label{sec:dev}
2093 %
2094 % \subsection{Feature Requests, Bug Reports, and Contributions}
2095 %
2096 % This package is developed as a collaborative project, currently hosted
2097 % on the Gitlab server instance \url{https://framagit.org/mattgk/moodle}.
2098 % The project's activity can be monitored there: reported issues, last
2099 % modifications, \dots
2100 %
2101 % Contributions, either bug reports or fixes, are welcome. Users willing to
2102 % help can either sign-in with an existing \brand{GitHub}, \brand{Gitlab.com}, or
2103 % \brand{Bitbucket} account or register a new account.
2104 %
2105 % Of course, getting in touch with the package maintainer by
2106 % \href{mailto:guerquin-kernATcrans.org}{email} works as well.
2107 %
2108 % The authors have used this package together with a limited number of colleagues
2109 % for a few semesters of teaching. If other users adopt this package, we fully expect them
2110 % to find bugs.
2111 %
2112 % When experiencing a problem and before reporting it, please check whether
2113 % or not something similar has already been filed as an issue
2114 % \href{https://framagit.org/mattgk/moodle/-/issues?scope=all&state=all}{here}.
2115 % If the problem appears to be new, please report it by following these steps:
2116 % \begin{enumerate}
2117 % \item Prepare a \emph{minimal} working example, i.e. a \filenm{.tex} file shrunk down
2118 % to the strict minimum (loaded packages, code, \dots) while still showing the
2119 % faulty behavior upon compilation.
2120 % \item Gather and send the \filenm{*.tex}, \filenm{*.log} and \filenm{*-moodle.xml} files together
2121 % with an explanation about
2122 % \begin{itemize}
2123 % \item your local working environment (\TeX\ engine and distribution, platform,
2124 % external tools used, \dots),
2125 % \item the version of the \Moodle\ instance you are using
2126 % (for instance see the file |https://|\meta{server-domain}|/lib/upgrade.txt| )
2127 % \item the faulty behavior, and
2128 % \item what you expected instead.
2129 % \end{itemize}
2130 % \end{enumerate}
2131 %
2132 % \subsection{Known Limitations}
2133 %
2134 % When using with pdf\TeX\ for compilation, \pkg{moodle} supports
2135 % question contents with \acro{ASCII} characters only. The use of
2136 % non-\acro{ASCII} characters may work in some cases but will most
2137 % probably yield compilation errors or undesired \XML\ contents.
2138 %
2139 % Instead, \pkg{moodle} will work flawlessly when \XeTeX\ and
2140 % \LuaTeX\ are used to compile \UTF-8 encoded documents.
2141 %
2142 % Table~\vref{tab:support-limitations} lists
2143 % some features supported, limitations, and bugs.
2144 %\begin{table}[tbp]
2145 %\centering
2146 %\begin{threeparttable}[b]
2147 %\caption{Content enrichment (pictures, equations) support after \XML\ import in \Moodle\ v3.5.7,
2148 % depending on the question type.}
2149 %\label{tab:support-limitations}
2150 %\begin{tabular}{lccc}
2151 % \toprule
2152 % & \multicolumn{3}{l}{XML rendering in\dots}\\\cmidrule(lr){2-4}
2153 %Question type & Question & Answer & Feedback\\\cmidrule(lr){1-1}\cmidrule(lr){2-2}
2154 %\cmidrule(lr){3-3}\cmidrule(lr){4-4}
2155 % \href{https://docs.moodle.org/en/Multiple_Choice_question_type}{Multichoice}
2156 %& yes & yes & yes \\
2157 % \href{https://docs.moodle.org/en/Numerical_question_type}{Numerical}
2158 %& yes & no\tnote{1} & yes \\
2159 % \href{https://docs.moodle.org/en/Short-Answer_question_type}{Short Answer}
2160 % & yes & no\tnote{1} & yes \\
2161 % Matching (\href{https://docs.moodle.org/en/Matching_question_type}{std})
2162 %& yes & no\tnote{2} & no\tnote{3} \\
2163 % Matching (\href{https://docs.moodle.org/en/Drag_and_drop_matching_question_type}{dd})
2164 % & yes & yes\tnote{4} & no\tnote{3} \\
2165 % \href{https://docs.moodle.org/en/Essay_question_type}{Essay}
2166 %& yes & yes\tnote{5,6} & yes\tnote{5} \\
2167 % \href{https://docs.moodle.org/en/True/False_question_type}{True/False}
2168 %& yes & no & yes \\
2169 % \href{https://docs.moodle.org/en/Description_question_type}{Description}
2170 %& yes & $\varnothing$ & yes \\
2171 %\href{https://docs.moodle.org/en/Embedded_Answers_(Cloze)_question_type}{Cloze} &
2172 %yes & $\varnothing$& $\varnothing$ \\\cmidrule(lr){1-1}
2173 %\hspace{1em}Numerical & yes & no\tnote{1} & yes \\
2174 %\hspace{1em}Short Answer & yes & no\tnote{1} & yes\tnote{7} \\
2175 %\hspace{1em}Multi (inline) & yes & no\tnote{2} & yes\tnote{7} \\
2176 %\hspace{1em}Multi (horizontal) & yes & yes & yes \\
2177 %\hspace{1em}Multi (vertical) & yes & yes & yes \\\bottomrule
2178 %\end{tabular}
2179 %\begin{tablenotes}
2180 %\item[1] \Moodle\ prompts the student for an answer and then compares it to the
2181 %solutions provided. This is text-only.
2182 %\item[2] \Moodle\ uses a dropdown list to let one choose among the possible
2183 %answers. This forbids either picture inclusion and \LaTeX\ rendering.
2184 %\item[3] Not supported by \Moodle\ (in this context, answer-specific feedback
2185 %represents lots of possible combinations).
2186 %\item[4] The drag-and-drop-matching plugin seems broken before version 1.6
2187 %20190409. \Moodle's \XML\ import fails with a \texttt{dmlwriteexception} when
2188 %the field content exceeds few hundreds characters. This prevents the inclusion
2189 %of most base64 images and maybe some complicated equations.
2190 %\item[5] For this question type and in the context of \XML\ generation, the
2191 %Answer column represents the ``template" while the Feedback column represents
2192 %the ``notes for the grader". Obviously, the grading process is not automatic
2193 %and there is no answer-specific feedback.
2194 %\item[6] Picture and \LaTeX\ rendering could be done, but only after
2195 %submission and only if the keyval ``response format" is set to ``html".
2196 %\item[7] \Moodle\ only reveals the feedback when hovering the checkmark or X
2197 %mark with the mouse.
2198 %\end{tablenotes}
2199 %\end{threeparttable}
2200 %\end{table}
2201 %
2202 % Some features of \Moodle\ quizzes have not yet been implemented in \pkg{moodle}.
2203 % Here is a non-exhaustive list.
2204 % \begin{itemize}
2205 % \item \Moodle's feature of designating feedback for correct,
2206 % partially correct, and incorrect answers.
2207 %^^A \item Calculated questions; that is, automatically generated \env{numerical} questions
2208 %^^A using randomly chosen numbers.
2209 % \item Hints
2210 % \item Units handling in \env{numerical} questions
2211 % \end{itemize}
2212 %
2213 % \subsection{Compatibility}
2214 % This package has been originally written for and tested with the implementation of
2215 % \Moodle\ 2.9 run by Moodlerooms for St.~Norbert College in January 2016.
2216 % Since then, it has been successfully combined with \Moodle\ 3.5.
2217 %
2218 % The package option \optn{LMS} lets you specify the targeted \Moodle\ version
2219 % and helps ensuring compatibility.
2220 %
2221 % As the ultimate purpose of this package is the generation of \XML\ files,
2222 % future versions of \pkg{moodle} will attempt to maintain backwards
2223 % compatibility with earlier versions regarding the \XML\ output, apart from
2224 % bug fixes.
2225 % Backwards compatibility of the \PDF\ output is not yet guaranteed, however,
2226 % in case the author or users discover better ways for the \PDF\ to display
2227 % the underlying \XML\ data to be proofread.
2228 %
2229 % In other words, compiling your current \filenm{.tex} file with a future version
2230 % of \pkg{moodle} should produce the same \XML\ file it does now
2231 % (apart from bug fixes),
2232 % but it might produce a more informative, and hence different,
2233 % \PDF\ output.
2234 %
2235 % \subsection{Unrelated Tip: Quality of \Moodle\ \TeX\ Images}
2236 % This has nothing to do with \pkg{moodle}, but is a Frequently Asked Question
2237 % in is own right.
2238 % On some servers, at least, \Moodle's default ``\TeX\ Filter'' for
2239 % displaying mathematical notation is of abysmally poor quality, rending mathematics
2240 % as low-resolution \PNG's. One solution that has worked for me is to go
2241 % to ``Course Administration $\to$ Filters,'' turn ``\TeX\ Notation'' \emph{off},
2242 % but turn ``MathJax'' \emph{on}. This forces \TeX\ code to be rendered by MathJax
2243 % instead of \Moodle, producing much higher-quality results.
2244 %
2245 % ^^A\clearpage
2246 % \changes{v0.5}{2016/01/05}{Initial version}
2247 % \changes{v0.6}{2019/02/18}{Bug-fixing release}
2248 % \changes{v0.7}{2020/07/09}{Feature extensions}
2249 % \changes{v0.8}{2021/01/04}{Bug fixes and feature extensions}
2250 % \changes{v0.9}{2021/02/07}{Bug fixes and feature extensions}
2251 % \changes{v1.0}{2023/01/28}{Bug fixes and feature extensions}
2252 % \begin{changelog}[title={Version History},sectioncmd=\section*,author={Matthieu Guerquin-Kern}]
2253 % ^^A \begin{version}[version=\fileversion,]^^Adate=]
2254 % ^^A \end{version}
2255 % \begin{version}[version=1.0,date=2023-01-28]
2256 % \added
2257 % ^^A \item A section describing the use of templates for generating large number
2258 % ^^A of quizzes has been added (courtesy of Colin Caprani).
2259 % \item For templating purposes, in \optn{draft} mode, general TeX code can
2260 % now be used in items and |tolerance| key of numerical questions
2261 % (courtesy of Colin Caprani).
2262 % \item Support for the \env{quote} and \env{quotation} environments in the HTML
2263 % conversion process (courtesy of Gerald Teschl).
2264 % \item Experimental package option \optn{pluginfile} mimics the way
2265 % \Moodle\ embeds pictures in the \XML.
2266 % \item Answer box for Essay questions with \optn{handout}.
2267 % \item Key-value package option \optn{LMS} to target a specific version
2268 % of \Moodle.
2269 % \item Support for more text mode diacritic and horizontal spacing
2270 % commands.
2271 % \item Macros \cmd{\moodleversion} and \cmd{\moodledate} are defined.
2272 % \item Experimental package option \optn{samepage} to avoid splitting
2273 % questions across multiple pages.
2274 % \item \optn{sanction} key to set default mark for incorrect answers.
2275 % \item Started the internationalization of the package based on
2276 % \pkg{translator} (optionally \pkg{translations}). English,
2277 % French, German, Italian, and Spanish
2278 % are fully supported (with help from J\"urgen Vollmer for German
2279 % and Romano Giannetti for Italian and Spanish). Contributions are welcome.
2280 % \item Warn user of the \pkg{babel} package set for Turkish
2281 % that using the shorthands will not play well with \pkg{moodle}.
2282 % \item Support for \cmd{\i} in conversion to \HTML.
2283 % \item \SVG\ option support for Windows (courtesy of Wolf M\"uller).
2284 % \changed
2285 % \item In Cloze \env{multi} subquestions, the default mode is
2286 % \optn{inline} when only one answer is to be selected and
2287 % \optn{vertical} when several answers can be selected.
2288 % \item Single straight quotes (apostrophe) in math mode are passed as-is
2289 % to the \XML\ (with help from Keno Wehr).
2290 % \item Empty groups |{}| in math-mode are passed as-is to the \XML\
2291 % (with help from Keno Wehr).
2292 % \item Inside \env{cloze} subquestions, \optn{points} are forced to the
2293 % nearest positive integer. ^^AA warning is issued when the user setting
2294 % ^^Ais modified.
2295 % \item \XML\ stamp exposes compilation time.
2296 % \item Labels of proposed answers now following \Moodle's convention
2297 % (\emph{1., 2., \dots}) in the \PDF\ typesetting of \env{multi} questions.
2298 % \item Automatic sanction mechanism for incorrect choices in \env{multi}
2299 % questions with multiple answers allowed. Now applies also inside
2300 % \env{cloze} questions.
2301 % \item In \env{cloze} subquestions, non-integer fractions are rounded.
2302 % \item Rewording of some indications in the \PDF, related to internationalization.
2303 % \item The answers of \env{matching} questions are now converted to \HTML\
2304 % (accents and \cmd{\htmlonly} in mind).
2305 % \removed
2306 % \item Support for non-\acro{ASCII} characters abandoned when compiling
2307 % with \prog{pdflatex}.
2308 % \fixed
2309 % \item In math-mode, \cmd{\underline} is no longer translated to \HTML.
2310 % \item Preexisting pictures no longer get deleted when including graphics
2311 % without specifying the extension (courtesy of Colin Caprani).
2312 % \item In answers of \env{matching} questions, some \TeX\ macros will not
2313 % break compilation. A problem with curly braces persists.
2314 % \item The cloze subquestions now inherit \optn{points} set at
2315 % the higher levels.
2316 % \item Option \optn{single=false} now works in Cloze \env{multi} questions.
2317 % \item Undesired trailing spaces are removed from offered answers in
2318 % \env{matching} question.
2319 % \item Compatibility with \pkg{siunitx} version 3.
2320 % \item Compatibility with \pkg{minted} starting from 2021/12/24 v2.6.
2321 % \item Different issues with graphics handling on Windows (\prog{magick},
2322 % \prog{del}, \prog{move},\dots).
2323 % \item Symbols |<| and |>| are translated to \HTML\ equivalents, also in
2324 % text-mode.
2325 % \item Warning german-writing and (Xe$\mid$Lua)\TeX\ users about troubles
2326 % caused by text-mode umlauts.
2327 % \item In \env{cloze} subquestions items and outside math environments,
2328 % the equal symbol (|=|) no longer interferes with the Cloze syntax.
2329 % \item A pagebreak occuring inside cloze shortanswers would reset page numbers.
2330 % \item The redefinition of the \env{description} environment is limited to
2331 % the scope of the \env{quiz}.
2332 % \item PDF typesetting of matching answers (line breaks, repeated matches).
2333 % \item Symbols \cmd{\%} found inside math mode are escaped for \HTML.
2334 % \item The \optn{fraction} keys specified inside \env{cloze} questions are
2335 % forced to integer values as required by \Moodle's \XML\ format.
2336 % \item True/False no longer broken when \pkg{hyperref} is loaded.
2337 % \item Tolerances in \env{numerical} answers now correctly displayed in \PDF.
2338 % \item Warning for users running a too old version of \pkg{graphics}.
2339 % \item In the code included with \pkg{verbatim}, \pkg{fancyvrb}, or
2340 % \pkg{fvextra}, characters that matter for \HTML\ are escaped.
2341 % \end{version}
2342 % \begin{version}[version=0.9,date=2021-02-07]
2343 % \added
2344 % \item Support for \href{https://docs.moodle.org/en/All_or_nothing_multiple_choice_question_type}
2345 % {all-or-nothing multiple choice} questions.
2346 % \item Support for the ogonek diacritical mark via \cmd{\k}\marg{\dots}.
2347 % \item Warn user of the \pkg{babel} package set for a German-related language
2348 % that using the character |"| will not play well with \pkg{moodle}.
2349 % \item Support for \pkg{babel} commands related to German quotes.
2350 % \item Support for en-dash (--) outside of math mode.
2351 % \item Support for \cmd{\%} in conversion to \HTML.
2352 % \item Command |\htmlonly[]{}| to pass \HTML\ contents directly to the \XML\ file.
2353 % \changed
2354 % \item An error is issued when a graphics conversion step fails.
2355 % \item Irrelevant points are no longer written at the \env{cloze} question level in \PDF\ and \XML.
2356 % \item The total number of marks is shown in the \PDF\ at the end of each quiz.
2357 % \item The \optn{tags} key can now be used to specify a comma-separated list of tags.
2358 % \fixed
2359 % \item Answer text of \env{shortanswer} questions is converted to \HTML.
2360 % \item Paragraph breaks in \env{multi} and \env{essay} items no longer break compilation.
2361 % \item Question text in Essays was not shown in \PDF\ file.
2362 % \item Commands \cmd{\textsc}, \cmd{\underline}, \cmd{\url}, and \cmd{\href} yielded \HTML\ code with
2363 % inadequate double quotation marks.
2364 % \item Broken base64-encoding pipeline for images under Windows (thanks to Andreas Vohns).
2365 % \item Repeated single right quotation marks no longer merged in math mode
2366 % (thanks to Alberto Albano).
2367 % \end{version}
2368 % \begin{version}[version=0.8,date=2021-01-04]
2369 % \added
2370 % \item Support for inclusion of \GIF\ pictures.
2371 % \item Added package option \optn{svg} to avoid the rasterization of vector graphics.
2372 % \item New macro \cmd{\setsubcategory} to define subcategories, reflected in \PDF\ and \XML.
2373 % \item Package option \optn{handout} for sharing \PDF\ with students.
2374 % \item Extensions can be omitted when including pictures.
2375 % \item Description question type.
2376 % \item \LuaLaTeX\ is now supported (and recommended for \UTF-8 coded sources).
2377 % \item Examples of ways to reproduce the behavior of calculated questions.
2378 % \item Command to trigger the automatic recording of new commands.
2379 % \item Mechanism to match \optn{fraction} key to values accepted by \Moodle.
2380 % \item A \optn{fractiontol} key to control the tolerance in this mechanism.
2381 % \item Support for inverted punctuation marks |¿| and |¡|.
2382 % \item Support for \cmd{\_} and \cmd{\textbackslash}.
2383 % \item Support for the wildcard character as an answer in \env{numerical} questions.
2384 % \changed
2385 % \item Template of Essay questions is now shown in \PDF.
2386 % \item The macro \cmd{\setcategory} is reflected by a new section in \PDF.
2387 % \item In \env{matching} questions, warnings are raised if the number of items is insufficient.
2388 % \item Improved display of \env{matching} questions in \PDF.
2389 % \item The package \pkg{iftex} is now required.
2390 % \item An error is thrown when \optn{fraction} is set to an invalid value.
2391 % \item In \env{numerical} questions, the tolerance can be set in exponent form.
2392 % \item Nicer \PDF\ rendering of numbers in \env{numerical} questions if \pkg{siunitx} is loaded.
2393 % \item Included \PNG\ and \acro{JPEG} files are now directly converted to base64.
2394 % \fixed
2395 % \item TeX's inline math (\texttt{$...$}) can now contain escaped dollar signs (\cmd{\$}).
2396 % \item Closing braces escaped in \env{cloze} subquestions outside math environment.
2397 % \item The scope of the \optn{tolerance} key is now respected.
2398 % \end{version}
2399 % \begin{version}[version=0.7,date=2020-09-06]
2400 % \added
2401 % \item Support for inclusion of verbatim code.
2402 % \item Package option \optn{tikz}.
2403 % \item Support for \cmd{\"Y} and \cmd{\"y}.
2404 % \item New commands converted to \XML.
2405 % \item Adding a stamp comment in \XML, package option offered to disable
2406 % this behavior.
2407 % \item Support for the \cmd{\tikz} command.
2408 % \item A different directory can be specified for picture inclusion.
2409 % \item Warn user of the \pkg{babel} package set for French that autospacing
2410 % must be deactivated.
2411 % \item Square bracket math delimiters are recognized and converted properly.
2412 % \item Support of breve and caron diacritical marks.
2413 % \changed
2414 % \item In \env{multi} with multiple answers allowed, choosing all options no longer
2415 % results in a good grade. An automatic penalty mechanism is introduced.
2416 % Can be overridden by manually setting fractions.
2417 % \removed
2418 % \item Irrelevant \optn{penalty} tag in \env{cloze} subquestions.
2419 % \fixed
2420 % \item Non-integer fractions can now be specified in \env{cloze} subquestions.
2421 % \item Significantly squeeze \PNG\ images size by skipping ancillary data.
2422 % \item Enumerate or itemize environment can now be nested in question items.
2423 % \item Several pictures can be included in a question without being mixed
2424 % in the \XML\ file.
2425 % \item Management and rendering of fraction in questions.
2426 % \item Correctly handling a \LaTeX\ command starting the last item of a question.
2427 % \item Closing braces escaped in \env{cloze} subquestions. This allows \LaTeX\
2428 % equations or images to be included.
2429 % \item Image inclusion with macOS.
2430 % \end{version}
2431 % \begin{version}[version=0.6b,date=2019-11-27]
2432 % \added
2433 % \item New package options to set section or subsection at the quiz level.
2434 % \item True/False question type is now supported.
2435 % \item \Moodle\ tags can now be specified for questions (and rendered in \PDF\
2436 % as well).
2437 % \item In \env{cloze} questions, the multiresponse subquestion type is
2438 % now supported.
2439 % \removed
2440 % \item External dependency on \prog{OpenSSL}.
2441 % \item Irrelevant tags were written in \XML\ for \env{matching} questions.
2442 % \fixed
2443 % \item \TikZ\ externalization now works when using \XeLaTeX.
2444 % \item It is now possible to set points manually among several correct
2445 % answers in multichoice questions.
2446 % \item General feedback can now contain backslashes.
2447 % \item Several quizzes can now be defined in a single source file, each
2448 % specifying a category for \Moodle's question bank.
2449 % \item Correct encoding information is now written in \XML\ depending on
2450 % the \LaTeX\ compiler used.
2451 % \end{version}
2452 % \begin{version}[version=0.6a,date=2019-06-21]
2453 % \added
2454 % \item \XeLaTeX\ is now recommended when using \UTF-8 encoded sources (support
2455 % of accents).
2456 % \item Feedbacks are now displayed in the \PDF\ file produced.
2457 % \item The \prog{OptiPNG} utility is used to reduce the size
2458 % of images embedded in the \XML\ file.
2459 % \item Question options and settings are now displayed in the \PDF\ file
2460 % \item Supporting more \LaTeX\ macros for symbols and accents (mostly
2461 % diacritical marks and ligatures).
2462 % \item Introduce shuffle options in cloze-multi subquestions.
2463 % \item Package option \optn{final}.
2464 % \changed
2465 % \item In draft mode, \TikZ\ externalization is no longer triggered.
2466 % \fixed
2467 % \item In the different question types, the feedback fields are now converted
2468 % for \HTML\ allowing \LaTeX\ equations and images.
2469 % \item Documentation improvements (limitations and previously undocumented
2470 % features).
2471 % \end{version}
2472 % \shortversion{version=0.5,date=2016-01-05,simple,changes=Initial version,author={Anders O.F. Hendrickson}}
2473 % \end{changelog}
2474 % \addcontentsline{toc}{section}{Version History}%
2475 % \PrintIndex
2476 % \addcontentsline{toc}{section}{Index}%
2477 % \StopEventually{%
2478 %^^A \PrintChanges
2479 % }
2480 %
2481 % \section{Implementation}
2482 % \subsection{Packages, Options, and Utilities}
2483 % \begin{macrocode}
2484 \newif\ifmoodle@draftmode
2485 \newif\ifmoodle@handout
2486 \newif\ifmoodle@stampmode
2487 \newif\ifmoodle@tikz
2488 \newif\ifmoodle@tikzloaded
2489 \newif\ifmoodle@svg
2490 \newif\ifmoodle@section
2491 \newif\ifmoodle@subsection
2492 \newif\ifmoodle@numbered
2493 \newif\ifmoodle@international
2494 \newif\ifmoodle@feedbackLeft% contribution of Juergen Vollmer, 2021-03-05
2495 \newif\ifmoodle@samepage% contribution of Romano Giannetti, 2021-03-07
2496 \newif\ifmoodle@pluginfile%
2497
2498 %% Moodle version
2499 \RequirePackage{xkeyval}%For key-handling
2500 \newcount\moodle@LMSmajor% major version number of the LMS targeted
2501 \newcount\moodle@LMSminor% minor version number of the LMS targeted
2502
2503 %%DECLARATION OF OPTIONS
2504 \DeclareOptionX{draft}{\moodle@draftmodetrue}%
2505 \DeclareOptionX{handout}{\moodle@handouttrue}%
2506 \DeclareOptionX{final}{\moodle@draftmodefalse}%
2507 \DeclareOptionX{nostamp}{\moodle@stampmodefalse}%
2508 \DeclareOptionX{tikz}{\moodle@tikztrue}%
2509 \DeclareOptionX{svg}{\moodle@svgtrue}%
2510 \DeclareOptionX{section}{\moodle@sectiontrue\moodle@numberedtrue}%
2511 \DeclareOptionX{section*}{\moodle@sectiontrue\moodle@numberedfalse}%
2512 \DeclareOptionX{subsection}{\moodle@sectionfalse\moodle@numberedtrue}%
2513 \DeclareOptionX{subsection*}{\moodle@sectionfalse\moodle@numberedfalse}%
2514 \DeclareOptionX{feedbackleft}{\moodle@feedbackLefttrue}% contribution of Juergen Vollmer, 2021-03-05
2515 \DeclareOptionX{feedbackright}{\moodle@feedbackLeftfalse}% default
2516 \DeclareOptionX{samepage}{\moodle@samepagetrue}% contribution of Romano Giannetti, 2021-03-07
2517 \DeclareOptionX{LMS}[0.0]{%
2518 \filename@parse{#1}%
2519 \moodle@LMSmajor=\filename@base
2520 \moodle@LMSminor=\filename@ext
2521 }%
2522 \DeclareOptionX{pluginfile}{\moodle@pluginfiletrue}%
2523
2524 \moodle@draftmodefalse
2525 \moodle@handoutfalse
2526 \moodle@stampmodetrue
2527 \moodle@tikzfalse
2528 \moodle@tikzloadedfalse
2529 \moodle@svgfalse
2530 \moodle@subsectiontrue
2531 \moodle@numberedfalse
2532 \moodle@feedbackLeftfalse% contribution of Juergen Vollmer, 2021-03-05
2533 \moodle@samepagefalse% contribution of Romano Giannetti, 2021-03-07
2534 \moodle@pluginfilefalse
2535
2536 \ProcessOptionsX*% the star allows to inherit 'draft' and 'final' from the class
2537
2538 \ifmoodle@samepage
2539 \def\moodle@begin@samepage{\minipage[t]{\linewidth}}
2540 \def\moodle@end@samepage{\endminipage\vskip 0pt plus 50pt\relax}
2541 \else
2542 % defining to relax is safer versus adding spurious spaces
2543 \def\moodle@begin@samepage{\relax}
2544 \def\moodle@end@samepage{\relax}
2545 \fi
2546
2547 \RequirePackage{environ} %To be able to take environment body as a macro argument
2548 \RequirePackage{amssymb} %For \checkmark symbol
2549 %\RequirePackage{trimspaces} %To remove extra spaces from strings (loaded by environ)
2550 \@ifpackageloaded{iftex}{}{\RequirePackage{iftex}}
2551 % iftex already required by recent versions of ifplatform. Needed to know:
2552 % 1) whether we can convert output from PDF to \PNG\ (ifpdf),
2553 % 2) when output pdf is latin1-encoded (ifpdf)
2554 % 3) when output xml is utf8-encoded (if?tex)
2555 \@ifundefined{ifeTeX}{% version of 'iftex' prior to November 2019.
2556 \RequirePackage{etex}{}
2557 }{
2558 \ifeTeX\else
2559 \RequirePackage{etex}{} % Recent (2015+) TeX engines should be e-TeX.
2560 %This is needed for expansion control, detokenization, etc.
2561 \fi
2562 }
2563 \RequirePackage{etoolbox}%List management
2564 \RequirePackage{xpatch} %To patch commands easily in \HTML\ mode
2565 \RequirePackage{array} %For formatting tables in the LaTeX mode of Clozes
2566 \RequirePackage{ifplatform} % To choose Ghostscript commands
2567 \@ifundefined{ifpdf}{\RequirePackage{ifpdf}}{}% old iftex would not define the conditional
2568 \RequirePackage{shellesc} %Luatex-compatible way of getting system access
2569 \RequirePackage{readprov} %To gather information on the package (version, date, ...)
2570 \RequirePackage{fancybox} %For fancy LaTeX tags
2571 \RequirePackage{getitems} %To gather the header and items
2572 \ifmoodle@handout
2573 \RequirePackage[seed=42]{randomlist} %To randomize answers in matching questions
2574 \fi
2575 \ifmoodle@svg
2576 \RequirePackage{graphicx} %To include graphics
2577 \fi
2578
2579 \GetFileInfo{moodle.sty}%
2580 \edef\moodledate{\filedate}%
2581 \edef\moodleversion{\fileversion}%
2582
2583 \let\xa=\expandafter
2584 \def\@star{*}%
2585 \def\@hundred{100}%
2586 \def\@fifty{50}%
2587 \def\@moodle@empty{}%
2588 \def\@relax{\relax}%
2589 \def\@moodle@par{\par}%
2590
2591 % Taken from https://tex.stackexchange.com/questions/47576/combining-ifxetex-and-ifluatex-with-the-logical-or-operation
2592 \@ifundefined{ifTUTeX}{
2593 \newif\ifTUTeX % a new conditional starts as false
2594 \ifnum 0\ifXeTeX 1\fi\ifLuaTeX 1\fi>0\relax
2595 \TUTeXtrue
2596 \fi
2597 }{}%
2598 \newif\ifpdfoutput % a new conditional starts as false
2599 \ifnum 0\ifTUTeX 1\fi\ifPDFTeX\ifpdf 1\fi\fi>0\relax
2600 \pdfoutputtrue
2601 \fi
2602 % \end{macrocode}
2603 % As the package involves a fair bit of file processing,
2604 % we automate the naming of auxiliary files.
2605 % \begin{macrocode}
2606 \def\jobnamewithsuffixtomacro#1#2{%
2607 \filenamewithsuffixtomacro{#1}{\jobname}{#2}%
2608 }
2609 \def\@jn@quote{"}%
2610 \def\filenamewithsuffixtomacro#1#2#3{%
2611 % #1 = macro to create
2612 % #2 = filename to add suffix to
2613 % #3 = suffix to add
2614 \edef\jn@suffix{#3}%
2615 \def\jn@macro{#1}%
2616 \xa\testforquote#2\@jn@rdelim
2617 }
2618 \def\testforquote#1#2\@jn@rdelim{%
2619 \def\jn@test@i{#1}%
2620 \ifx\jn@test@i\@jn@quote
2621 % Involves quotes
2622 \edef\jn@next{"\jn@stripquotes#1#2\jn@suffix"}%
2623 \else
2624 \edef\jn@next{#1#2\jn@suffix}%
2625 \fi
2626 \xa\xdef\jn@macro{\jn@next}%
2627 }
2628 \def\jn@stripquotes"#1"{#1}%
2629
2630
2631 \jobnamewithsuffixtomacro{\outputfilename}{-moodle.xml}
2632 % \end{macrocode}
2633 % Next, we create macros to open and close the Moodle \XML\ file
2634 % we will be writing.
2635 % \begin{macrocode}
2636 \newwrite\moodle@outfile
2637 \def\openmoodleout{%
2638 \immediate\openout\moodle@outfile=\outputfilename\relax
2639 \ifPDFTeX % latin1-based engines (pdflatex or latex)
2640 \writetomoodle{<?xml version="1.0" encoding="iso-8859-1"?>}%
2641 \else
2642 \ifTUTeX % UTF8-based engines (XeTeX or LuaTeX)
2643 \writetomoodle{<?xml version="1.0" encoding="UTF-8"?>}%
2644 \else % what shall we do?
2645 \writetomoodle{<?xml version="1.0" encoding="UTF-8"?>}%
2646 %\stop
2647 \fi
2648 \fi
2649 \ifmoodle@stampmode
2650 \def\moodle@stamp{This is a question bank made for Moodle }
2651 \ifnum\the\moodle@LMSmajor\the\moodle@LMSminor=\z@\else
2652 \g@addto@macro{\moodle@stamp}{\the\moodle@LMSmajor.\the\moodle@LMSminor.\space}
2653 \fi
2654 \writetomoodle{<!-- \moodle@stamp -->}%
2655 \newcount\hour\hour=\time
2656 \divide\hour by 60\relax
2657 \newcount\minute\minute=\hour
2658 \multiply\minute by -60\relax
2659 \advance\minute by \time\relax
2660 \def\moodle@stamp{It was generated on \the\year-\two@digits\month-\two@digits\day\space \the\hour:\the\minute}
2661 \ifPDFTeX % pdflatex or latex
2662 \ifpdf % pdflatex
2663 \g@addto@macro{\moodle@stamp}{ by pdfLaTeX }%
2664 \else % latex
2665 \g@addto@macro{\moodle@stamp}{ by LaTeX }%
2666 \fi
2667 \else
2668 \ifXeTeX % xetex
2669 \g@addto@macro{\moodle@stamp}{ by XeLaTeX }%
2670 \else
2671 \ifLuaTeX % luatex
2672 \g@addto@macro{\moodle@stamp}{ by LuaLaTeX }%
2673 \else
2674 \g@addto@macro{\moodle@stamp}{ a TeX engine }%
2675 \fi
2676 \fi
2677 \fi
2678 \writetomoodle{<!-- \moodle@stamp running -->}%
2679 \def\moodle@stamp{on \platformname}%
2680 \g@addto@macro{\moodle@stamp}{ with the package moodle \moodleversion\space (\moodledate) }%
2681 \writetomoodle{<!-- \moodle@stamp -->}%
2682 \fi
2683 \immediate\write\moodle@outfile{}%
2684 \writetomoodle{<quiz>}%
2685 }%
2686 \def\closemoodleout{%
2687 \writetomoodle{ }%
2688 \writetomoodle{</quiz>}%
2689 \immediate\closeout\moodle@outfile
2690 }%
2691 % \end{macrocode}
2692 %
2693 % To both make this \filenm{.sty} file and the \XML\ output more readable,
2694 % we create a mechanism for writing to the output file with indents.
2695 % The macro |\calculateindent|\marg{$n$} globally defines
2696 % |\moodle@indent| to be a string of \meta{$n$} |\otherspace|'s.
2697 % \begin{macrocode}
2698 \newcount\moodle@indentnum
2699 \def\calculateindent#1{%
2700 \bgroup
2701 \moodle@indentnum=\number#1\relax
2702 \gdef\moodle@indent{}%
2703 \calculateindent@int
2704 \egroup
2705 }%
2706 \def\calculateindent@int{%
2707 \ifnum\moodle@indentnum>0\relax
2708 \g@addto@macro{\moodle@indent}{\otherspace}%
2709 \advance\moodle@indentnum by -1\relax
2710 \expandafter
2711 \calculateindent@int
2712 \fi
2713 }%
2714 % \end{macrocode}
2715 % Now the command |\writetomoodle|\oarg{n}\marg{stuff} adds the line
2716 % ``\meta{stuff}'' to the \XML\ file
2717 % preceded by an indent of \meta{n} spaces.
2718 % Note that this command |\edef|'s its second argument.
2719 % \begin{macrocode}
2720 \newcommand\writetomoodle[2][0]{%
2721 \edef\test@ii{#2}%
2722 \ifnum#1=0\relax
2723 \immediate\write\moodle@outfile{\test@ii}%
2724 \else
2725 \calculateindent{#1}%
2726 \immediate\write\moodle@outfile{\moodle@indent\trim@pre@space{\test@ii}}%
2727 \fi
2728 }%
2729 % \end{macrocode}
2730 % We now create the main |quiz| environment that will contain
2731 % the questions we write. It outputs to \XML\ as a |<question type="category">| tag.
2732 % \begin{macrocode}
2733 {\catcode`\$=12\catcode`\ =12% in this context we cannot indent with spaces...
2734 \gdef\moodle@write@category@xml#1{%
2735 \@moodle@ifgeneratexml{%
2736 \writetomoodle{ }%
2737 \writetomoodle{<question type="category">}%
2738 \writetomoodle{ <category>}%
2739 \writetomoodle{ <text>$course$/top/#1</text>}%
2740 \writetomoodle{ </category>}%
2741 \writetomoodle{</question>}%
2742 \writetomoodle{ }%
2743 }{}%
2744 }}%
2745 \newcommand*\@enumeratename{enumerate}%
2746 \newdimen\moodle@totalmarks
2747 \gdef\moodle@currentcategory{}%
2748 \newenvironment{quiz}[2][]{%
2749 \setkeys{moodle}{#1}%
2750 \gdef\setcategory##1{%
2751 % At first call (end of \begin{quiz}) enumerate is not started yet
2752 \ifx\@currenvir\@enumeratename
2753 % In case no question is defined between two calls of \setcategory
2754 \def\@noitemerr{}%\@latex@warning{Empty question list}
2755 \end{enumerate}%
2756 \fi
2757 \gdef\moodle@currentcategory{##1}%
2758 \moodle@write@category@xml{##1}%
2759 \ifmoodle@section
2760 \ifmoodle@numbered
2761 \section{##1}%
2762 \else
2763 \section*{##1}%
2764 \fi
2765 \else
2766 \ifmoodle@numbered
2767 \subsection{##1}%
2768 \else
2769 \subsection*{##1}%
2770 \fi
2771 \fi
2772 \begin{enumerate}\renewcommand\labelenumi{(\theenumi)}%
2773 }%
2774 \gdef\setsubcategory##1{%
2775 \def\@noitemerr{}%\@latex@warning{Empty question list}
2776 \end{enumerate}%
2777 \moodle@write@category@xml{\moodle@currentcategory/##1}%
2778 \ifmoodle@section
2779 \ifmoodle@numbered
2780 \subsection{##1}%
2781 \else
2782 \subsection*{##1}%
2783 \fi
2784 \else
2785 \ifmoodle@numbered
2786 \subsubsection{##1}%
2787 \else
2788 \subsubsection*{##1}%
2789 \fi
2790 \fi
2791 \begin{enumerate}\renewcommand\labelenumi{(\theenumi)}%
2792 }%
2793 \setcategory{#2}%
2794 \moodle@totalmarks=0pt%
2795 }{%
2796 \end{enumerate}%
2797 \emph{\GetTranslation{Total of marks}: \strip@pt\moodle@totalmarks}%
2798 \let\setcategory\relax
2799 \let\setsubcategory\relax
2800 }%
2801
2802 % \end{macrocode}
2803 % The next utility takes a single macro control sequence |#1|,
2804 % and allows that macro's current value to persist
2805 % after the next |\egroup|, |}|, or |\endgroup|.
2806 % \begin{macrocode}
2807 \def\passvalueaftergroup#1{%
2808 \xa\xa\xa\gdef\xa\xa\csname moodle@remember@\string#1\endcsname\xa{\xa\def\xa#1\xa{#1}}%
2809 \xa\aftergroup\csname moodle@remember@\string#1\endcsname
2810 }
2811 % \end{macrocode}
2812 %
2813 % \subsubsection{Main Switch: to create \XML\ or not}
2814 %
2815 % \begin{macrocode}
2816 \long\def\@moodle@ifgeneratexml#1#2{%
2817 % If we are generating \XML, do #1; otherwise do #2.
2818 \tikzifexternalizing{%
2819 % This run of LaTeX is currently ONLY generating a TikZ image
2820 % to be saved in an external file. We do NOT want to waste time
2821 % generating \XML, and moreover trying to do so would cause errors
2822 % because of file dependencies.
2823 #2%
2824 }{%
2825 \ifmoodle@draftmode
2826 #2%
2827 \else
2828 #1%
2829 \fi
2830 }%
2831 }
2832 % \end{macrocode}
2833 % Now the macros |openmoodleout| and |closemoodleout| are triggered at Begin and End Document, respectively
2834 % \begin{macrocode}
2835 \AfterEndPreamble{
2836 \@moodle@ifgeneratexml{%
2837 \openmoodleout%
2838 }{}%
2839 }
2840 \AtEndDocument{
2841 \@moodle@ifgeneratexml{%
2842 \closemoodleout%
2843 }{}%
2844 }
2845 % \end{macrocode}
2846 %
2847 % \subsection{Key-Value Pairs for Quiz Questions}
2848 %
2849 % The various options are set using key-value syntax of |xkeyval|.
2850 % \begin{macrocode}
2851 \def\moodleset#1{\setkeys{moodle}{#1}}%
2852 % \end{macrocode}
2853 % We first define some macros that will help us write other macros.
2854 % Calling |\generate@moodle@write@code|\marg{name}|<|\meta{HTML tag}|>|\marg{text to write}
2855 % creates a macro |\moodle@write|\meta{name}, taking no parameters,
2856 % which writes the code |<|\meta{HTML tag}|>...</|\meta{HTML tag}|>|
2857 % to the output \XML\ file.
2858 %
2859 % The ordinary version |\generate@moodle@write@code| passes its output text |#3|
2860 % through the HTMLizer, producing \HTML\ code, while the starred variant
2861 % |\generate@moodle@write@code*| passes |#3| verbatim as text.
2862 %
2863 % For example,
2864 % |\generate@moodle@write@code{excuse}<EXC>{\theexcuse}|
2865 % would expand to
2866 % \begin{Verbatim}[gobble=4,frame=single]
2867 % \gdef\moodle@writeexcuse{%
2868 % \xa\def\xa\test@iii\xa{\theexcuse}%
2869 % \ifx\test@iii\@moodle@empty
2870 % \writetomoodle[2]{ <EXC format="html"><text/></EXC>}%
2871 % \else
2872 % \xa\converttohtmlmacro\xa\moodle@htmltowrite\xa{\theexcuse}%
2873 % \writetomoodle[2]{ <EXC format="html">}%
2874 % \writetomoodle[4]{ <text><![CDATA[<p>\moodle@htmltowrite</p>]]></text>}%
2875 % \writetomoodle[2]{ </EXC>}%
2876 % \fi
2877 % }%
2878 % \end{Verbatim}
2879 % but
2880 % |\generate@moodle@write@code*{excuse}<EXC>{\theexcuse}|
2881 % would expand only to
2882 % \begin{Verbatim}[gobble=4,frame=single]
2883 % \gdef\moodle@writeexcuse{%
2884 % \writetomoodle[2]{ <EXC>\theexcuse</EXC>}%
2885 % }
2886 % \end{Verbatim}
2887 % \begin{macrocode}
2888 \def\generate@moodle@write@code{%
2889 \@ifnextchar*\generate@moodle@write@data\generate@moodle@write@html
2890 }%
2891
2892 \def\generate@moodle@write@html#1<#2>#3{%
2893 % #1 = NAME for \moodle@writeNAME
2894 % #2 = \HTML\ tag
2895 % #3 = what, exactly, to write
2896 \xa\gdef\csname moodle@write#1\endcsname{%
2897 \xa\def\xa\test@iii\xa{#3}%
2898 \ifx\test@iii\@moodle@empty
2899 \writetomoodle[2]{ <#2 format="html"><text/></#2>}%
2900 \else
2901 \xa\converttohtmlmacro\xa\moodle@htmltowrite\xa{#3}%
2902 \writetomoodle[2]{ <#2 format="html">}%
2903 \writetomoodle[4]{ <text><![CDATA[<p>\moodle@htmltowrite</p>]]></text>}%
2904 \ifmoodle@pluginfile
2905 \writetomoodle[0]{\htmlize@embeddedfiletags}%
2906 \fi
2907 \writetomoodle[2]{ </#2>}%
2908 \fi
2909 }%
2910 }%
2911
2912 \def\generate@moodle@write@html@noptag#1<#2>#3{%
2913 % No <P>..</P> introduced
2914 % #1 = NAME for \moodle@writeNAME
2915 % #2 = \HTML\ tag
2916 % #3 = what, exactly, to write
2917 \xa\gdef\csname moodle@write#1\endcsname{%
2918 \xa\def\xa\test@iii\xa{#3}%
2919 \ifx\test@iii\@moodle@empty
2920 \writetomoodle[2]{ <#2 format="html"><text/></#2>}%
2921 \else
2922 \xa\converttohtmlmacro\xa\moodle@htmltowrite\xa{#3}%
2923 \writetomoodle[2]{ <#2 format="html">}%
2924 \writetomoodle[4]{ <text><![CDATA[\moodle@htmltowrite]]></text>}%
2925 \ifmoodle@pluginfile
2926 \writetomoodle[0]{\htmlize@embeddedfiletags}%
2927 \fi
2928 \writetomoodle[2]{ </#2>}%
2929 \fi
2930 }%
2931 }%
2932
2933 \def\generate@moodle@write@data*#1<#2>#3{%
2934 % #1 = NAME for \moodle@writeNAME
2935 % #2 = \HTML\ tag
2936 % #3 = what, exactly, to write
2937 \xa\gdef\csname moodle@write#1\endcsname{%
2938 \writetomoodle[2]{ <#2>#3</#2>}%
2939 }%
2940 }%
2941
2942 \def\moodle@writetags{%
2943 \xa\xdef\xa\test@iii\xa{\moodle@tags}%
2944 \ifx\test@iii\@moodle@empty\relax\else
2945 \writetomoodle[2]{ <tags>}%
2946 \renewcommand*{\do}[1]{%
2947 \def\moodle@tagtext{##1}%
2948 \xa\converttohtmlmacro\xa\moodle@htmltowrite\xa{\moodle@tagtext}%
2949 \writetomoodle[4]{ <tag><text><![CDATA[\moodle@htmltowrite]]></text></tag>}%
2950 }
2951 \xa\docsvlist\xa{\moodle@tags}%
2952 \writetomoodle[2]{ </tags>}%
2953 \fi
2954 }%
2955 \newif\ifmoodle@firsttag
2956 \moodle@firsttagtrue
2957 \def\moodle@latex@writetags{%
2958 \xa\xdef\xa\test@iii\xa{\moodle@tags}%
2959 \ifx\test@iii\@moodle@empty\relax\else
2960 \hfill \GetTranslation{tags}: %
2961 \renewcommand*{\do}[1]{\ifmoodle@firsttag\moodle@firsttagfalse\else, \fi\texttt{##1}}%
2962 \xa\docsvlist\xa{\test@iii}%
2963 \fi
2964 }%
2965 % \end{macrocode}
2966 % \subsubsection{Keys for all question types}
2967 % \begin{macrocode}
2968 %% QUESTIONNAME
2969 \define@cmdkey{moodle}[moodle@]{questionname}{}%
2970 % \gdef\moodle@writequestionname{%
2971 % \writetomoodle[2]{<name>}%
2972 % \writetomoodle[4]{ <text>\moodle@questionname</text>}%
2973 % \writetomoodle[2]{</name>}%
2974 % }%
2975 %\generate@moodle@write@code{questionname}<name>{\moodle@questionname}%
2976 \generate@moodle@write@html@noptag{questionname}<name>{\moodle@questionname}%
2977
2978 %% QUESTIONTEXT
2979 %I tried to use questiontext as a key, but it doesn't seem to work.
2980 %The trouble is that xkeyval has trouble parsing a key with a \par token followed by a comma within brackets,
2981 %like \setkeys{moodle}{questiontext={ABC\par [D,E]}}
2982 %It's not worth trying to fix.
2983
2984 \long\def\questiontext#1{%
2985 %\converttohtmlmacro\myoutput{#1}%
2986 %\let\moodle@questiontext=\myoutput%
2987 \def\moodle@questiontext{#1}%
2988 }%
2989 \generate@moodle@write@code{questiontext}<questiontext>{\moodle@questiontext}%{%
2990
2991 %% PENALTY FOR WRONG ATTEMPT
2992 \define@cmdkey{moodle}[moodle@]{penalty}[0.10]{}%
2993 \generate@moodle@write@code*{penalty}<penalty>{\moodle@penalty}%
2994 \moodleset{penalty=0.10}%
2995
2996 %% FEEDBACK
2997 % Moodle allows for feedback tailored to each question,
2998 % and feedback tailored to each right or wrong answer.
2999 % We shall use the key 'feedback' to record both kinds of feedback,
3000 % relying on TeX's grouping mechanism to keep them apart.
3001 % When it comes time to write them to \XML,
3002 % \moodle@writegeneralfeedback uses the \HTML\ tag <generalfeedback>
3003 % whereas \moodle@writefeedback uses the tag <feedback>.
3004 % Note that the general feedback is NOT inherited by each answer!
3005 \define@cmdkey{moodle}[moodle@]{feedback}[]{}%
3006 \generate@moodle@write@code{generalfeedback}<generalfeedback>{\moodle@feedback}%
3007 \generate@moodle@write@code{feedback}<feedback>{\moodle@feedback}%
3008 \moodleset{feedback={}}%
3009
3010 %% DEFAULT GRADE
3011 %The next line creates \moodle@defaultgrade,
3012 %which is how many points the quiz question is worth.
3013 %Key calls like [default grade=7] set \moodle@defaultgrade.
3014 \define@cmdkey{moodle}[moodle@]{default grade}[1.0]{}%
3015 %Next, makes 'points' a synonym for 'default grade'
3016 \define@key{moodle}{points}[1.0]{\xa\def\csname moodle@default grade\endcsname{#1}}%
3017 \generate@moodle@write@code*{defaultgrade}<defaultgrade>{\csname moodle@default grade\endcsname}%
3018 \moodleset{default grade=1.0} %This sets the default.
3019
3020 %% HIDDEN
3021 \define@boolkey{moodle}[moodle@]{hidden}[true]{}%
3022 \generate@moodle@write@code*{hidden}<hidden>{\ifmoodle@hidden 1\else 0\fi}%
3023 \moodleset{hidden=false}%
3024
3025 \def\moodle@writecommondata{%
3026 \moodle@writequestionname%
3027 \moodle@writequestiontext%
3028 \moodle@writedefaultgrade%
3029 \moodle@writegeneralfeedback%
3030 \moodle@writepenalty%
3031 \moodle@writehidden%
3032 }%
3033
3034 %% TAGS
3035 %The next line creates \moodle@tags,
3036 %which defines a "tag" (i.e., keyword) for the question.
3037 %Key calls like [tags={random}] set \moodle@tags.
3038 \define@cmdkey{moodle}[moodle@]{tags}[]{}%
3039 \moodleset{tags={}}%
3040
3041 % \end{macrocode}
3042 % \subsubsection{Keys for all answers}
3043 % \begin{macrocode}
3044 %% FRACTION -- how much this answer is worth out of 100 percent
3045 \define@cmdkey{moodle}[moodle@]{fraction}[100]{}%
3046 %We do not create \moodle@writefraction, because the fraction occurs in
3047 %the \XML\ within the answer tag, like <answer fraction="75">.
3048 \moodleset{fraction=100} %This sets the default.
3049 % \end{macrocode}
3050 % \begin{macrocode}
3051 %% FRACTIONTOL -- the tolerance for fractions with respect to valid values
3052 \define@cmdkey{moodle}[moodle@]{fractiontol}[0.1]{}%
3053 \moodleset{fractiontol=0.1} %This sets the default.
3054 % \end{macrocode}
3055 % \subsubsection{Keys for multiple choice questions}
3056 % \begin{macrocode}
3057
3058 %% SINGLE and MULTIPLE -- for multichoice, is there 1 right answer or more than 1?
3059 \define@boolkey{moodle}[moodle@]{single}[true]{}%
3060 \generate@moodle@write@code*{single}<single>{\ifmoodle@single true\else false\fi}%
3061 \moodleset{single=true}%
3062 %The key 'multiple' is an antonym to 'single'.
3063 \define@boolkey{moodle}[moodle@]{multiple}[true]{\ifmoodle@multiple\moodle@singlefalse\else\moodle@singletrue\fi}%
3064
3065 %% SHUFFLE ANSWERS
3066 \define@boolkey{moodle}[moodle@]{shuffle}[true]{}%
3067 \generate@moodle@write@code*{shuffle}<shuffleanswers>{\ifmoodle@shuffle 1\else 0\fi}%
3068 \moodleset{shuffle=true}%
3069
3070 %% ALLORNOTHING -- for multichoice with multiple answers where all the points are given
3071 % if and only if all the correct answers are selected.
3072 \define@boolkey{moodle}[moodle@]{allornothing}[true]{}%
3073 \moodleset{allornothing=false}%
3074
3075 %% SANCTION -- how much shall incorrect choices by sanctioned in multichoice questions (single)
3076 \define@cmdkey{moodle}[moodle@]{sanction}[]{}%
3077 \moodleset{sanction=0} %This sets the default.
3078
3079 %% TODO: CORRECTFEEDBACK
3080 %% TODO: PARTIALLYCORRECTFEEDBACK
3081 %% TODO: INCORRECTFEEDBACK
3082 %% TODO: NUMCORRECT key
3083
3084 %% NUMBERING -- for numbering of multichoice questions
3085 \define@choicekey{moodle}{numbering}%
3086 {alpha,alph,Alpha,Alph,arabic,roman,Roman,%
3087 abc,ABCD,123,iii,IIII,none}[abc]{%
3088 \def\moodle@numbering{#1}%
3089 \def\test@@i{#1}%
3090 \ifx\test@@i\@moodle@alpha
3091 \def\moodle@numbering{abc}\fi
3092 \ifx\test@@i\@moodle@alph
3093 \def\moodle@numbering{abc}\fi
3094 \ifx\test@@i\@moodle@Alpha
3095 \def\moodle@numbering{ABCD}\fi
3096 \ifx\test@@i\@moodle@Alph
3097 \def\moodle@numbering{ABCD}\fi
3098 \ifx\test@@i\@moodle@arabic
3099 \def\moodle@numbering{123}\fi
3100 \ifx\test@@i\@moodle@roman
3101 \def\moodle@numbering{iii}\fi
3102 \ifx\test@@i\@moodle@Roman
3103 \def\moodle@numbering{IIII}\fi
3104 }%
3105 %'answer numbering' will be a synonym to 'numbering'
3106 \define@key{moodle}{answer numbering}[abc]{\setkeys{moodle}{numbering={#1}}}%
3107 \generate@moodle@write@code*{answernumbering}<answernumbering>{\moodle@numbering}%
3108 %N.B. if we did not set the default here, then \moodle@numbering would be undefined, causing problems.
3109 \moodleset{answer numbering=abc}%
3110
3111 \def\@moodle@alpha{alpha}%
3112 \def\@moodle@Alpha{Alpha}%
3113 \def\@moodle@alph{alph}%
3114 \def\@moodle@Alph{Alph}%
3115 \def\@moodle@arabic{arabic}%
3116 \def\@moodle@roman{roman}%
3117 \def\@moodle@Roman{Roman}%
3118 \def\@moodle@abc{abc}%
3119 \def\@moodle@ABCD{ABCD}%
3120 \def\@moodle@arabicnumbers{123}%
3121 \def\@moodle@iii{iii}%
3122 \def\@moodle@IIII{IIII}%
3123 \def\@moodle@none{none}%
3124 \def\moodle@obeynumberingstyle{%
3125 \renewcommand\labelenumii{\theenumii.}% follow Moodle's labeling convention
3126 \ifx\moodle@numbering\@moodle@abc
3127 \renewcommand\theenumii{\alph{enumii}}%
3128 \fi
3129 \ifx\moodle@numbering\@moodle@ABCD
3130 \renewcommand\theenumii{\Alph{enumii}}%
3131 \fi
3132 \ifx\moodle@numbering\@moodle@arabicnumbers
3133 \renewcommand\theenumii{\arabic{enumii}}%
3134 \fi
3135 \ifx\moodle@numbering\@moodle@iii
3136 \renewcommand\theenumii{\roman{enumii}}%
3137 \fi
3138 \ifx\moodle@numbering\@moodle@IIII
3139 \renewcommand\theenumii{\Roman{enumii}}%
3140 \fi
3141 \ifx\moodle@numbering\@moodle@none
3142 \renewcommand\labelenumii{$\bullet$~}%
3143 \fi
3144 }
3145 %TODO: * In the PDF, how should 'none' in a multi look different from
3146 % short answer or numerical options?
3147 % * Instead of \theenumi and \labelenumi,
3148 % use \@enumdepth to automatically set the correct depth.
3149
3150 %% DISPLAY MODE -- affects Cloze multiple choice questions only.
3151 % 0 = inline, 1 = vertical, 2 = horizontal
3152 \def\moodle@multi@mode{\ifmoodle@single 0\else 1\fi}%
3153 \define@key{moodle}{inline}[]{\def\moodle@multi@mode{0}}%
3154 \define@key{moodle}{vertical}[]{\def\moodle@multi@mode{1}}%
3155 \define@key{moodle}{horizontal}[]{\def\moodle@multi@mode{2}}%
3156 % \end{macrocode}
3157 % \subsubsection{Keys for numerical questions}
3158 % \begin{macrocode}
3159 %% TOLERANCE
3160 \define@cmdkey{moodle}[moodle@]{tolerance}[0]{}%
3161 \moodleset{tolerance=0}%
3162 %There is no \moodle@writetolerance, because in the \XML\ the
3163 %tolerance is given within the answer tag,
3164 %like <answer fraction=100 tolerance=0.03>.
3165
3166 % TODO: implement unit-handling for numerical questions!
3167 % \end{macrocode}
3168 % \subsubsection{Keys for short answer questions}
3169 % \begin{macrocode}
3170 %% CASE SENSITIVE
3171 \define@boolkey{moodle}[moodle@]{usecase}[true]{}%
3172 \generate@moodle@write@code*{usecase}<usecase>{\ifmoodle@usecase 1\else 0\fi}%
3173 % We make 'case sensitive' a synonym for 'usecase'.
3174 \define@boolkey{moodle}[moodle@]{case sensitive}[true]{\ifcsname moodle@case sensitive\endcsname \moodle@usecasetrue\else\moodle@usecasefalse\fi}%
3175 \moodleset{usecase=false}%
3176 % \end{macrocode}
3177 % \subsubsection{Keys for matching questions}
3178 % \begin{macrocode}
3179 %% DRAG-AND-DROP FORMAT
3180 \define@boolkey{moodle}[moodle@]{draganddrop}[true]{}%
3181 % We make 'dd' and 'draganddrop' and 'drag and drop' synonyms for 'draganddrop'.
3182 \define@boolkey{moodle}[moodle@]{dd}[true]{\ifmoodle@dd\moodle@draganddroptrue\else\moodle@draganddropfalse\fi}%
3183 \define@boolkey{moodle}[moodle@]{drag and drop}[true]{\moodle@ddsynonym}%
3184 \def\moodle@ddsynonym{%
3185 \csname ifmoodle@drag and drop\endcsname
3186 \moodle@draganddroptrue
3187 \else
3188 \moodle@draganddropfalse
3189 \fi
3190 }
3191 \moodleset{draganddrop=false}%
3192 % \end{macrocode}
3193 % \subsubsection{Keys for essay questions}
3194 % \begin{macrocode}
3195 %% EDITOR
3196 \def\@moodle@html{html}%
3197 \def\@moodle@htmlfile{html+file}%
3198 \def\@moodle@text{text}%
3199 \def\@moodle@plain{plain}%
3200 \def\@moodle@monospaced{monospaced}%
3201 \def\@moodle@file{file}%
3202 \def\@moodle@noinline{noinline}%
3203 \define@choicekey{moodle}{response format}%
3204 {html,html+file,text,monospaced,file}[html]%
3205 {\def\test@i{#1}%
3206 \ifx\test@i\@moodle@html
3207 % \HTML\ Editor
3208 \def\moodle@responseformat{editor}%
3209 \fi
3210 \ifx\test@i\@moodle@htmlfile
3211 % \HTML\ Editor with File Picker
3212 \def\moodle@responseformat{editorfilepicker}%
3213 \fi
3214 \ifx\test@i\@moodle@text
3215 % Plain text
3216 \def\moodle@responseformat{plain}%
3217 \fi
3218 \ifx\test@i\@moodle@plain
3219 % Plain text
3220 \def\moodle@responseformat{plain}%
3221 \fi
3222 \ifx\test@i\@moodle@monospaced
3223 % Plain text, monospaced font
3224 \def\moodle@responseformat{monospaced}%
3225 \fi
3226 \ifx\test@i\@moodle@file
3227 % No inline text (i.e., attachments only)
3228 \def\moodle@responseformat{noinline}%
3229 \fi
3230 \ifx\test@i\@moodle@noinline
3231 % No inline text (i.e., attachments only)
3232 \def\moodle@responseformat{noinline}%
3233 \fi
3234 }%
3235 \generate@moodle@write@code*{responseformat}<responseformat>{\moodle@responseformat}%
3236 \moodleset{response format=html}%
3237 %N.B. if we did not set a default, then \moodle@responseformat would be undefined, causing problems.
3238
3239 %% RESPONSE REQUIRED
3240 \define@boolkey{moodle}[moodle@]{response required}[true]{}%
3241 % TODO: Make synonym 'required'
3242 \generate@moodle@write@code*{responserequired}<responserequired>{\csname ifmoodle@response required\endcsname 1\else 0\fi}%
3243 \moodleset{response required=false}%
3244
3245 %% RESPONSEFIELDLINES
3246 \define@cmdkey{moodle}[moodle@]{response field lines}[15]{}%
3247 \generate@moodle@write@code*{responsefieldlines}<responsefieldlines>{\csname moodle@response field lines\endcsname}%
3248 %Make synonyms 'input box size' or 'height' or 'lines'?
3249 \moodleset{response field lines=15}% N.B. if we do not set a default, then \moodle@responseformat will be undefined, causing problems.
3250
3251 %% ATTACHMENTS ALLOWED
3252 \def\@moodle@unlimited{unlimited}%
3253 \define@choicekey{moodle}{attachments allowed}{0,1,2,3,unlimited}[1]{%
3254 \def\test@i{#1}%
3255 \ifx\test@i\@moodle@unlimited
3256 \def\moodle@attachmentsallowed{-1}%
3257 \else
3258 \def\moodle@attachmentsallowed{#1}%
3259 \fi
3260 }
3261 \generate@moodle@write@code*{attachmentsallowed}<attachments>{\moodle@attachmentsallowed}
3262 \moodleset{attachments allowed=0}%
3263
3264 %% ATTACHMENTS REQUIRED
3265 \define@choicekey{moodle}{attachments required}{0,1,2,3}[1]{\def\moodle@attachmentsrequired{#1}}%
3266 \generate@moodle@write@code*{attachmentsrequired}<attachmentsrequired>{\moodle@attachmentsrequired}
3267 \moodleset{attachments required=0}%
3268
3269 %% RESPONSE TEMPLATE
3270 \define@key{moodle}{template}{\long\def\moodle@responsetemplate{#1}}%
3271 \generate@moodle@write@html@noptag{responsetemplate}<responsetemplate>{\moodle@responsetemplate}
3272 \moodleset{template={}}%
3273 % \end{macrocode}
3274 % \subsubsection{Hint tags}
3275 % The following are not yet fully implemented.
3276 % \begin{macrocode}
3277 %% SHOWNUMCORRECT
3278 \define@boolkey{moodle}[moodle@]{shownumcorrect}[true]{}%
3279 \gdef\moodle@writeshownumcorrect{%
3280 \if\moodle@shownumcorrect
3281 \writetomoodle[4]{ <shownumcorrect/>}%
3282 \fi
3283 }%
3284 \moodleset{shownumcorrect=false}%
3285
3286 %% CLEARWRONG
3287 \define@boolkey{moodle}[moodle@]{clearwrong}[true]{}%
3288 \gdef\moodle@writeclearwrong{%
3289 \if\moodle@clearwrong
3290 \writetomoodle[4]{ <clearwrong/>}%
3291 \fi
3292 }%
3293 \moodleset{clearwrong=false}%
3294
3295 % TODO: Implement hints
3296 % \end{macrocode}
3297 %
3298 % \subsection{Answer handling}
3299 %
3300 % \begin{macrocode}
3301 %The Answers \XML\ depends heavily on the question type.
3302 %Each type of question defines how it obtains answers from the LaTeX input,
3303 %how it typesets those in a \PDF\ or \DVI, and how it writes them as \XML\ code.
3304 %It will write that \XML\ to the macro \moodle@answers@xml,
3305 %which them gets written to the file when \moodle@writeanswers
3306 %is invoked.
3307
3308 \def\moodle@answers@xml{}%
3309 \gdef\moodle@writeanswers{%
3310 \writetomoodle{\moodle@answers@xml}%
3311 }%
3312
3313 \newcommand\addto@xml[3][0]{%
3314 % #1 = spaces to indent (default=0)
3315 % #2 = macro containing \XML\ code (possibly empty)
3316 % #3 = \XML\ text to be appended to that macro (will be \edef'd)
3317 \calculateindent{#1}%
3318 \edef\xml@to@add{\moodle@indent\trim@pre@space{#3}}%
3319 \ifx#2\@moodle@empty
3320 \edef\newxml{\noexpand#2\xml@to@add}%
3321 \else
3322 \edef\newxml{\noexpand#2^^J\xml@to@add}%
3323 \fi
3324 \xa\xa\xa\def\xa\xa\xa#2\xa\xa\xa{\newxml}%
3325 }%
3326 % \end{macrocode}
3327 %
3328 % \subsubsection{Not yet implemented}
3329 %
3330 % \begin{macrocode}
3331
3332 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3333 %% CALCULATED %%%%%%%%%%%%%%%%%%%%%%%%%%
3334
3335 % TODO: I don't think I really want to handle this. Not now.
3336
3337 % \end{macrocode}
3338 %
3339 % \subsection{Typesetting options}
3340 % This section provides the tools to allow on to control how the quiz gets typeset
3341 % in the resulting PDF file.
3342 % \begin{macrocode}
3343 \ifmoodle@feedbackLeft% contribution of Juergen Vollmer, 2021-03-05
3344 \newcommand{\moodle@preFeedback}{\\}%
3345 \else%
3346 \newcommand{\moodle@preFeedback}{\hfill}%
3347 \fi
3348 % \end{macrocode}
3349 %
3350 % \subsection{Front Ends}
3351 % This section creates the user interface for the various question types.
3352 % First, we define a generic command to create
3353 % a front-end environment for a Moodle question type.
3354 % In order to function, the following macros must be hard-coded:
3355 % \begin{itemize}
3356 % \item |\moodle@|\meta{type}|@latexprocessing|:
3357 % Loops through the saved |\item|'s to typeset them in LaTeX,
3358 % usually inside an itemize or enumerate environment.
3359 % \item |\save|\meta{type}|answer#1|:
3360 % Processes the text of a single |\item| to save the information to memory,
3361 % usually inside |\moodle@answers@xml|.
3362 % \item |\write|\meta{type}|question|:
3363 % Writes the information, hitherto saved only in macros,
3364 % into the \XML\ file.
3365 % \end{itemize}
3366 % For example, to create the `shortanswer' question type,
3367 % we shall call
3368 % \begin{Verbatim}[gobble=5,frame=single]
3369 % \moodle@makefrontend{shortanswer}
3370 % \def\moodle@shortanswer@latexprocessing{...}
3371 % \def\saveshortansweranswer#1{...}
3372 % \def\writeshortanswerquestion{...}
3373 % \end{Verbatim}
3374 %
3375 % \begin{macrocode}
3376
3377 \def\moodle@makelatextagbox#1{%
3378 % \ifmoodle@tikzloaded
3379 % \tikzset{external/export next=false}
3380 % \tikz[baseline]{\node[draw,minimum height=1.2em,rounded corners,fill=black!20] {\tiny #1};}
3381 % % Fancy but interferes with the tikzexternalize counter
3382 % \else
3383 \Ovalbox{\tiny #1}
3384 %\ovalbox{\tiny #1}
3385 %\shadowbox{\tiny #1}
3386 % \fi
3387 }%
3388
3389 \def\moodle@makelatextag@qtype#1{%
3390 \doublebox{\tiny \textsc{\GetTranslation{#1}}}
3391 }%
3392
3393 \def\moodle@makelatextag@value#1#2{%
3394 \moodle@makelatextagbox{\GetTranslation{#2}~\csname moodle@#1\endcsname}%
3395 }%
3396
3397 \def\moodle@makelatextag@key#1{%
3398 \moodle@makelatextagbox{\GetTranslation{#1}}
3399 }%
3400
3401 \def\moodle@makelatextag@other#1{%
3402 \moodle@makelatextagbox{\GetTranslation{#1}}
3403 }%
3404
3405 \def\moodle@makefrontend#1#2{%
3406 \NewEnviron{#1}[2][]{%
3407 \bgroup
3408 \setkeys{moodle}{##1,questionname={##2}}%
3409 \global\advance\moodle@totalmarks by \csname moodle@default grade\endcsname pt
3410 \expandafter\gatheritems\xa{\BODY}%
3411 \let\moodle@questionheader=\gatheredheader
3412 %First, the LaTeX processing
3413 \item \moodle@begin@samepage \textbf{\moodle@questionname}
3414 \ifmoodle@handout
3415 \moodle@makelatextag@qtype{#1}
3416 \else
3417 \moodle@latex@writetags
3418 \par
3419 \noindent
3420 \moodle@makelatextag@qtype{#1}%
3421 \moodle@makelatextag@value{default grade}{marked out of}
3422 \moodle@makelatextag@value{penalty}{penalty}%
3423 \fi
3424 #2\par
3425 \noindent
3426 \moodle@questionheader
3427 \edef\moodle@generalfeedback{\expandonce\moodle@feedback}
3428 \csname moodle@#1@latexprocessing\endcsname
3429 \moodle@end@samepage
3430 %Now, writing information to XML
3431 \@moodle@ifgeneratexml{%
3432 \xa\questiontext\xa{\moodle@questionheader}% Save the question text.
3433 \csname write#1question\endcsname
3434 \bgroup
3435 \gdef\moodle@answers@xml{}%
3436 \setkeys{moodle}{feedback={}}%
3437 \xa\loopthroughitemswithcommand\xa{\csname save#1answer\endcsname}%
3438 \passvalueaftergroup{\moodle@answers@xml}%
3439 \egroup
3440 \moodle@writeanswers%
3441 \moodle@writetags%
3442 \writetomoodle{</question>}%
3443 }{}%
3444 \egroup
3445 }%
3446 }
3447 % \end{macrocode}
3448 %
3449 % \subsubsection{Description Question Front-End}
3450 % Description and essay questions are the only question types whose front end
3451 % is not yet created by |\moodle@makefrontend|.
3452 % This is because of what need to be done with their contents.
3453 %
3454 % Description blocks can be empty. In this case, nothing is done.
3455 %
3456 % \begin{macrocode}
3457 \AtBeginEnvironment{quiz}{% protect existing description outside of quiz
3458 \let\description\relax% remove the meaning of existing \description and \enddescription
3459 \let\enddescription\relax
3460 \NewEnviron{description}[2][]{%
3461 \bgroup
3462 \setkeys{moodle}{#1,questionname={#2}}%
3463 \let\moodle@questiontext=\BODY
3464 \trim@spaces@in\moodle@questiontext
3465 \ifx\moodle@questiontext\@empty\relax\else%
3466 %First, the LaTeX processing.
3467 \item \moodle@begin@samepage\textbf{\moodle@questionname}
3468 \ifmoodle@handout\else
3469 \moodle@latex@writetags
3470 \par
3471 \noindent
3472 \fi
3473 \moodle@makelatextag@qtype{description}\par
3474 \noindent
3475 \moodle@questiontext\par
3476 \ifmoodle@handout\else
3477 \ifx\moodle@feedback\@empty\relax\else
3478 \fbox{\parbox{.96\linewidth}{\emph{\moodle@feedback}}}%
3479 \fi
3480 \fi
3481 \moodle@end@samepage
3482 %Now, writing information to memory.
3483 \@moodle@ifgeneratexml{%
3484 \writetomoodle{<question type="description">}%
3485 \moodle@writecommondata
3486 \moodle@writetags%
3487 \writetomoodle{</question>}%
3488 }{}%
3489 \fi
3490 \egroup
3491 }%
3492 }%
3493 % \end{macrocode}
3494 %
3495 % \subsubsection{Essay Question Front-End}
3496 % The front end is not yet created by |\moodle@makefrontend| because of
3497 % what must must be done with the |\item|'s.
3498 %
3499 % \begin{macrocode}
3500 \def\moodle@essay@latexprocessing{%
3501 % Moodle cannot automatically grade an essay,
3502 % but if the user puts \item's in, we can list them in an itemize as notes.
3503 \par\noindent \emph{\GetTranslation{Information for graders}:}
3504 \ifnum\c@numgathereditems>0\relax
3505 \begin{itemize} \setlength\itemsep{0pt}\setlength\parskip{0pt}%
3506 \loopthroughitemswithcommand{\moodle@print@essay@answer}%
3507 \end{itemize}%
3508 \fi
3509 \ifx\moodle@generalfeedback\@empty\relax\else%
3510 \fbox{\parbox{.96\linewidth}{\emph{\moodle@generalfeedback}}}%
3511 \fi
3512 }
3513
3514 \NewEnviron{essay}[2][]{%
3515 \bgroup
3516 \setkeys{moodle}{#1,questionname={#2}}%
3517 \global\advance\moodle@totalmarks by \csname moodle@default grade\endcsname pt%
3518 \moodle@checkresponsefieldlines
3519 \expandafter\gatheritems\expandafter{\BODY}%
3520 \let\moodle@questionheader=\gatheredheader
3521 %First, the LaTeX processing.
3522 \item \moodle@begin@samepage\textbf{\moodle@questionname}
3523 \ifmoodle@handout
3524 \moodle@makelatextag@qtype{essay}
3525 \else
3526 \moodle@latex@writetags
3527 \par
3528 \noindent
3529 \moodle@makelatextag@qtype{essay}
3530 \moodle@makelatextag@value{default grade}{marked out of}
3531 \moodle@makelatextag@value{penalty}{penalty}
3532 \xa\moodle@makelatextag@key\xa{\moodle@responseformat}
3533 \fi
3534 \par
3535 \noindent
3536 \moodle@questionheader
3537 \long\def\@lempty{}%
3538 \ifx\moodle@responsetemplate\@lempty\else
3539 \par\noindent\emph{\GetTranslation{Response template}:}
3540 \par\noindent\fbox{\parbox{.96\linewidth}{\moodle@responsetemplate}}\par
3541 \fi
3542 \edef\moodle@generalfeedback{\expandonce\moodle@feedback}
3543 \ifmoodle@handout
3544 \par\noindent
3545 \fbox{\parbox[t][\csname moodle@response field lines\endcsname\baselineskip]{.96\linewidth}{\phantom{Moodle}}}%
3546 \else
3547 \csname moodle@essay@latexprocessing\endcsname
3548 \fi
3549 \moodle@end@samepage
3550 %Now, writing information to memory.
3551 \@moodle@ifgeneratexml{%
3552 \xa\questiontext\xa{\moodle@questionheader}% Save the question text.
3553 \writeessayquestion
3554 \bgroup
3555 \gdef\moodle@answers@xml{}%
3556 %
3557 \ifnum\c@numgathereditems=0\relax
3558 \addto@xml[2]\moodle@answers@xml{<graderinfo format="html"><text/></graderinfo>}%
3559 \else
3560 \addto@xml[2]\moodle@answers@xml{<graderinfo format="html"><text><![CDATA[}%
3561 \ifnum\c@numgathereditems>1\relax
3562 \addto@xml[4]\moodle@answers@xml{<ul>}%
3563 \fi
3564 \loopthroughitemswithcommand{\moodle@savegraderinfo}%
3565 \ifnum\c@numgathereditems>1\relax
3566 \addto@xml[4]\moodle@answers@xml{</ul>}%
3567 \fi
3568 \addto@xml[2]\moodle@answers@xml{]]></text></graderinfo>}%
3569 \fi
3570 %
3571 \passvalueaftergroup{\moodle@answers@xml}%
3572 \egroup
3573 \moodle@writeanswers% The 'answers' \XML\ really contains the grader info.
3574 \moodle@writeresponsetemplate%
3575 \moodle@writetags%
3576 \writetomoodle{</question>}%
3577 }{}%
3578 \egroup
3579 }%
3580
3581 \def\moodle@checkresponsefieldlines{%
3582 \newcount\a\a=\number\csname moodle@response field lines\endcsname
3583 \newcount\b\b=5%
3584 \ifnum\the\a>40\relax% if the value was more than 40
3585 \a=40%
3586 \fi
3587 \ifnum\the\a<5\relax% if the value was less than 5
3588 \a=5%
3589 \fi
3590 \divide\a by\b% integer division by 5
3591 \multiply\a by\b% multiply by 5
3592 \ifnum\a=\csname moodle@response field lines\endcsname\relax% equality holds if we had 5, 10, 15, 20, 25, 30, or 40
3593 \else
3594 \ifnum\csname moodle@response field lines\endcsname>5\relax%
3595 \ifnum\csname moodle@response field lines\endcsname<40\relax%
3596 \advance\a by\b% approximate with the next multiple of 5
3597 \fi
3598 \fi
3599 \PackageWarning{moodle}{"response field lines" admits only multiples of 5 between 5 and 40
3600 (You tried to set \csname moodle@response field lines\endcsname). The value
3601 \the\a\space will be used.}%
3602 \setkeys{moodle}{response field lines=\the\a}%
3603 \fi
3604 }%
3605
3606 %%%% TODO
3607 %%%% To make essay work will be tough.
3608 %%%% Every line from \ifnum\c@numgathereditems=0\relax through its \else and \fi,
3609 %%%% with the exception of
3610 %%%% \xa\loopthroughitemswithcommand\xa{\csname save#1answer\endcsname}%
3611 %%%% , does not exist in our current \moodle@makefrontend code.
3612 %%%% How can we cope?
3613 %%%%
3614 %%%% Idea: change \moodle@makefrontend so that
3615 %%%% 1. if \c@numgathereditems=0, we don't do anything.
3616 %%%% 2. it calls a preamble and postamble around the \loopthroughitemswithcommand.
3617 %%%% Like this:
3618 %%%%
3619 %%%% \@moodle@ifgeneratexml{%
3620 %%%% \xa\questiontext\xa{\moodle@questionheader}% Save the question text.
3621 %%%% \bgroup
3622 %%%% \gdef\moodle@answers@xml{}%
3623 %%%% \setkeys{moodle}{feedback={}}%
3624 %%%% \@ifundefined{moodle@#1@answers@preamble}{}{}%
3625 %%%% \csname moodle@#1@answers@preamble\endcsname
3626 %%%% \ifnum\c@numgathereditems=0\relax
3627 %%%% \relax
3628 %%%% \else
3629 %%%% \xa\loopthroughitemswithcommand\xa{\csname save#1answer\endcsname}%
3630 %%%% \fi
3631 %%%% \@ifundefined{moodle@#1@answers@postamble}{}{}%
3632 %%%% \csname moodle@#1@answers@postamble\endcsname
3633 %%%% \passvalueaftergroup{\moodle@answers@xml}%
3634 %%%% \egroup
3635 %%%% \csname write#1question\endcsname
3636 %%%% }{}%
3637 %%%% The \@ifundefined lines should automatically define the
3638 %%%% \...@preamble \...@postamble macros to be \relax if they don't exist already.
3639
3640 \gdef\writeessayquestion{%
3641 \writetomoodle{<question type="essay">}%
3642 \moodle@writecommondata%
3643 \moodle@writeresponserequired%
3644 \moodle@writeresponseformat%
3645 \moodle@writeresponsefieldlines%
3646 \moodle@writeattachmentsallowed%
3647 \moodle@writeattachmentsrequired%
3648 }%
3649
3650 \long\def\moodle@print@essay@answer#1{%
3651 \item #1%
3652 }%
3653
3654 \long\def\moodle@savegraderinfo#1{%
3655 \def\moodle@answertext{#1}
3656 \xa\converttohtmlmacro\xa\moodle@answertext@html\xa{\moodle@answertext}%
3657 %\trim@spaces@in\moodle@answertext
3658 \ifnum\c@numgathereditems>1\relax
3659 \addto@xml[6]{\moodle@answers@xml}{<li>\moodle@answertext@html</li>}%
3660 \else
3661 \addto@xml[4]{\moodle@answers@xml}{\moodle@answertext@html}%
3662 \fi
3663 }%
3664 % \end{macrocode}
3665 %
3666 % \subsubsection{Short Answer Question Front-End}
3667 %
3668 % \begin{macrocode}
3669 %\NewEnviron{shortanswer}[2][]{%
3670 % \bgroup
3671 % \setkeys{moodle}{#1,questionname={#2}}%
3672 % \expandafter\gatheritems\xa{\BODY}%
3673 % \let\moodle@questionheader=\gatheredheader
3674 % %First, the LaTeX processing.
3675 % \item \textbf{\moodle@questionname}
3676 % \csname ifmoodle@case sensitive\endcsname
3677 % \framebox{\tiny Case-Sensitive}\relax
3678 % \fi
3679 % \framebox{\tiny\csname moodle@default grade\endcsname~points}
3680 % \framebox{\tiny\csname moodle@penalty\endcsname~penalty}\par
3681 % \noindent
3682 % \moodle@questionheader
3683 % \csname moodle@shortanswer@latexprocessing\endcsname
3684 % %Now, writing information to memory.
3685 % \@moodle@ifgeneratexml{%
3686 % \xa\questiontext\xa{\moodle@questionheader}% Save the question text.
3687 % \bgroup
3688 % \gdef\moodle@answers@xml{}%
3689 % \setkeys{moodle}{feedback={}}%
3690 % \xa\loopthroughitemswithcommand\xa{\csname
3691 % saveshortansweranswer\endcsname}%
3692 % \passvalueaftergroup{\moodle@answers@xml}%
3693 % \egroup
3694 % \csname writeshortanswerquestion\endcsname
3695 % }{}%
3696 % \egroup
3697 % }%
3698
3699 \moodle@makefrontend{shortanswer}{\moodle@makelatextag@shortanswer}%
3700
3701 % LATEX PROCESSING
3702
3703 \def\moodle@makelatextag@shortanswer{%
3704 \ifmoodle@usecase
3705 \moodle@makelatextag@other{Case-Sensitive}\relax
3706 \else
3707 \moodle@makelatextag@other{Case-Insensitive}\relax
3708 \fi
3709 }
3710
3711 \ifmoodle@handout
3712 \let\moodle@shortanswer@latexprocessing\relax
3713 \else
3714 \def\moodle@shortanswer@latexprocessing{%
3715 \begin{itemize} \setlength\itemsep{0pt}\setlength\parskip{0pt}%
3716 \loopthroughitemswithcommand{\moodle@print@shortanswer@answer}%
3717 \end{itemize}%
3718 \ifx\moodle@generalfeedback\@empty\relax\else%
3719 \fbox{\parbox{.96\linewidth}{\emph{\moodle@generalfeedback}}}%
3720 \fi
3721 }
3722 \fi
3723
3724 \def\moodle@print@shortanswer@answer#1{%
3725 \let\moodle@feedback=\@empty
3726 \moodle@print@shortanswer@answer@int#1\@rdelim
3727 }%
3728 \newcommand\moodle@print@shortanswer@answer@int[1][]{%
3729 \setkeys{moodle}{#1}%
3730 \moodle@print@shortanswer@answer@int@int%
3731 }%
3732 \def\moodle@print@shortanswer@answer@int@int#1\@rdelim{%
3733 \ifx\moodle@fraction\@hundred
3734 \item #1$~\checkmark$%
3735 \else
3736 \moodle@checkfraction
3737 \item #1$~(\moodle@fraction\%)$%
3738 \fi
3739 \ifx\moodle@feedback\@empty\relax\else
3740 \moodle@preFeedback \emph{$\rightarrow$ \moodle@feedback}
3741 \fi
3742 }%
3743
3744 % SAVING ANSWERS TO MEMORY
3745 \def\saveshortansweranswer#1{%
3746 \bgroup
3747 \saveshortansweranswer@int#1\moodle@answer@rdelim
3748 \passvalueaftergroup{\moodle@answers@xml}%
3749 \egroup
3750 }%
3751 \newcommand\saveshortansweranswer@int[1][]{%
3752 \setkeys{moodle}{fraction=100,#1}% %%%%%% DEFAULT VALUE IS 100%
3753 \saveshortansweranswer@int@int%
3754 }%
3755 \def\saveshortansweranswer@int@int#1\moodle@answer@rdelim{%
3756 \def\moodle@answertext{#1}%
3757 \trim@spaces@in\moodle@answertext
3758 \moodle@checkfraction
3759 \addto@xml[2]{\moodle@answers@xml}{<answer fraction="\moodle@fraction" format="plain_text">}%
3760 \xa\converttohtmlmacro\xa\moodle@answertext@html\xa{\moodle@answertext}%
3761 \addto@xml[4]{\moodle@answers@xml}{ <text>\moodle@answertext@html</text>}%
3762 \ifmoodle@pluginfile
3763 \writetomoodle[0]{\htmlize@embeddedfiletags}%
3764 \fi
3765 \ifx\moodle@feedback\@empty\relax\else
3766 \trim@spaces@in\moodle@feedback
3767 \xa\converttohtmlmacro\xa\moodle@feedback@html\xa{\moodle@feedback}%
3768 \addto@xml[4]{\moodle@answers@xml}{ <feedback format="html"><text><![CDATA[<p>\moodle@feedback@html</p>]]></text>\ifmoodle@pluginfile\htmlize@embeddedfiletags\fi</feedback>}%
3769 \fi
3770 \addto@xml[2]{\moodle@answers@xml}{</answer>}%
3771 }%
3772
3773 % WRITING QUESTION TO \XML\ FILE
3774 \gdef\writeshortanswerquestion{%
3775 \writetomoodle{<question type="shortanswer">}%
3776 \moodle@writecommondata%
3777 \moodle@writeusecase%
3778 }%
3779 % \end{macrocode}
3780 %
3781 % \subsubsection{Numerical Question Front-End}
3782 %
3783 % \begin{macrocode}
3784 \moodle@makefrontend{numerical}{\moodle@makelatextag@numerical}%
3785
3786 % LATEX PROCESSING
3787
3788 \def\moodle@makelatextag@numerical{}
3789
3790 \AtEndPreamble{
3791 \@ifpackageloaded{siunitx}{\def\moodle@printnum{\num[omit-uncertainty]}}%,copy-decimal-marker
3792 {\let\moodle@printnum\trim@spaces}%
3793 }
3794
3795 \ifmoodle@handout
3796 \let\moodle@numerical@latexprocessing\relax
3797 \else
3798 \def\moodle@numerical@latexprocessing{%
3799 \begin{itemize} \setlength\itemsep{0pt}\setlength\parskip{0pt}%
3800 \loopthroughitemswithcommand{\moodle@print@numerical@answer}%
3801 \end{itemize}%
3802 \ifx\moodle@generalfeedback\@empty\relax\else%
3803 \fbox{\parbox{.96\linewidth}{\emph{\moodle@generalfeedback}}}%
3804 \fi
3805 }
3806 \fi
3807
3808 \def\moodle@print@numerical@answer#1{%
3809 \let\moodle@feedback=\@empty
3810 \bgroup
3811 \moodle@print@numerical@answer@int#1\@rdelim
3812 \egroup
3813 }%
3814 \newcommand\moodle@print@numerical@answer@int[1][]{%
3815 \setkeys{moodle}{#1}%
3816 \moodle@print@numerical@answer@int@int%
3817 }%
3818 \def\moodle@print@numerical@answer@int@int#1\@rdelim{%
3819 \gdef\test@i{#1}%
3820 \trim@spaces@in\test@i
3821 \ifx\test@i\@star
3822 \item \test@i
3823 \else
3824 \item \moodle@printnum{#1}%
3825 \ifx\moodle@tolerance\moodle@zero\else
3826 $\,\pm\,$\moodle@printnum{\expandonce\moodle@tolerance}%
3827 \fi
3828 \fi
3829 \ifx\moodle@fraction\@hundred
3830 $~\checkmark$%
3831 \else
3832 \moodle@checkfraction
3833 $~(\moodle@fraction\%)$%
3834 \fi
3835 \ifx\moodle@feedback\@empty\relax\else
3836 \moodle@preFeedback \emph{$\rightarrow$ \moodle@feedback}%
3837 \fi
3838 }%
3839
3840 % SAVING ANSWERS TO MEMORY
3841 \def\savenumericalanswer#1{%
3842 \bgroup
3843 \savenumericalanswer@int#1\moodle@answer@rdelim
3844 \passvalueaftergroup{\moodle@answers@xml}%
3845 \egroup
3846 }%
3847 \newcommand\savenumericalanswer@int[1][]{%
3848 \setkeys{moodle}{fraction=100,#1}% %%%%%% DEFAULT VALUE IS 100%
3849 \savenumericalanswer@int@int%
3850 }%
3851 \def\savenumericalanswer@int@int#1\moodle@answer@rdelim{%
3852 \def\moodle@answertext{#1}%
3853 \trim@spaces@in\moodle@answertext
3854 \moodle@checkfraction
3855 \addto@xml[2]{\moodle@answers@xml}{<answer fraction="\moodle@fraction" format="plain_text">}%
3856 \addto@xml[4]{\moodle@answers@xml}{ <text>\moodle@answertext</text>}%
3857
3858 \ifx\moodle@answertext\@star\else
3859 \addto@xml[4]{\moodle@answers@xml}{ <tolerance>\moodle@tolerance</tolerance>}%
3860 \fi
3861 \ifmoodle@pluginfile
3862 \writetomoodle[0]{\htmlize@embeddedfiletags}%
3863 \fi
3864 \ifx\moodle@feedback\@empty\relax\else
3865 \trim@spaces@in\moodle@feedback
3866 \xa\converttohtmlmacro\xa\moodle@feedback@html\xa{\moodle@feedback}%
3867 \addto@xml[4]{\moodle@answers@xml}{ <feedback format="html"><text><![CDATA[<p>\moodle@feedback@html</p>]]></text>\ifmoodle@pluginfile\htmlize@embeddedfiletags\fi</feedback>}%
3868 \fi
3869 \addto@xml[2]{\moodle@answers@xml}{</answer>}%
3870 }%
3871
3872
3873 % WRITING QUESTION TO \XML\ FILE
3874 \gdef\writenumericalquestion{%
3875 \writetomoodle{<question type="numerical">}%
3876 \moodle@writecommondata%
3877 }%
3878 % \end{macrocode}
3879 %
3880 % \subsubsection{Multiple Choice Question Front-End}
3881 %
3882 % \begin{macrocode}
3883 %Multiple choice has the structure
3884 % \begin{multi}[options]{name}%
3885 % What is 5+7?
3886 % \item 13
3887 % \item* 12
3888 % \item 11
3889 % \end{multi}%
3890
3891 \moodle@makefrontend{multi}{\moodle@makelatextag@multi}%
3892
3893 % LATEX PROCESSING
3894
3895 \def\moodle@makelatextag@multi{%
3896 \ifmoodle@allornothing
3897 \ifx\endmulti\endclozemulti
3898 \PackageError{moodle}{Unsupported option "allornothing" for a multichoice subquestion}
3899 {Please set "allornothing=false"}%
3900 \else
3901 \moodle@makelatextag@other{All-or-nothing}%
3902 \fi
3903 \else
3904 \ifmoodle@single
3905 \moodle@makelatextag@other{Single}%
3906 \else
3907 \moodle@makelatextag@other{Multiple}%
3908 \fi
3909 \fi
3910 \ifmoodle@handout\else
3911 \ifmoodle@shuffle
3912 \moodle@makelatextag@other{Shuffle}\relax%
3913 \fi
3914 \fi
3915 }
3916
3917 \def\moodle@multi@latexprocessing{%
3918 \ifmoodle@allornothing\moodle@singletrue\fi
3919 \ifmoodle@single\relax\else\moodle@InspectMultipleAnswers\fi
3920 \ifmoodle@handout\NewList{answerlist}\fi
3921 \begin{enumerate}\moodle@obeynumberingstyle%
3922 %\renewcommand{\theenumi}{\alph{enumi}}%
3923 \setlength\itemsep{0pt}\setlength\parskip{0pt}%
3924 \loopthroughitemswithcommand{\moodle@print@multichoice@answer}%
3925 \ifmoodle@handout
3926 \ifmoodle@shuffle
3927 \let\moodle@multi@loop=\ForEachRandomItem
3928 \else
3929 \let\moodle@multi@loop=\ForEachFirstItem
3930 \fi
3931 \moodle@multi@loop{answerlist}{Answer}{\Answer}%
3932 \fi
3933 \end{enumerate}%
3934 \ifmoodle@handout\else
3935 \ifx\moodle@generalfeedback\@empty\relax\else%
3936 \fbox{\parbox{.96\linewidth}{\emph{\moodle@generalfeedback}}}%
3937 \fi
3938 \fi
3939 }
3940 \long\def\moodle@print@multichoice@answer#1{%
3941 \let\moodle@feedback=\@empty%
3942 \moodle@print@multichoice@answer@int#1 \@rdelim%
3943 }%
3944 \newcommand\moodle@print@multichoice@answer@int[1][]{%
3945 \let\moodle@fraction\@empty%
3946 \setkeys{moodle}{#1}%
3947 \moodle@print@multichoice@answer@int@int%
3948 }%
3949 \long\def\moodle@print@multichoice@answer@int@int#1#2\@rdelim{%
3950 \def\test@i{#1}%
3951 \def\test@ii{#2}%
3952 \def\moodle@answertext{\item }%
3953 \ifx\test@i\@star%
3954 \g@addto@macro\moodle@answertext{#2}%
3955 \ifmoodle@single%
3956 \setkeys{moodle}{fraction=100}%
3957 \else
3958 \setkeys{moodle}{fraction=\moodle@AutoScore}%
3959 \fi
3960 \else
3961 \g@addto@macro\moodle@answertext{#1#2}%
3962 \fi
3963 \trim@spaces@in\moodle@answertext%
3964 \trim@spaces@in\moodle@answertext%
3965 \ifmoodle@handout\else
3966 \ifmoodle@single%
3967 \ifx\moodle@fraction\@empty\relax%
3968 \ifdim0pt<\moodle@sanction pt\relax
3969 \setkeys{moodle}{fraction=-\moodle@sanction}%
3970 \else
3971 \setkeys{moodle}{fraction=0}%
3972 \fi
3973 \fi
3974 \moodle@checkfraction
3975 \ifx\moodle@fraction\@hundred%
3976 \trim@spaces@in\moodle@answertext%
3977 \g@addto@macro\moodle@answertext{$~\checkmark$}%
3978 \else
3979 \ifdim0pt=\moodle@fraction pt\relax\else%
3980 \g@addto@macro\moodle@answertext{$~(\moodle@fraction\%)$}%
3981 \fi
3982 \fi
3983 \else% multiple
3984 \ifx\moodle@fraction\@empty\relax%
3985 \ifmoodle@AdvancedScoreMode
3986 \setkeys{moodle}{fraction=0}%
3987 \else
3988 \setkeys{moodle}{fraction=-\moodle@AutoScore}%
3989 \fi
3990 \fi
3991 \moodle@checkfraction
3992 \g@addto@macro\moodle@answertext{$~(\moodle@fraction\%)$}%
3993 \fi
3994 \fi
3995 \ifmoodle@handout
3996 \def\temp{\InsertLastItem{answerlist}}%
3997 \xa\temp\xa{\moodle@answertext}%
3998 \else
3999 \ifx\moodle@feedback\@empty\relax\else%
4000 \g@addto@macro\moodle@answertext{\moodle@preFeedback \emph{$\rightarrow$ \moodle@feedback}}%
4001 \fi
4002 \moodle@answertext
4003 \fi
4004 }%
4005
4006 % COMMON UTILITY: Inspecting answers of multiple choice questions (for option 'multiple')
4007 \newcounter{moodle@NumStarredAnswers}% count the stars
4008 \newdimen\moodle@autoscore@tmp%
4009 \newdimen\moodle@TotalPositiveFractions% Total of user-set positive fractions
4010 \newdimen\moodle@PositiveScoreFactor% scaling factor to impose the fractions of
4011 %correct answers to add up to 100%
4012 \newif\ifmoodle@AdvancedScoreMode%
4013
4014 \def\moodle@InspectMultipleAnswers{%
4015 \setcounter{moodle@NumStarredAnswers}{0}%
4016 \moodle@autoscore@tmp=100pt\relax% temporary variable
4017 \moodle@TotalPositiveFractions=0pt\relax%
4018 \moodle@PositiveScoreFactor=1pt\relax
4019 \moodle@AdvancedScoreModefalse
4020 \loopthroughitemswithcommand{\moodle@InspectMultipleAnswers@a}%
4021 \ifmoodle@AdvancedScoreMode% advanced mode
4022 \ifx\endmulti\endclozemulti% inside cloze
4023 \divide\moodle@TotalPositiveFractions by 100\relax
4024 \advance\moodle@TotalPositiveFractions by \c@moodle@NumStarredAnswers pt\relax
4025 \moodle@PositiveScoreFactor=1 pt\relax
4026 \moodle@PositiveScoreFactor=\dimexpr 1 pt * \moodle@PositiveScoreFactor / \moodle@TotalPositiveFractions\relax%
4027 \global\def\moodle@OtherScore{% for multianswer questions in cloze, with advanced mode
4028 \ifdim0pt<\moodle@fraction pt\relax
4029 \moodle@fraction
4030 \else
4031 \moodle@autoscore@tmp=\moodle@PositiveScoreFactor\relax%
4032 \multiply\moodle@autoscore@tmp by \moodle@fraction\relax%
4033 \strip@pt\moodle@autoscore@tmp
4034 \fi
4035 }%
4036 \else% outside cloze
4037 \advance\moodle@autoscore@tmp by-\moodle@TotalPositiveFractions\relax%
4038 \def\ds{\strip@pt\moodle@TotalPositiveFractions}%
4039 \ifnum0=\c@moodle@NumStarredAnswers\relax%
4040 % autopoints will never be used but we check if the sum of positive fractions is 100%
4041 \ifdim\moodle@autoscore@tmp<-\moodle@fractiontol pt\relax%
4042 \PackageWarning{moodle}{Positive fractions add up to more than 100 (here: \ds)}%
4043 % Here we issue only a warning because Moodle accepts the \XML\ without error.
4044 \else
4045 \ifdim\moodle@autoscore@tmp>\moodle@fractiontol pt\relax%
4046 \PackageError{moodle}{Positive fractions add up to less than 100 (here: \ds)}%
4047 \fi
4048 \fi
4049 \else% there are starred items
4050 \ifdim0pt<\moodle@autoscore@tmp\relax\else%
4051 % we have starred items so the sum of user-set positive fractions must be less than 100%
4052 % otherwise, starred items would lead to penalties
4053 \PackageError{moodle}{Positive fractions add up to 100 or more (here: \ds):
4054 there is no positive points left to be given to starred items.}%
4055 \fi
4056 \divide\moodle@autoscore@tmp by \c@moodle@NumStarredAnswers\relax%
4057 \fi
4058 \fi
4059 \else% automatic score (not in advanced score mode)
4060 \global\divide\moodle@autoscore@tmp by \c@moodle@NumStarredAnswers\relax%
4061 \fi
4062 \xdef\moodle@AutoScore{\strip@pt\moodle@autoscore@tmp}%
4063 }
4064 \long\def\moodle@InspectMultipleAnswers@a#1{%
4065 %The grouping is to keep key answer-specific key changes local.
4066 \bgroup
4067 \moodle@InspectMultipleAnswers@b#1\moodle@answer@rdelim
4068 \egroup
4069 }%
4070 \newcommand\moodle@InspectMultipleAnswers@b[1][]{%
4071 %\ifx&#1&%
4072 \let\moodle@fraction\@empty%
4073 \setkeys{moodle}{#1}%
4074 \moodle@InspectMultipleAnswers@c%
4075 %\fi
4076 }%
4077 \long\def\moodle@InspectMultipleAnswers@c#1#2\moodle@answer@rdelim{%
4078 \def\test@i{#1}%
4079 \ifx\test@i\@star
4080 \stepcounter{moodle@NumStarredAnswers}%
4081 \else
4082 \ifx\moodle@fraction\@empty\else
4083 \global\moodle@AdvancedScoreModetrue
4084 \ifdim0pt<\moodle@fraction pt\relax%
4085 \global\advance\moodle@TotalPositiveFractions by \moodle@fraction pt\relax%
4086 \fi
4087 \fi
4088 \fi
4089 }%
4090 \newdimen\test@fraction%
4091 \newdimen\test@lower%
4092 \newdimen\test@upper%
4093 \def\moodle@fractionerror{%
4094 \def\ds{\moodle@fraction}%
4095 \PackageError{moodle}{the current fraction is not an admissible value (here: \ds)}%
4096 }
4097 {\catcode`|=3\relax
4098 \gdef\moodle@validfractionlist{0|5|10|11.11111|12.5|14.28571|16.66667|20|25|30|33.33333|40|50|60|66.66667|70|75|80|83.33333|90|100}}%
4099 \def\moodle@isfractionnear#1{%
4100 \test@lower=\dimexpr #1 pt - \moodle@fractiontol pt\relax%
4101 \test@upper=\dimexpr #1 pt + \moodle@fractiontol pt\relax%
4102 \ifdim\test@upper>\test@fraction\relax
4103 \ifdim\test@lower<\test@fraction\relax
4104 \gdef\test@fractionmatched{#1}%
4105 \fi
4106 \fi
4107 }
4108 \def\moodle@checkfraction{%
4109 \ifmoodle@allornothing
4110 \ifnum\moodle@fraction>0\relax
4111 \setkeys{moodle}{fraction=100}%
4112 \fi
4113 \ifnum\moodle@fraction<0\relax
4114 \setkeys{moodle}{fraction=0}%
4115 \fi
4116 \else
4117 %\def\test@i{#1}%
4118 \test@fraction=\moodle@fraction pt\relax%
4119 % take the absolute value
4120 \ifdim0pt>\test@fraction\relax%
4121 \test@fraction=-\moodle@fraction pt\relax%
4122 \fi
4123 % test if the fraction is an admissible value
4124 \let\test@fractionmatched\@empty
4125 \forlistloop{\moodle@isfractionnear}{\moodle@validfractionlist}%
4126 \ifx\test@fractionmatched\@empty\relax
4127 \moodle@fractionerror%
4128 \fi
4129 \ifdim\moodle@fraction pt<-\moodle@fractiontol pt\relax%
4130 \xdef\moodle@fraction{-\test@fractionmatched}%
4131 \else
4132 \xdef\moodle@fraction{\test@fractionmatched}%
4133 \fi
4134 \fi
4135 }
4136 % TODO: Put these macros in same order as other sections'.
4137
4138 % SAVING ANSWERS TO MEMORY
4139 \long\def\savemultianswer#1{%
4140 \bgroup
4141 \savemultianswer@int#1 \moodle@answer@rdelim
4142 \passvalueaftergroup{\moodle@answers@xml}%
4143 \egroup
4144 }%
4145 \newcommand\savemultianswer@int[1][]{%
4146 \let\moodle@fraction\@empty%
4147 \setkeys{moodle}{#1}%
4148 \ifmoodle@allornothing
4149 \moodle@singletrue
4150 \fi
4151 \savemultianswer@int@int%
4152 }%
4153 \long\def\savemultianswer@int@int#1#2\moodle@answer@rdelim{%
4154 \def\test@i{#1}%
4155 \ifx\test@i\@star
4156 \ifmoodle@single
4157 \setkeys{moodle}{fraction=100}%
4158 \else
4159 \setkeys{moodle}{fraction=\moodle@AutoScore}%
4160 \fi
4161 \def\moodle@answertext{#2}%
4162 \else
4163 \def\moodle@answertext{#1#2}%
4164 \fi
4165 \ifx\moodle@fraction\@empty\relax%
4166 \ifmoodle@single\relax
4167 \ifdim0pt<\moodle@sanction pt\relax
4168 \setkeys{moodle}{fraction=-\moodle@sanction}%
4169 \else
4170 \setkeys{moodle}{fraction=0}%
4171 \fi
4172 \else% multiple
4173 \ifmoodle@AdvancedScoreMode
4174 \setkeys{moodle}{fraction=0}%
4175 \else
4176 \setkeys{moodle}{fraction=-\moodle@AutoScore}%
4177 \fi
4178 \fi
4179 \fi
4180 \trim@spaces@in\moodle@answertext
4181 \trim@spaces@in\moodle@answertext
4182 \moodle@checkfraction
4183 \addto@xml[2]{\moodle@answers@xml}{<answer fraction="\moodle@fraction" format="html">}%
4184 \xa\converttohtmlmacro\xa\moodle@answertext@html\xa{\moodle@answertext}%
4185 \addto@xml[4]{\moodle@answers@xml}{ <text><![CDATA[<p>\moodle@answertext@html</p>]]></text>}%
4186 \ifmoodle@pluginfile
4187 \addto@xml[4]{\moodle@answers@xml}{\htmlize@embeddedfiletags}%
4188 \fi
4189 \ifx\moodle@feedback\@empty\relax\else
4190 \trim@spaces@in\moodle@feedback
4191 \xa\converttohtmlmacro\xa\moodle@feedback@html\xa{\moodle@feedback}%
4192 \addto@xml[4]{\moodle@answers@xml}{ <feedback format="html"><text><![CDATA[<p>\moodle@feedback@html</p>]]></text>\ifmoodle@pluginfile\htmlize@embeddedfiletags\fi</feedback>}%
4193 \fi
4194 \addto@xml[2]{\moodle@answers@xml}{</answer>}%
4195 }%
4196
4197 % WRITING QUESTION TO \XML\ FILE
4198 \gdef\writemultiquestion{%
4199 \writetomoodle{<question type="multichoice\ifmoodle@allornothing set\fi">}%
4200 \moodle@writecommondata%
4201 \ifmoodle@allornothing\else
4202 \moodle@writesingle%
4203 \fi
4204 \moodle@writeshuffle%
4205 \moodle@writeanswernumbering%
4206 }%
4207 % \end{macrocode}
4208 %
4209 % \subsubsection{True/False Question Front-End}
4210 %
4211 % \begin{macrocode}
4212 % True/False has structure
4213 % \begin{truefalse}[options]{name}%
4214 % This is a matching question.
4215 % \item[feedback={feedback for student answering incorrectly "true"}] % first item is for true
4216 % \item* this is an other way of specifying answer-specific feedback
4217 % \end{truefalse}%
4218
4219 %\moodle@makefrontend{truefalse}{}% We dont use the generic frontend because truefalse has no tunable penalty
4220
4221 \NewEnviron{truefalse}[2][]{%
4222 \bgroup
4223 \setkeys{moodle}{#1,questionname={#2}}%
4224 \global\advance\moodle@totalmarks by \csname moodle@default grade\endcsname pt
4225 \expandafter\gatheritems\xa{\BODY}%
4226 \let\moodle@questionheader=\gatheredheader
4227 %First, the LaTeX processing
4228 \item \moodle@begin@samepage\textbf{\moodle@questionname}
4229 \ifmoodle@handout
4230 \moodle@makelatextag@qtype{truefalse}
4231 \else
4232 \moodle@latex@writetags
4233 \par
4234 \noindent
4235 \moodle@makelatextag@qtype{truefalse}
4236 \moodle@makelatextag@value{default grade}{marked out of}
4237 \fi
4238 \par
4239 \noindent
4240 \moodle@questionheader
4241 \edef\moodle@generalfeedback{\expandonce\moodle@feedback}
4242 \moodle@truefalse@latexprocessing
4243 \moodle@end@samepage
4244 %Now, writing information to XML
4245 \@moodle@ifgeneratexml{%
4246 \setkeys{moodle}{penalty=1}%
4247 \xa\questiontext\xa{\moodle@questionheader}% Save the question text.
4248 \csname writetruefalsequestion\endcsname
4249 \bgroup
4250 \gdef\moodle@answers@xml{}%
4251 \setkeys{moodle}{feedback={}}%
4252 \xa\loopthroughitemswithcommand\xa{\xa\savetruefalseanswer}%
4253 \ifnum\c@numgathereditems=1\relax
4254 \setcounter{currentitemnumber}{2}%
4255 \savetruefalseanswer{}
4256 \fi
4257 \passvalueaftergroup{\moodle@answers@xml}%
4258 \egroup
4259 \moodle@writeanswers%
4260 \moodle@writetags%
4261 \writetomoodle{</question>}%
4262 }{}%
4263 \egroup
4264 }%
4265
4266 % LATEX PROCESSING
4267
4268 \def\moodle@truefalse@latexprocessing{%
4269 % \ifnum\c@numgathereditems>2\relax%
4270 % \PackageError{moodle}{Expecting at max two answers with truefalse type}
4271 % \fi
4272 \setcounter{moodle@NumStarredAnswers}{0}%
4273 \begin{itemize} \setlength\itemsep{0pt}\setlength\parskip{0pt}%
4274 \loopthroughitemswithcommand{\moodle@print@truefalse@answer}%
4275 \ifnum\c@currentitemnumber=2\relax
4276 \item \textbf{\GetTranslation{False}}%
4277 \fi
4278 \end{itemize}
4279 \ifmoodle@handout\else
4280 \ifx\moodle@generalfeedback\@empty\relax\else%
4281 \fbox{\parbox{.96\linewidth}{\emph{\moodle@generalfeedback}}}%
4282 \fi
4283 \fi
4284 \ifnum\c@moodle@NumStarredAnswers=0\relax
4285 \PackageError{moodle}{No answer is explicitly marked as correct (*). Be sure one answer leads to points.}%
4286 \fi
4287 \ifnum\c@moodle@NumStarredAnswers>1\relax
4288 \PackageError{moodle}{Two answers are explicitly marked as correct (*). Be sure only one answer leads to points.}%
4289 \fi
4290 }
4291
4292 \def\moodle@print@truefalse@answer#1{% here # is all what comes after "\item", that is "[options]* text"
4293 \let\moodle@feedback=\@empty
4294 \moodle@print@truefalse@answer@int#1\@rdelim % add an end delimiter:
4295 }%
4296 \newcommand\moodle@print@truefalse@answer@int[1][]{% with the optional argument, catch options and set them as keys
4297 \setkeys{moodle}{#1}%
4298 \moodle@print@truefalse@answer@int@int% applies to the rest: "* text\@rdelim"
4299 }%
4300 \def\moodle@print@truefalse@answer@int@int#1\@rdelim{% this is just to treat appart the case where nothing follows
4301 \def\test@i{#1}
4302 \trim@spaces@in\test@i
4303 \ifx\test@i\@empty\relax
4304 \moodle@print@truefalse@answer@int@int@empty
4305 \else
4306 \moodle@print@truefalse@answer@int@int@int#1\@rdelim
4307 \fi
4308 }%
4309 \def\moodle@print@truefalse@answer@int@int@empty{%
4310 \ifnum\c@currentitemnumber=1\relax
4311 \def\moodle@answertext{\GetTranslation{True}}%
4312 \fi
4313 \ifnum\c@currentitemnumber=2\relax
4314 \def\moodle@answertext{\GetTranslation{False}}%
4315 \fi
4316 \item \textbf{\moodle@answertext}%
4317 \ifmoodle@handout\else
4318 \ifx\moodle@feedback\@empty\relax\else
4319 ~\moodle@preFeedback \emph{$\rightarrow$ \moodle@feedback}%
4320 \fi
4321 \fi
4322 }%
4323 \def\moodle@print@truefalse@answer@int@int@int#1#2\@rdelim{%
4324 \ifnum\c@currentitemnumber=1\relax
4325 \def\moodle@answertext{\GetTranslation{True}}%
4326 \fi
4327 \ifnum\c@currentitemnumber=2\relax
4328 \def\moodle@answertext{\GetTranslation{False}}%
4329 \fi
4330 \item \textbf{\moodle@answertext}%
4331 \ifnum\c@currentitemnumber<3\relax
4332 \def\test@i{#1}%
4333 %\trim@spaces@in\test@i
4334 \ifx\test@i\@star
4335 \ifmoodle@handout\else
4336 ~$\checkmark$%
4337 \fi
4338 \stepcounter{moodle@NumStarredAnswers}%
4339 \else
4340 ~%
4341 \fi
4342 \ifmoodle@handout\else
4343 \ifx\moodle@feedback\@empty\relax
4344 \def\test@ii{#2}%
4345 \trim@spaces@in\test@ii
4346 \ifx\test@ii\@empty\relax\else
4347 \ifx\test@i\@star%
4348 \moodle@preFeedback \emph{$\rightarrow$ #2}%
4349 \else%
4350 \moodle@preFeedback \emph{$\rightarrow$ #1#2}%
4351 \fi
4352 \fi
4353 \else
4354 \moodle@preFeedback \emph{$\rightarrow$ \moodle@feedback}%
4355 \fi
4356 \fi
4357 \fi
4358 }%
4359
4360 % SAVING ANSWERS TO MEMORY
4361 \def\savetruefalseanswer#1{%
4362 \bgroup
4363 \savetruefalseanswer@int#1\moodle@answer@rdelim
4364 \passvalueaftergroup{\moodle@answers@xml}%
4365 \egroup
4366 }%
4367 \newcommand\savetruefalseanswer@int[1][]{%
4368 \setkeys{moodle}{#1}%
4369 \savetruefalseanswer@int@int%
4370 }%
4371 \def\savetruefalseanswer@int@int#1\moodle@answer@rdelim{%
4372 \def\test@i{#1}
4373 \trim@spaces@in\test@i
4374 \ifx\test@i\@empty\relax
4375 \savetruefalseanswer@int@int@empty
4376 \else
4377 \savetruefalseanswer@int@int@int#1\moodle@answer@rdelim
4378 \fi
4379 }%
4380 \def\savetruefalseanswer@int@int@empty{%
4381 \setkeys{moodle}{fraction=0}%
4382 \ifnum\c@currentitemnumber=1\relax
4383 \def\moodle@answertext{true}%
4384 \fi
4385 \ifnum\c@currentitemnumber=2\relax
4386 \def\moodle@answertext{false}%
4387 \fi
4388 \ifnum\c@currentitemnumber<3\relax
4389 \addto@xml[2]{\moodle@answers@xml}{<answer fraction="\moodle@fraction" format="plain_text">}%
4390 \addto@xml[4]{\moodle@answers@xml}{ <text>\moodle@answertext</text>}%
4391 \ifmoodle@pluginfile
4392 \addto@xml[4]{\moodle@answers@xml}{\htmlize@embeddedfiletags}%
4393 \fi
4394 \ifx\moodle@feedback\@empty\relax\else
4395 \trim@spaces@in\moodle@feedback
4396 \xa\converttohtmlmacro\xa\moodle@feedback@html\xa{\moodle@feedback}%
4397 \addto@xml[4]{\moodle@answers@xml}{ <feedback format="html"><text><![CDATA[<p>\moodle@feedback@html</p>]]></text>\ifmoodle@pluginfile\htmlize@embeddedfiletags\fi</feedback>}%
4398 \fi
4399 \addto@xml[2]{\moodle@answers@xml}{</answer>}%
4400 \fi
4401 }%
4402 \def\savetruefalseanswer@int@int@int#1#2\moodle@answer@rdelim{%
4403 \def\test@i{#1}%
4404 \ifx\test@i\@star
4405 \setkeys{moodle}{fraction=100}%
4406 \else
4407 \setkeys{moodle}{fraction=0}%
4408 \fi
4409 \ifnum\c@currentitemnumber=1\relax
4410 \def\moodle@answertext{true}%
4411 \fi
4412 \ifnum\c@currentitemnumber=2\relax
4413 \def\moodle@answertext{false}%
4414 \fi
4415 \ifnum\c@currentitemnumber<3\relax
4416 \addto@xml[2]{\moodle@answers@xml}{<answer fraction="\moodle@fraction" format="plain_text">}%
4417 \addto@xml[4]{\moodle@answers@xml}{ <text>\moodle@answertext</text>}%
4418 \ifmoodle@pluginfile
4419 \addto@xml[4]{\moodle@answers@xml}{\htmlize@embeddedfiletags}%
4420 \fi
4421 \ifx\moodle@feedback\@empty\relax
4422 \def\test@ii{#2}
4423 \ifx\test@ii\@empty\relax\else
4424 \ifx\test@i\@star
4425 \xa\converttohtmlmacro\xa\moodle@feedback@html\xa{#2}%
4426 \else%
4427 \xa\converttohtmlmacro\xa\moodle@feedback@html\xa{#1#2}%
4428 \fi%
4429 \addto@xml[4]{\moodle@answers@xml}{ <feedback format="html"><text><![CDATA[<p>\moodle@feedback@html</p>]]></text>\ifmoodle@pluginfile\htmlize@embeddedfiletags\fi</feedback>}%
4430 \fi
4431 \else
4432 \trim@spaces@in\moodle@feedback
4433 \xa\converttohtmlmacro\xa\moodle@feedback@html\xa{\moodle@feedback}%
4434 \addto@xml[4]{\moodle@answers@xml}{ <feedback format="html"><text><![CDATA[<p>\moodle@feedback@html</p>]]></text>\ifmoodle@pluginfile\htmlize@embeddedfiletags\fi</feedback>}%
4435 \fi
4436 \addto@xml[2]{\moodle@answers@xml}{</answer>}%
4437 \fi
4438 }%
4439
4440 % WRITING QUESTION TO \XML\ FILE
4441 \gdef\writetruefalsequestion{%
4442 \writetomoodle{<question type="truefalse">}%
4443 \moodle@writecommondata%
4444 }%
4445 % \end{macrocode}
4446 %
4447 % \subsubsection{Matching Question Front-End}
4448 %
4449 % \begin{macrocode}
4450 %\let\answer=\hfill
4451
4452 \moodle@makefrontend{matching}{\moodle@makelatextag@matching}%
4453
4454 % LATEX PROCESSING
4455
4456 \def\moodle@makelatextag@matching{%
4457 \ifmoodle@handout\else
4458 \ifmoodle@draganddrop
4459 \moodle@makelatextag@other{Drag and drop}\relax%
4460 \fi
4461 \ifmoodle@shuffle
4462 \moodle@makelatextag@other{Shuffle}\relax%
4463 \fi
4464 \fi
4465 }
4466 \long\def\moodle@matching@left#1{%
4467 \parbox[c]{.9\linewidth}{\raggedleft #1}\hfil\vrule width .5pt$\bullet$%
4468 }%
4469 \long\def\moodle@matching@right#1{%
4470 $\bullet$\vrule width .5pt\hfil\parbox[c]{.9\linewidth}{#1}%
4471 }%
4472 \def\moodle@matching@latexprocessing{%
4473 \bgroup
4474 %\let\answer=\hfill
4475 \par\noindent
4476 \ifmoodle@handout
4477 \NewList{questionlist}%
4478 \gdef\matcheslist{}%
4479 \NewList{answerlist}%
4480 \else
4481 \long\def\matching@table@text{}%
4482 \fi
4483 \setcounter{moodle@NumStarredAnswers}{0}% Here this counter is for "questions" (items on the left column)
4484 \loopthroughitemswithcommand{\moodle@print@matching@answer}%
4485 \ifnum\c@numgathereditems<3\relax
4486 \PackageWarning{moodle}{Moodle expects at least three proposed matches in matching questions}%
4487 \fi
4488 \ifnum\c@moodle@NumStarredAnswers<2\relax
4489 \PackageWarning{moodle}{Moodle expects at least two items in matching questions}%
4490 \fi
4491 \ifmoodle@handout
4492 \ifmoodle@shuffle
4493 \let\moodle@matching@loop=\ForEachRandomItem
4494 \else
4495 \let\moodle@matching@loop=\ForEachFirstItem
4496 \fi
4497 \begin{minipage}{.43\linewidth}%
4498 \moodle@matching@loop{questionlist}{Question}{%
4499 \moodle@matching@left{\Question}%
4500 \vskip 4pt\relax
4501 }%
4502 \end{minipage}%
4503 \hfill
4504 \begin{minipage}{.43\linewidth}%
4505 \ForEachFirstItem{answerlist}{Answer}{%
4506 \moodle@matching@right{\Answer}%
4507 \vskip 4pt\relax
4508 }%
4509 \end{minipage}%
4510 \else
4511 \begin{tabular}{@{}p{.43\linewidth}@{}p{.1\linewidth}@{}p{.43\linewidth}@{}}%
4512 \matching@table@text
4513 \end{tabular}%
4514 \ifx\moodle@generalfeedback\@empty\relax\else%
4515 \fbox{\parbox{.96\linewidth}{\emph{\moodle@generalfeedback}}}%
4516 \fi
4517 \fi
4518 \egroup
4519 }
4520
4521 \long\def\moodle@print@matching@answer#1{%
4522 \moodle@print@matching@answer@int#1 \@rdelim
4523 }%
4524 \newcommand\moodle@print@matching@answer@int[1][]{%
4525 \moodle@print@matching@answer@int@int
4526 }%
4527 \long\def\moodle@print@matching@answer@int@int#1\answer#2\@rdelim{%
4528 %\typeout{\string#1 \answer \string#2}%
4529 \def\test@i{#1}%
4530 \trim@spaces@in\test@i
4531 \ifmoodle@handout
4532 \ifx\test@i\@empty\else
4533 \stepcounter{moodle@NumStarredAnswers}%
4534 \InsertLastItem{questionlist}{#1}%
4535 \fi
4536 \edef\test@ii{\detokenize{#2}}%
4537 \trim@spaces@in\test@ii
4538 \trim@spaces@in\test@ii% don't know why the 2nd call is required
4539 % add proposed match only if not already in the list
4540 \xifinlist{\expandonce\test@ii}{\matcheslist}{}{%
4541 \listeadd\matcheslist{\expandonce\test@ii}%
4542 % matches are always proposed shuffled
4543 \InsertRandomItem{answerlist}{#2}%
4544 }%
4545 \else
4546 \ifx\test@i\@empty
4547 \xa\g@addto@macro\xa\matching@table@text\xa{%
4548 &&\moodle@matching@right{#2}\\\\\relax%
4549 }%
4550 \else
4551 \stepcounter{moodle@NumStarredAnswers}%
4552 \xa\g@addto@macro\xa\matching@table@text\xa{%
4553 \moodle@matching@left{#1}&\leavevmode\leaders\hb@[email protected]{\hss$\cdot$\hss}\hfill\kern\z@%
4554 &\moodle@matching@right{#2}\\\\\relax
4555 }%
4556 \fi
4557 \fi
4558 }%
4559
4560
4561 % SAVING ANSWERS TO MEMORY
4562 \long\def\savematchinganswer#1{%
4563 \bgroup
4564 \savematchinganswer@int#1 \moodle@answer@rdelim%
4565 \passvalueaftergroup{\moodle@answers@xml}%
4566 \egroup
4567 }%
4568 \newcommand\savematchinganswer@int[1][]{%
4569 \setkeys{moodle}{#1}%
4570 \savematchinganswer@int@int%\space
4571 }%
4572 \long\def\savematchinganswer@int@int#1\answer#2\moodle@answer@rdelim{%
4573 %\typeout{\string#1 \answer \string#2}%
4574 % Note that #1 may simply be \relax.
4575 \def\moodle@subquestiontext{#1}%
4576 \def\moodle@subanswertext{#2}%
4577 \trim@spaces@in\moodle@subquestiontext
4578 \xa\converttohtmlmacro\xa\moodle@subquestiontext@htmlized\xa{\moodle@subquestiontext}%
4579 \addto@xml[2]{\moodle@answers@xml}{<subquestion format="html">}%
4580 \ifx\moodle@subquestiontext\@empty
4581 \addto@xml[4]{\moodle@answers@xml}{ <text></text>}%
4582 \else
4583 \addto@xml[4]{\moodle@answers@xml}{ <text><![CDATA[<p>\moodle@subquestiontext@htmlized</p>]]></text>\ifmoodle@pluginfile\htmlize@embeddedfiletags\fi}%
4584 \fi
4585 \trim@spaces@in\moodle@subanswertext
4586 \trim@spaces@in\moodle@subanswertext% don't know why but a second call seems required...
4587 %\ifmoodle@draganddrop
4588 \xa\converttohtmlmacro\xa\moodle@subanswertext@htmlized\xa{\moodle@subanswertext}%
4589 %\fi
4590 \ifmoodle@draganddrop
4591 % \show\moodle@subanswertext@htmlized
4592 \addto@xml[4]{\moodle@answers@xml}{ <answer format="html"><text><![CDATA[<p>\moodle@subanswertext@htmlized</p>]]></text>\ifmoodle@pluginfile\htmlize@embeddedfiletags\fi</answer>}%
4593 \else
4594 % \show\moodle@subanswertext@htmlized
4595 \addto@xml[4]{\moodle@answers@xml}{ <answer format="html"><text><![CDATA[\moodle@subanswertext@htmlized]]></text></answer>}%
4596 \fi
4597 % \ifx\moodle@feedback\@empty\relax\else
4598 % \trim@spaces@in\moodle@feedback
4599 % \xa\converttohtmlmacro\xa\moodle@feedback@html\xa{\moodle@feedback}%
4600 % \addto@xml[4]{\moodle@answers@xml}{ <feedback
4601 %format="html"><text><![CDATA[<p>\moodle@feedback@html</p>]]></text></feedback>}%
4602 % \fi
4603 \addto@xml[2]{\moodle@answers@xml}{</subquestion>}%
4604 }%
4605
4606 % WRITING QUESTION TO \XML\ FILE
4607 \gdef\writematchingquestion{%
4608 \ifmoodle@draganddrop
4609 \writetomoodle{<question type="ddmatch">}%
4610 \else
4611 \writetomoodle{<question type="matching">}%
4612 \fi
4613 \moodle@writecommondata%
4614 % \moodle@writesingle% %irrelevant for the matching type
4615 \moodle@writeshuffle%
4616 % \moodle@writeanswernumbering% %irrelevant for the matching type
4617 }%
4618 % \end{macrocode}
4619 %
4620 % \subsection{Cloze Questions}
4621 % Because cloze questions are so complicated, they get their own section of code.
4622 % The cloze strategy is as follows.
4623 %
4624 % All subquestions show up as part of the question body text.
4625 % For each type of subquestion, we have a cloze-version environment
4626 % that actually has 2 versions, depending on whether we are doing LaTeX or \XML\ processing.
4627 % So the main environment is quite typical:
4628 % \begin{enumerate}
4629 % \item Process the body as LaTeX.
4630 % During this run, a |\begin{multi}| etc.~will be processed for display onscreen.
4631 % \item Then save the body as the questiontext for \XML.
4632 % During this run, a |\begin{multi}| etc.~will be parsed and turned into
4633 % cloze code as part of the \XML\ questiontext.
4634 % \end{enumerate}
4635 % \begin{macrocode}
4636 % LATEX PROCESSING
4637 % SAVING ANSWERS TO MEMORY
4638
4639 \newif\ifmoodle@clozemode
4640 \moodle@clozemodefalse
4641 \NewEnviron{cloze}[2][]{%
4642 \bgroup
4643 \setkeys{moodle}{default grade=1}%
4644 \setkeys{moodle}{#1,questionname={#2}}%
4645 % A cloze question won't have any \item's in it, so we just use \BODY.
4646 \moodle@enableclozeenvironments
4647 %First, the LaTeX processing.
4648 \item \moodle@begin@samepage\textbf{\moodle@questionname}
4649 \ifmoodle@handout
4650 \moodle@makelatextag@qtype{cloze}
4651 \else
4652 \moodle@latex@writetags
4653 \par
4654 \noindent
4655 \moodle@makelatextag@qtype{cloze}
4656 \moodle@makelatextag@value{penalty}{penalty}
4657 \fi
4658 \par
4659 \noindent
4660 \BODY
4661 \edef\moodle@generalfeedback{\expandonce\moodle@feedback}
4662 %\csname moodle@cloze@latexprocessing\endcsname
4663 \ifmoodle@handout\else
4664 \ifx\moodle@generalfeedback\@empty\relax\else%
4665 \fbox{\parbox{.96\linewidth}{\emph{\moodle@generalfeedback}}}%
4666 \fi
4667 \fi
4668 \moodle@end@samepage
4669 %Now, writing information to memory.
4670 \@moodle@ifgeneratexml{%
4671 \xa\questiontext\xa{\BODY}% Save the question text as \HTML.
4672 \writeclozequestion
4673 }{}%
4674 \egroup%
4675 }
4676
4677 \def\moodle@enableclozeenvironments{%
4678 \let\multi=\clozemulti
4679 \let\endmulti=\endclozemulti
4680 \let\numerical=\clozenumerical
4681 \let\endnumerical=\endclozenumerical
4682 \let\shortanswer=\clozeshortanswer
4683 \let\endshortanswer=\endclozeshortanswer
4684 }
4685
4686 % WRITING QUESTION TO \XML\ FILE
4687 \gdef\writeclozequestion{%
4688 \writetomoodle{<question type="cloze">}%
4689 \moodle@writequestionname%
4690 \moodle@writequestiontext%
4691 \moodle@writegeneralfeedback%
4692 \moodle@writepenalty%
4693 \moodle@writehidden%
4694 \moodle@writetags%
4695 \writetomoodle{</question>}%
4696 }%
4697 % \end{macrocode}
4698 %
4699 % Utility to check the validity of fractions and points inside cloze subquestions.
4700 % \begin{macrocode}
4701 \newdimen\moodle@tmpdim
4702 \def\moodle@checkclozefraction{%
4703 \moodle@tmpdim=\moodle@fraction pt\relax
4704 % Rounding is performed in three steps:
4705 % 1) round(x)=floor(x+1/2)
4706 \advance\moodle@tmpdim by .5pt\relax
4707 % 2) floor(x)=trunc(x) if x>0, and floor(x)=trunc(x-1) if x<0
4708 \ifdim\moodle@tmpdim<0pt\relax\advance\moodle@tmpdim by -1pt\fi
4709 % 3) Truncation because the quantum of TeX dimensions is 1/65536-th of a point.
4710 \divide\moodle@tmpdim by 65536\relax\multiply\moodle@tmpdim by 65536\relax
4711 \def\moodle@tmpval{\strip@pt\moodle@tmpdim}%
4712 \ifdim\moodle@tmpdim=\moodle@fraction pt\else
4713 \PackageWarning{moodle}{in cloze questions, fractions must be integers. Rounding \moodle@fraction\space to \moodle@tmpval}%
4714 \fi
4715 \xdef\moodle@fraction{\moodle@tmpval}% in any case, take eventual decimals out (e.g. change 10.0 for 10)
4716 }%
4717
4718 \def\moodle@checkclozegrade{%
4719 \moodle@tmpdim=\csname moodle@default grade\endcsname pt\relax
4720 \ifdim\moodle@tmpdim<1 pt\relax
4721 \PackageWarning{moodle}{for cloze questions, the default grade must be a positive integer. Changing the default grade from \csname moodle@default grade\endcsname\space to 1}%
4722 \csdef{moodle@default grade}{1}%
4723 \else % Rounding is performed in three steps:
4724 % 1) round(x)=floor(x+1/2)
4725 \advance\moodle@tmpdim by .5pt\relax
4726 % 2) floor(x)=trunc(x) if x>0, and floor(x)=trunc(x-1) if x<0
4727 \ifdim\moodle@tmpdim<0pt\relax\advance\moodle@tmpdim by -1pt\fi
4728 % 3) Truncation because the quantum of TeX dimensions is 1/65536-th of a point.
4729 \divide\moodle@tmpdim by 65536\relax\multiply\moodle@tmpdim by 65536\relax
4730 \def\moodle@tmpval{\strip@pt\moodle@tmpdim}%
4731 \ifdim\moodle@tmpdim=\csname moodle@default grade\endcsname pt\else
4732 \PackageWarning{moodle}{for cloze questions, the default grade must be a positive integer. Rounding \csname moodle@default grade\endcsname\space to \moodle@tmpval}%
4733 \fi
4734 \csedef{moodle@default grade}{\moodle@tmpval}% in any case, take eventual decimals out (e.g. change 10.0 for 10)
4735 \fi
4736 }%
4737 % \end{macrocode}
4738 %
4739 % \subsubsection{Cloze Multiple Choice Questions}
4740 %
4741 % \begin{macrocode}
4742 \NewEnviron{clozemulti}[1][]{%
4743 \bgroup
4744 \setkeys{moodle}{#1}%
4745 \moodle@checkclozegrade
4746 \expandafter\gatheritems\xa{\BODY}%
4747 \let\moodle@questionheader=\gatheredheader
4748 \ifhtmlizer@active
4749 %HTML version
4750 \def\moodle@clozemulti@output{}%
4751 \xa\g@addto@macro\xa\moodle@clozemulti@output\xa{\moodle@questionheader}%
4752 \def\clozemulti@coding{}%
4753 \edef\clozemulti@coding{\csname moodle@default grade\endcsname:}%
4754 \ifmoodle@single
4755 \g@addto@macro{\clozemulti@coding}{MULTICHOICE}%
4756 \else
4757 \moodle@WarningOrError{3}{5}{Cloze Multiresponse}%
4758 \g@addto@macro{\clozemulti@coding}{MULTIRESPONSE}%
4759 \fi
4760 \ifcase\moodle@multi@mode\relax
4761 % Case 0: dropdown box style
4762 \ifmoodle@single\else
4763 \PackageError{moodle}{Inline mode (dropdown box) incompatible with multiresponse.}
4764 \fi
4765 \ifmoodle@shuffle
4766 \g@addto@macro{\clozemulti@coding}{_}%
4767 \fi
4768 \or
4769 % Case 1: vertical style
4770 \ifmoodle@single
4771 \g@addto@macro{\clozemulti@coding}{_V}%
4772 \else
4773 \ifmoodle@shuffle
4774 \g@addto@macro{\clozemulti@coding}{_}%
4775 \fi
4776 \fi
4777 \else
4778 % Case 2: horizontal radio buttons
4779 \g@addto@macro{\clozemulti@coding}{_H}%
4780 \fi
4781 \ifmoodle@shuffle
4782 \moodle@WarningOrError{3}{0}{Cloze Multi Shuffling}
4783 \g@addto@macro{\clozemulti@coding}{S:}%
4784 \else
4785 \g@addto@macro{\clozemulti@coding}{:}%
4786 \fi
4787 \bgroup
4788 \setkeys{moodle}{feedback={}}%
4789 \loopthroughitemswithcommand{\saveclozemultichoiceanswer}%
4790 \egroup
4791 %\xa\g@addto@macro\xa\clozemulti@coding\xa{\clozerbrace}%
4792 \xa\g@addto@macro\xa\moodle@clozemulti@output\xa{\xa\clozelbrace\clozemulti@coding\clozerbrace}%
4793 %\show\moodle@clozemulti@output
4794 \xa\gdef\xa\htmlize@afteraction@hook\xa{\moodle@clozemulti@output}%
4795 \def\endclozemulti@code{\htmlize@patchendenvironment}%
4796 \else
4797 %LaTeX version
4798 \global\advance\moodle@totalmarks by \csname moodle@default grade\endcsname pt
4799 \moodle@questionheader% %Any introductory text just continues to be typeset.
4800 \par
4801 \noindent
4802 \moodle@makelatextag@qtype{multi}
4803 \ifmoodle@handout\else
4804 \moodle@makelatextag@value{default grade}{marked out of}
4805 \moodle@makelatextag@multi
4806 \fi
4807 \def\cloze@multichoice@table@text{}%
4808 \ifmoodle@single\relax\else\moodle@InspectMultipleAnswers\fi
4809 \ifmoodle@handout\NewList{answerlist}\fi
4810 %\let\moodle@feedback=\@empty
4811 \loopthroughitemswithcommand{\moodle@print@clozemultichoice@answer}%
4812 \ifmoodle@handout
4813 \ifmoodle@shuffle
4814 \let\moodle@clozemult@loop=\ForEachRandomItem
4815 \else
4816 \let\moodle@clozemult@loop=\ForEachFirstItem
4817 \fi
4818 \moodle@clozemult@loop{answerlist}{Answer}{
4819 \xdef\cloze@multichoice@table@text{\expandonce\cloze@multichoice@table@text\expandonce\Answer}%
4820 }%
4821 \fi
4822 \ifcase\moodle@multi@mode\relax
4823 %Case 0: dropdown box style
4824 \par\noindent
4825 \ifmoodle@handout
4826 \begin{tabular}[t]{|p{.45\linewidth}|}
4827 \else
4828 \begin{tabular}[t]{|p{.45\linewidth}|p{.45\linewidth}|}
4829 % answer & feedback \\\hline\hline
4830 \fi
4831 \firsthline% (\firsthline is from the array package.)
4832 \cloze@multichoice@table@text%
4833 \end{tabular}%
4834 \par%
4835 \or
4836 %Case 1: vertical style
4837 \par\noindent
4838 \begin{itemize}\setlength\itemsep{0pt}\setlength\parskip{0pt}%
4839 \cloze@multichoice@table@text%
4840 \end{itemize}%
4841 \par%
4842 \else
4843 %Case 2: horizontal radio buttons
4844 \par{\cloze@multichoice@table@text}\par%
4845 \fi
4846 \def\endclozemulti@code{\relax}%
4847 \fi
4848 \passvalueaftergroup\endclozemulti@code%
4849 \passvalueaftergroup\htmlize@afteraction@hook%
4850 \egroup%
4851 }[\endclozemulti@code]%
4852
4853 \long\def\moodle@print@clozemultichoice@answer#1{%
4854 %\bgroup
4855 \let\moodle@feedback=\@empty
4856 \moodle@print@clozemultichoice@answer@int#1 \@rdelim%
4857 %\egroup
4858 }%
4859 \newcommand\moodle@print@clozemultichoice@answer@int[1][]{%
4860 \let\moodle@fraction\@empty%
4861 \setkeys{moodle}{#1}%
4862 \moodle@print@clozemultichoice@answer@int@int%
4863 }%
4864 \long\def\moodle@print@clozemultichoice@answer@int@int#1#2\@rdelim{%
4865 \def\moodle@answertext{}%
4866 % Case 0: "(answer) \\ \hline"
4867 % Case 1: "\item (answer)"
4868 % Case 2: "$\bullet~$(answer)\hfill"
4869 \ifcase\moodle@multi@mode\relax
4870 \relax% Case 0
4871 \or
4872 \g@addto@macro\moodle@answertext{\item}% Case 1
4873 \else
4874 \g@addto@macro\moodle@answertext{$\bullet~$}% Case 2
4875 \fi
4876 \def\test@i{#1}%
4877 \ifx\test@i\@star
4878 \setkeys{moodle}{fraction=100}%
4879 \g@addto@macro\moodle@answertext{#2}%
4880 \else
4881 \g@addto@macro\moodle@answertext{#1#2}%
4882 \fi
4883 \trim@spaces@in\moodle@answertext
4884 \trim@spaces@in\moodle@answertext
4885 \ifmoodle@handout\else
4886 \ifmoodle@single%
4887 \ifx\moodle@fraction\@empty\relax%
4888 \ifdim0pt<\moodle@sanction pt\relax
4889 \setkeys{moodle}{fraction=-\moodle@sanction}%
4890 \else
4891 \setkeys{moodle}{fraction=0}%
4892 \fi
4893 \fi
4894 \moodle@checkclozefraction
4895 \ifx\moodle@fraction\@hundred%
4896 \trim@spaces@in\moodle@answertext%
4897 \g@addto@macro\moodle@answertext{$~\checkmark$}%
4898 \else
4899 \ifdim0pt=\moodle@fraction pt\relax\else%
4900 \xdef\moodle@answertext{\expandonce\moodle@answertext$~(\moodle@fraction\%)$}%
4901 \fi
4902 \fi
4903 \else% multiple
4904 \ifx\moodle@fraction\@empty\relax%
4905 \ifmoodle@AdvancedScoreMode
4906 \setkeys{moodle}{fraction=0}%
4907 \else
4908 \setkeys{moodle}{fraction=-\moodle@AutoScore}%
4909 \fi
4910 \else
4911 \ifmoodle@AdvancedScoreMode
4912 \moodle@checkclozefraction
4913 \ifdim0pt<\moodle@fraction pt\relax
4914 \moodle@autoscore@tmp=\moodle@PositiveScoreFactor\relax%
4915 \multiply\moodle@autoscore@tmp by \moodle@fraction\relax%
4916 \xdef\moodle@fraction{\strip@pt\moodle@autoscore@tmp}%
4917 \fi
4918 \else
4919 \setkeys{moodle}{fraction=\moodle@AutoScore}%
4920 \fi
4921 \fi
4922 \xdef\moodle@answertext{\expandonce\moodle@answertext$~(\moodle@fraction\%)$}%
4923 \fi
4924 \fi
4925 \ifcase\moodle@multi@mode\relax
4926 % Case 0
4927 \ifmoodle@handout\else
4928 \xdef\moodle@answertext{\expandonce\moodle@answertext &\expandonce\emph{\expandonce\moodle@feedback}}%
4929 \fi
4930 \g@addto@macro\moodle@answertext{\\\hline}
4931 \or % Case 1
4932 \ifmoodle@handout\else
4933 \ifx\moodle@feedback\@empty\relax\else
4934 \xdef\moodle@answertext{\expandonce\moodle@answertext \moodle@preFeedback \expandonce\emph{$\rightarrow$ \expandonce\moodle@feedback}}%
4935 \fi
4936 \fi
4937 \else % otherwise
4938 \ifmoodle@handout\else
4939 \ifx\moodle@feedback\@empty\relax\else
4940 \xdef\moodle@answertext{\expandonce\moodle@answertext\,\expandonce\emph{$\rightarrow$ \expandonce\moodle@feedback}}%
4941 \fi
4942 \fi
4943 \g@addto@macro\moodle@answertext{\hfill}% Case 2
4944 \fi
4945 \ifmoodle@handout
4946 \def\temp{\InsertLastItem{answerlist}}%
4947 \xa\temp\xa{\moodle@answertext}%
4948 \else
4949 \xdef\cloze@multichoice@table@text{\expandonce\cloze@multichoice@table@text\expandonce\moodle@answertext}%
4950 \fi
4951 }%
4952
4953 \long\def\saveclozemultichoiceanswer#1{%
4954 \bgroup
4955 \saveclozemultichoiceanswer@int#1 \moodle@answer@rdelim
4956 \egroup
4957 }%
4958 \newcommand\saveclozemultichoiceanswer@int[1][]{%
4959 \setkeys{moodle}{fraction=0,#1}%
4960 \saveclozemultichoiceanswer@int@int%
4961 }%
4962 \long\def\saveclozemultichoiceanswer@int@int#1#2\moodle@answer@rdelim{%
4963 \def\test@i{#1}%
4964 \ifgatherbeginningofloop\else
4965 \xa\gdef\xa\clozemulti@coding\xa{\clozemulti@coding\clozetilde}% separator between answers
4966 \fi
4967 \ifx\test@i\@star
4968 \setkeys{moodle}{fraction=100}%
4969 \def\moodle@answertext{#2}%
4970 \else
4971 \def\moodle@answertext{#1#2}%
4972 \fi
4973 \trim@spaces@in\moodle@answertext
4974 \trim@spaces@in\moodle@answertext
4975 \ifx\moodle@fraction\@hundred
4976 \g@addto@macro\clozemulti@coding{\clozecorrect}%
4977 \else
4978 \moodle@checkclozefraction
4979 \ifdim0pt=\moodle@fraction pt\relax\else
4980 \xdef\clozemulti@coding{\expandonce\clozemulti@coding\otherpercent\moodle@fraction\otherpercent}%
4981 \fi
4982 \fi
4983 \xdef\clozemulti@coding{\expandonce\clozemulti@coding\expandonce\moodle@answertext}%
4984 \ifx\moodle@feedback\@empty\else
4985 \xdef\clozemulti@coding{\expandonce\clozemulti@coding\otherbackslash\otherhash\expandonce\moodle@feedback}%
4986 \fi
4987 }%
4988 % \end{macrocode}
4989 %
4990 % \subsubsection{Cloze Numerical Questions}
4991 %
4992 % \begin{macrocode}
4993 \NewEnviron{clozenumerical}[1][]{%
4994 \bgroup
4995 \expandafter\gatheritems\expandafter{\BODY}%
4996 \let\moodle@questionheader=\gatheredheader
4997 \setkeys{moodle}{#1}%
4998 \moodle@checkclozegrade
4999 \ifhtmlizer@active
5000 %HTML version
5001 \def\moodle@clozenumerical@output{}%
5002 \xa\g@addto@macro\xa\moodle@clozenumerical@output\xa{\moodle@questionheader}%
5003 \def\clozenumerical@coding{}%
5004 \edef\clozenumerical@coding{\csname moodle@default grade\endcsname:NUMERICAL:}%
5005 \bgroup
5006 \setkeys{moodle}{feedback={}}%
5007 \loopthroughitemswithcommand{\saveclozenumericalanswer}%
5008 \egroup
5009 %\xa\g@addto@macro\xa\clozenumerical@coding\xa{\otherrbrace}%
5010 \xa\g@addto@macro\xa\moodle@clozenumerical@output\xa{\xa\clozelbrace\clozenumerical@coding\clozerbrace}%
5011 \xa\gdef\xa\htmlize@afteraction@hook\xa{\moodle@clozenumerical@output}%
5012 \def\endclozenumerical@code{\htmlize@patchendenvironment}%
5013 \else
5014 %LaTeX version
5015 \global\advance\moodle@totalmarks by \csname moodle@default grade\endcsname pt
5016 \moodle@questionheader% %Any introductory text just continues to be typeset.
5017 \par
5018 \noindent
5019 \moodle@makelatextag@qtype{numerical}
5020 \ifmoodle@handout\else
5021 \moodle@makelatextag@value{default grade}{marked out of}
5022 \moodle@makelatextag@numerical
5023 \par
5024 \noindent
5025 \def\cloze@numerical@table@text{}%
5026 \loopthroughitemswithcommand{\moodle@print@clozenumerical@answer}%
5027 \begin{tabular}[t]{|p{.45\linewidth}|p{.45\linewidth}|}
5028 \firsthline% (\firsthline is from the array package.)
5029 % answer & feedback \\\hline\hline
5030 \cloze@numerical@table@text%
5031 \end{tabular}%
5032 \par%
5033 \fi
5034 \def\endclozenumerical@code{\relax}%
5035 \fi
5036 \passvalueaftergroup\endclozenumerical@code%
5037 \passvalueaftergroup\htmlize@afteraction@hook%
5038 \egroup
5039 }[\endclozenumerical@code]%
5040
5041 \def\moodle@print@clozenumerical@answer#1{%
5042 \let\moodle@feedback=\@empty
5043 \bgroup
5044 \moodle@print@clozenumerical@answer@int#1\@rdelim
5045 \egroup
5046 }%
5047 \newcommand\moodle@print@clozenumerical@answer@int[1][]{%
5048 \setkeys{moodle}{#1}%
5049 \moodle@print@clozenumerical@answer@int@int%
5050 }%
5051 \def\moodle@zero{0}%
5052 \def\moodle@print@clozenumerical@answer@int@int#1\@rdelim{%
5053 \ifx\moodle@fraction\@hundred
5054 \def\moodle@clozenumericalprint@fraction{$~\checkmark$}%
5055 \else
5056 \moodle@checkclozefraction
5057 \edef\moodle@clozenumericalprint@fraction{$(~\moodle@fraction\%)$}%
5058 \fi
5059 \ifx\moodle@zero\moodle@tolerance%
5060 \def\moodle@clozenumericalprint@tolerance{}%
5061 \else
5062 \edef\moodle@clozenumericalprint@tolerance{$\,\pm\,$\moodle@printnum{\expandonce\moodle@tolerance}}%
5063 \fi
5064 \gdef\test@i{#1}%
5065 \trim@spaces@in\test@i
5066 \ifx\test@i\@star
5067 \xdef\moodle@clozenumericalprint@line{\expandonce\test@i~\moodle@clozenumericalprint@fraction & \expandonce\emph{\expandonce\moodle@feedback}}%
5068 \else
5069 \xdef\moodle@clozenumericalprint@line{\moodle@printnum{\expandonce\test@i}\expandonce\moodle@clozenumericalprint@tolerance~\moodle@clozenumericalprint@fraction & \expandonce\emph{\expandonce\moodle@feedback}}%
5070 \fi
5071 \xa\g@addto@macro\xa\cloze@numerical@table@text\xa{\moodle@clozenumericalprint@line \\\hline}%
5072 }%
5073
5074 \def\saveclozenumericalanswer#1{%
5075 \bgroup
5076 \saveclozenumericalanswer@int#1\moodle@answer@rdelim
5077 \egroup
5078 }%
5079 \newcommand\saveclozenumericalanswer@int[1][]{%
5080 \setkeys{moodle}{fraction=100,#1}% %%%%%% DEFAULT VALUE IS 100%
5081 \saveclozenumericalanswer@int@int%
5082 }%
5083 \def\saveclozenumericalanswer@int@int#1\moodle@answer@rdelim{%
5084 \ifgatherbeginningofloop\else
5085 \xa\gdef\xa\clozenumerical@coding\xa{\clozenumerical@coding\clozetilde}% separator between answers
5086 \fi
5087 \def\moodle@answertext{#1}%
5088 \trim@spaces@in\moodle@answertext
5089 \ifx\moodle@fraction\@hundred
5090 \g@addto@macro\clozenumerical@coding{\clozecorrect}%
5091 \else
5092 \moodle@checkclozefraction
5093 \ifdim0pt=\moodle@fraction pt\relax\else
5094 \xdef\clozenumerical@coding{\expandonce\clozenumerical@coding\otherpercent\moodle@fraction\otherpercent}%
5095 \fi
5096 \fi
5097 \ifx\moodle@answertext\@star
5098 \xdef\clozenumerical@coding{\expandonce\clozenumerical@coding\moodle@answertext}%
5099 \else
5100 \xdef\clozenumerical@coding{\expandonce\clozenumerical@coding\moodle@answertext:\moodle@tolerance}%
5101 \fi
5102 \ifx\moodle@feedback\@empty\else
5103 %\trim@spaces@in\moodle@feedback
5104 \xdef\clozenumerical@coding{\expandonce\clozenumerical@coding\otherbackslash\otherhash\expandonce\moodle@feedback}%
5105 \fi
5106 }%
5107 % \end{macrocode}
5108 %
5109 % \subsubsection{Cloze Short Answer Questions}
5110 %
5111 % \begin{macrocode}
5112 \NewEnviron{clozeshortanswer}[1][]{%
5113 \bgroup
5114 \expandafter\gatheritems\expandafter{\BODY}%
5115 \let\moodle@questionheader=\gatheredheader
5116 \setkeys{moodle}{#1}%
5117 \moodle@checkclozegrade
5118 \ifhtmlizer@active
5119 %HTML version
5120 \def\moodle@clozeshortanswer@output{}%
5121 \xa\g@addto@macro\xa\moodle@clozeshortanswer@output\xa{\moodle@questionheader}%
5122 \def\clozeshortanswer@coding{}%
5123 \ifmoodle@usecase
5124 \edef\clozeshortanswer@coding{\csname moodle@default grade\endcsname:SHORTANSWER_C:}%
5125 \else
5126 \edef\clozeshortanswer@coding{\csname moodle@default grade\endcsname:SHORTANSWER:}%
5127 \fi
5128 \bgroup
5129 \setkeys{moodle}{feedback={}}%
5130 \loopthroughitemswithcommand{\saveclozeshortansweranswer}%
5131 \egroup
5132 %\xa\g@addto@macro\xa\clozeshortanswer@coding\xa{\otherrbrace}%
5133 \xa\g@addto@macro\xa\moodle@clozeshortanswer@output\xa{\xa\clozelbrace\clozeshortanswer@coding\clozerbrace}%
5134 \xa\gdef\xa\htmlize@afteraction@hook\xa{\moodle@clozeshortanswer@output}%
5135 \def\endclozeshortanswer@code{\htmlize@patchendenvironment}%
5136 \else
5137 %LaTeX version
5138 \global\advance\moodle@totalmarks by \csname moodle@default grade\endcsname pt
5139 \moodle@questionheader% %Any introductory text just continues to be typeset.
5140 \par
5141 \noindent
5142 \moodle@makelatextag@qtype{shortanswer}
5143 \ifmoodle@handout\else
5144 \moodle@makelatextag@value{default grade}{marked out of}
5145 \moodle@makelatextag@shortanswer
5146 \par
5147 \noindent
5148 \def\cloze@shortanswer@table@text{}%
5149 \loopthroughitemswithcommand{\moodle@print@clozeshortanswer@answer}%
5150 \begin{tabular}[t]{|p{.45\linewidth}|p{.45\linewidth}|}
5151 \firsthline% (\firsthline is from the array package.)
5152 % answer & feedback \\\hline\hline
5153 \cloze@shortanswer@table@text%
5154 \end{tabular}%
5155 \par%
5156 \fi
5157 \def\endclozeshortanswer@code{\relax}%
5158 \fi
5159 \passvalueaftergroup\endclozeshortanswer@code%
5160 \passvalueaftergroup\htmlize@afteraction@hook%
5161 \egroup
5162 }[\endclozeshortanswer@code]%
5163
5164 \def\moodle@print@clozeshortanswer@answer#1{%
5165 \let\moodle@feedback=\@empty
5166 \bgroup
5167 \moodle@print@clozeshortanswer@answer@int#1\@rdelim
5168 \egroup
5169 }%
5170 \newcommand\moodle@print@clozeshortanswer@answer@int[1][]{%
5171 \setkeys{moodle}{#1}%
5172 \moodle@print@clozeshortanswer@answer@int@int%
5173 }%
5174 \def\moodle@print@clozeshortanswer@answer@int@int#1\@rdelim{%
5175 \ifx\moodle@fraction\@hundred
5176 \def\moodle@clozeshortanswerprint@fraction{$~\checkmark$}%
5177 \else
5178 \moodle@checkclozefraction
5179 \edef\moodle@clozeshortanswerprint@fraction{$~(\moodle@fraction\%)$}%
5180 \fi
5181 \xdef\moodle@clozeshortanswerprint@line{#1~\moodle@clozeshortanswerprint@fraction & \expandonce\emph{\expandonce\moodle@feedback}}%
5182 \xa\g@addto@macro\xa\cloze@shortanswer@table@text\xa{\moodle@clozeshortanswerprint@line \\\hline}%
5183 }%
5184
5185 \def\saveclozeshortansweranswer#1{%
5186 \bgroup
5187 \saveclozeshortansweranswer@int#1\moodle@answer@rdelim
5188 \egroup
5189 }%
5190 \newcommand\saveclozeshortansweranswer@int[1][]{%
5191 \setkeys{moodle}{fraction=100,#1}% %%%%%% DEFAULT VALUE IS 100%
5192 \saveclozeshortansweranswer@int@int%
5193 }%
5194 \def\saveclozeshortansweranswer@int@int#1\moodle@answer@rdelim{%
5195 \ifgatherbeginningofloop\else
5196 \xa\gdef\xa\clozeshortanswer@coding\xa{\clozeshortanswer@coding\clozetilde}% separator between answers
5197 \fi
5198 \def\moodle@answertext{#1}%
5199 \trim@spaces@in\moodle@answertext
5200 \ifx\moodle@fraction\@hundred
5201 \g@addto@macro\clozeshortanswer@coding{\clozecorrect}%
5202 \else
5203 \moodle@checkclozefraction
5204 \ifdim0pt=\moodle@fraction pt\relax\else
5205 \xdef\clozeshortanswer@coding{\expandonce\clozeshortanswer@coding\otherpercent\moodle@fraction\otherpercent}%
5206 \fi
5207 \fi
5208 \xdef\clozeshortanswer@coding{\expandonce\clozeshortanswer@coding\moodle@answertext}%
5209 \ifx\moodle@feedback\@empty\else
5210 \xdef\clozeshortanswer@coding{\expandonce\clozeshortanswer@coding\otherbackslash\otherhash\expandonce\moodle@feedback}%
5211 \fi
5212 }%
5213 % \end{macrocode}
5214 %
5215 % \section{Converting \LaTeX\ to HTML}
5216 % A lot of work must now be done to convert the \LaTeX\ code
5217 % of a question or answer into \HTML\ code with embedded \TeX\ for math.
5218 %
5219 % \subsection{Catcode Setup}
5220 % First, we create versions of the special characters with catcode 12, ``other.''
5221 % \begin{macrocode}
5222 {\catcode`\#=12\gdef\otherhash{#}%
5223 \catcode`\~=12\gdef\othertilde{~}%
5224 \catcode`\&=12\gdef\otherampersand{&}%
5225 \catcode`\^=12\gdef\othercaret{^}%
5226 \catcode`\$=12\gdef\otherdollar{$}%
5227 \catcode`\%=12\gdef\otherpercent{%}
5228 \catcode`\[=12\gdef\otherlbracket{[}
5229 \catcode`\]=12\gdef\otherrbracket{]}}%
5230 {\catcode`\=\string=12\gdef\otherequal{=}}%
5231 {\catcode`\ =12\gdef\otherspace{ }}%
5232 {\ttfamily\catcode`\|=0\catcode`\\=12\relax|gdef|otherbackslash{\}}%
5233 {\catcode`\[=1\catcode`\]=2\catcode`\{=12\catcode`\}=12%
5234 \gdef\otherlbrace[{]\gdef\otherrbrace[}]\gdef\clozelbrace[{]\gdef\clozerbrace[}]]%
5235
5236 \edef\@otherlbrace{\otherlbrace}%
5237 \edef\@otherrbrace{\otherrbrace}%
5238 \edef\@otherlbracket{\otherlbracket}%
5239 \edef\@otherrbracket{\otherrbracket}%
5240 \edef\@clozelbrace{\clozelbrace}%
5241 \edef\@clozerbrace{\clozerbrace}%
5242 \edef\@otherdollar{\otherdollar}%
5243 \edef\@otherbackslash{\otherbackslash}%
5244 \edef\@othertilde{\othertilde}%
5245 \edef\@otherequal{\otherequal}%
5246 % \end{macrocode}
5247 %
5248 % Next, we define commands to change catcodes to a suitable verbatim mode
5249 % for transcription.
5250 %
5251 % \begin{macrocode}
5252 { \catcode`\[=1\relax
5253 \catcode`\]=2\relax
5254 \catcode`\|=0\relax
5255 |gdef|verbcatcodesweirdest[
5256 |catcode`\{=12|relax
5257 |catcode`\}=12|relax
5258 |catcode`\\=12|relax
5259 ]%
5260 }%
5261 \def\verbcatcodes{%
5262 \catcode`\$=12\relax
5263 \catcode`\&=12\relax
5264 \catcode`\#=12\relax
5265 \catcode`\^=12\relax
5266 \catcode`\_=12\relax
5267 \catcode`\~=12\relax
5268 \makeatletter
5269 \catcode`\%=12\relax
5270 \catcode`\ =12\relax\catcode\newlinechar=12\verbcatcodesweirdest}%
5271
5272 \def\normalcatcodes{%
5273 \catcode`\\=0\relax
5274 \catcode`\{=1\relax
5275 \catcode`\}=2\relax
5276 \catcode`\$=3\relax
5277 \catcode`\&=4\relax
5278 \catcode\endlinechar=5\relax
5279 \catcode`\#=6\relax
5280 \catcode`\^=7\relax
5281 \catcode`\_=8\relax
5282 \catcode`\ =10\relax
5283 \makeatletter% We will be detokenizing and retokenizing internal control sequences, so we need this.
5284 \catcode`\~=13\relax
5285 \catcode`\%=14\relax}%
5286
5287 \def\retokenizingcatcodes{%
5288 %For rescanning previously scanned text, all true comments will already be gone,
5289 %but % signs may have been inserted by Cloze questions, so we want to treat them as 'other.'
5290 %
5291 % TODO: #'s are more worrisome.
5292 \normalcatcodes
5293 \catcode`\%=12\relax
5294 }
5295 % \end{macrocode}
5296 %
5297 % \subsection{Detokenization and Retokenization}
5298 %
5299 % We will be processing a \TeX\ token list.
5300 % Based on its content, sometimes we will want it to be detokenized to
5301 % individual characters, but other times we want it retokenized so that
5302 % \TeX's own parsing mechanism can gather up the parameters of macros.
5303 % We use the e\TeX\ primitive command |\scantokens| to do this.
5304 %
5305 % The following code (catcodes, groupings and all) defines a |\scantokens@to@macro| macro.
5306 % That will assemble and disassemble strings of tokens
5307 % using any changing schemes of catcodes we desire.
5308 %
5309 % We define |^^A| to be |\gdef\stm@saved|, while |^^B| and |^^C| are substitutes for |{| and |}|, respectively.
5310 % This permits us to define |\scantokens@to@macro| in a peculiar catcode regime.
5311 % \begin{macrocode}
5312 \begingroup
5313 \catcode`\^^A=13\gdef^^A{\gdef\stm@saved}%
5314 \catcode`\^^B=1\catcode`\^^C=2\relax
5315 \long\gdef\scantokens@to@macro#1#2#3{%
5316 % #1 = control sequence to be defined
5317 % #2 = command to change catcodes, e.g. \verbcatcodes,
5318 % and define any command sequences
5319 % #3 = text to be retokenized and saved into #1.
5320 \bgroup
5321 \def\texttorescan{#3}%
5322 \catcode`\^^A=13\catcode`\^^B=1\catcode`\^^C=2\relax
5323 \xa\def\xa\arg\xa{\xa^^A\xa^^B\texttorescan^^C}%
5324 #2%
5325 \catcode\endlinechar=9\relax%
5326 %\scantokens always sees an end-of-line character at its end and converts it to a space.
5327 %The catcode change sets \scantokens to ignore end-of-line chars.
5328 %In practice, we're always calling \scantokens on previously scanned text anyway,
5329 %so we won't miss any real end-of-line chars, since they were already converted to spaces.
5330 \xa\scantokens\xa{\arg}%
5331 \egroup
5332 \xa\def\xa#1\xa{\stm@saved}%
5333 }%
5334 \endgroup%
5335
5336 \long\def\ultradetokenize@to@macro#1#2{%
5337 \scantokens@to@macro#1{\verbcatcodes}{#2}%
5338 }%
5339 \def\retokenizenormal@to@macro#1#2{%
5340 \scantokens@to@macro#1{\retokenizingcatcodes}{#2}%
5341 }%
5342 % \end{macrocode}
5343 %
5344 % \subsection{Level-Tracking}
5345 %
5346 % \subsubsection{TeX groups}
5347 % While parsing, we'll need to keep track of how deeply nested in \TeX\ groups we are.
5348 % \begin{macrocode}
5349 \newcount\grouplevel
5350 % \end{macrocode}
5351 %
5352 % \subsubsection{Math mode}
5353 % While parsing, we'll need to keep track of whether
5354 % we are in math mode (and how many levels deep the math mode might be nested).
5355 % \begin{macrocode}
5356 \newcount\moodle@mathmodedepth
5357 \moodle@mathmodedepth=0\relax
5358 \def\moodle@ifmathmode#1#2{%
5359 \ifnum\moodle@mathmodedepth>0\relax
5360 #1%
5361 \else
5362 #2%
5363 \fi
5364 }%
5365 % \end{macrocode}
5366 %
5367 % \subsubsection{Nested Lists}
5368 % While parsing, we'll need to keep track levels of nested list.
5369 % \begin{macrocode}
5370 \newcount\moodle@listdepth
5371 \moodle@listdepth=0\relax
5372
5373 % \end{macrocode}
5374 %
5375 % \subsection{Separation}
5376 %
5377 % This code separates a string of tokens into two parts.
5378 % Its parameters, |#1#2|, consist of tokenized text,
5379 % plus one terminal |\@htmlize@stop|.
5380 % We are trying to break up the text into its first group and the remainder.
5381 % This |\@htmlize@stop| is needed in case |#2| has the form ``|{...}|'',
5382 % since we don't want \TeX\ to strip the braces off.
5383 % Thus |\@htmlize@remainder| will definitely end in ``|\@htmlize@stop|''.
5384 % \begin{macrocode}
5385 \long\def\htmlize@grabblock#1#2\htmlize@rdelim@ii{%
5386 \long\def\htmlize@blockinbraces{#1}%
5387 \long\def\htmlize@remainder{#2}%
5388 }%
5389 % \end{macrocode}
5390 %
5391 % The next line defines the macro |\@htmlize@stop@detokenized| to contain
5392 % the string of tokens |\@htmlize@stop|, all of category code 12 (other) or 10 (letter).
5393 % We'll need this for comparison purposes later.
5394 % \begin{macrocode}
5395 \ultradetokenize@to@macro\@htmlize@stop@detokenized{\@htmlize@stop}%
5396 % \end{macrocode}
5397 %
5398 % The next line creates the macro |\htmlize@remove@stopcode|,
5399 % which removes the characters ``|\@htmlize@stop |'' from the end of a
5400 % detokenized sequence.
5401 % Its syntax when called is simply |\htmlize@remove@stopcode |\meta{material},
5402 % with no delimiters, since the ``|\@htmlize@stop |'' is itself the delimiter.
5403 % \begin{macrocode}
5404 \xa\def\xa\htmlize@remove@stopcode\xa#\xa1\@htmlize@stop@detokenized{#1}%
5405 % \end{macrocode}
5406 %
5407 % \subsection{Main Code: the HTMLizer}
5408 %
5409 % \begin{macrocode}
5410 \newif\ifhtmlizer@active
5411 \htmlizer@activefalse
5412 \newif\ifhtmlize@actioncs
5413 \newif\ifhtmlize@expandcs
5414 \newif\ifhtmlize@passcs
5415
5416 \long\def\@@begin@cs{\begin}%
5417 \def\@@htmlize@stop{\@htmlize@stop}%
5418
5419 \long\def\converttohtmlmacro#1#2{%
5420 \grouplevel=0\relax
5421 \def\htmlize@output{}%
5422 \ifmoodle@pluginfile
5423 \gdef\htmlize@embeddedfiletags{}%
5424 \fi
5425 \htmlizer@activetrue%
5426 \converttohtml@int{#2}%
5427 \htmlizer@activefalse%
5428 \let#1=\htmlize@output\relax
5429 }
5430
5431 \long\def\converttohtml@int#1{%
5432 \advance\grouplevel by 1\relax
5433 \bgroup
5434 \ultradetokenize@to@macro\htmlize@texttoscan{#1}%
5435 \xa\htmlize@recursive@i\htmlize@texttoscan\@htmlize@stop\@htmlize@stop\@htmlize@stop\htmlize@rdelim@i%
5436 \egroup
5437 \advance\grouplevel by -1\relax
5438 }%
5439
5440 \def\@lt{<}%
5441 \def\@gt{>}%
5442 \def\@dash{-}%
5443 \def\@dq{"}%
5444
5445 \long\def\htmlize@recursive@i#1#2#3\htmlize@rdelim@i{%
5446 % #1#2#3 is a sequence of tokens. All should be categories 11 (letter) or 12 (other).
5447 % It terminates with the control sequences \@htmlize@stop\@htmlize@stop\@htmlize@stop.
5448 %\long\def\ds{(#1|#2|#3)}\show\ds
5449 \def\test@i{#1}%
5450 \def\test@ii{#2}%
5451 \ifx\test@i\@@htmlize@stop
5452 \let\htmlize@next@i=\relax
5453 \else
5454 \ifx\test@i\@otherlbrace%
5455 \ifx\test@ii\@otherrbrace%
5456 \moodle@ifmathmode{\g@addto@macro\htmlize@output{\otherlbrace\otherrbrace}}{}%
5457 \def\htmlize@next@i{\htmlize@recursive@i#3\htmlize@rdelim@i}%
5458 \else
5459 \xa\g@addto@macro\xa\htmlize@output\xa{\otherlbrace}%
5460 \bgroup
5461 \normalcatcodes
5462 %We need to rescan the input as TeX code,
5463 % so TeX can automatically pull off the first group in braces.
5464 % First, let's get rid of the terminal \@htmlize@stop codes.
5465 {\def\@htmlize@stop{}\xdef\htmlize@scrap{#1#2#3}}%
5466 \let\htmlize@text@to@rescan=\htmlize@scrap%
5467 % Next, we retokenize the code.
5468 \xa\retokenizenormal@to@macro\xa\htmlize@rescanned\xa{\htmlize@text@to@rescan}%
5469 % Now break it up into two pieces.
5470 \xa\htmlize@grabblock\htmlize@rescanned\@htmlize@stop\htmlize@rdelim@ii%
5471 % The first piece, \htmlize@blockinbraces, will be passed as a unit to \converttohtml@int.
5472 % The second part, \htmlize@remainder, will continue at this depth of grouping.
5473 % Therefore we'll detokenize \htmlize@remainder here.
5474 \xa\ultradetokenize@to@macro\xa\htmlize@remainder@detokenized\xa{\htmlize@remainder}%
5475 \edef\htmlize@remainder@detokenized{\xa\htmlize@remove@stopcode\htmlize@remainder@detokenized}%
5476 %
5477 % Now build \htmlize@next@i.
5478 % When done, should look like
5479 % \converttohtml@int{\htmlize@blockinbraces}%
5480 % \g@addto@macro\htmlize@output{\otherrbrace}%
5481 % \htmlize@recursive@i\htmlize@remainder@detokenized\@htmlize@stop\@htmlize@stop\@htmlize@stop\htmlize@rdelim@i%
5482 % but with all three arguments expanded.
5483 % Note that we are running
5484 \gdef\htmlize@scrap{\converttohtml@int}%
5485 \xa\g@addto@macro\xa\htmlize@scrap\xa{\xa{\htmlize@blockinbraces}}%
5486 \g@addto@macro\htmlize@scrap{\g@addto@macro\htmlize@output}%
5487 \ifmoodle@clozemode
5488 \xa\g@addto@macro\xa\htmlize@scrap\xa{\xa{\otherbackslash\otherrbrace}}%
5489 % \moodle@ifmathmode{\xa\g@addto@macro\xa\htmlize@scrap\xa{\xa{\otherbackslash}}}%
5490 % {}%
5491 \else
5492 \xa\g@addto@macro\xa\htmlize@scrap\xa{\xa{\otherrbrace}}%
5493 \fi
5494 \g@addto@macro\htmlize@scrap{\htmlize@recursive@i}%
5495 \xa\g@addto@macro\xa\htmlize@scrap\xa{\htmlize@remainder@detokenized\@htmlize@stop\@htmlize@stop\@htmlize@stop\htmlize@rdelim@i}%
5496 % Okay, that's done. It's stored in a global macro.
5497 % Now we get it out of this group.
5498 \egroup
5499 \let\htmlize@next@i=\htmlize@scrap
5500 \fi
5501 \else
5502 \ifx\test@i\@otherdollar%
5503 % Math shift character.
5504 \ifx\test@ii\@otherdollar
5505 % Double dollar sign, so we're entering display math mode.
5506 % We grab everything between $$...$$, sanitize it, and add it verbatim to
5507 % our output.
5508 \htmlize@displaymathshift@replace#1#2#3\htmlize@rdelim@iii%
5509 \else
5510 % Single dollar sign, so we're entering inline math mode.
5511 % We grab everything between $...$, sanitize it, and add it verbatim to
5512 % our output.
5513 \htmlize@inlinemathshift@replace#1#2#3\htmlize@rdelim@iii%
5514 \fi% \ifx\test@ii\@otherdollar
5515 % Now we resume work.
5516 % The \htmlize@xxxxxxmathshift@replace macro stored the remaining text in \htmlize@remaining@text.
5517 % Note that since we never detokenized and retokenized #1#2#3,
5518 % \htmlize@remaining@text still includes the terminating \@htmlize@stop\@htmlize@stop\@htmlize@stop.
5519 \def\htmlize@next@i{\xa\htmlize@recursive@i\htmlize@remaining@text\htmlize@rdelim@i}%
5520 \else
5521 \ifx\test@i\@otherbackslash%
5522 % Control sequence. Oh boy.
5523 % There are three possible things to do:
5524 % 1. Retokenize everything, so we get a token list.
5525 % Expand this control sequence, the first one in the list,
5526 % to obtain a new token list. Then resume processing that list.
5527 % Examples: \def\emph#1{<EM>#1</EM>}, \def\rec#1{\frac{1}{#1}}, \def\inv{^{-1}}
5528 % \& --> &amp; \# --> #; etc.
5529 % Environments: \begin{center}...\end{center} --> <CENTER>...</CENTER>
5530 % 2. Retokenize everything, so we get a token list.
5531 % Let this first command (with its parameters) ACT.
5532 % This may involve work in TeX's stomach (e.g., with counters)
5533 % or with external files (e.g., image processing).
5534 % The command may directly add material to \htmlize@output,
5535 % but it should not typeset anything and should vanish from the
5536 % input stream when it is done.
5537 % When it's done, we somehow need to detokenize and resume
5538 % processing the remainder of the input stream.
5539 % Only commands explicitly crafted (or modified) to work
5540 % with moodle.sty can possibly do all this!
5541 % Examples: (modified) \includegraphics
5542 % Environments: \begin{clozemulti}, \begin{enumerate}
5543 % 3. Ignore that it's a command. Pass it right on as a character
5544 % sequence to \htmlize@output.
5545 % Examples: \alpha, \frac
5546 % Environments: \begin{array}
5547 %
5548 % #2 is only for items on a specific list.
5549 % #1 is anything that runs in TeX's mouth.
5550 % We could keep a list and give users a way to add to it.
5551 % I could also try expanding macros, using \ifcsmacro from etoolbox.sty
5552 %
5553 % The first step is to figure out what control sequence we're dealing with.
5554 % First, let's get rid of the terminal \@htmlize@stop codes.
5555 {\def\@htmlize@stop{}\xdef\htmlize@scrap{#1#2#3}}%
5556 \let\htmlize@text@to@rescan=\htmlize@scrap%
5557 % Next, we retokenize the code.
5558 \xa\retokenizenormal@to@macro\xa\htmlize@rescanned\xa{\htmlize@text@to@rescan}%
5559 % Now break it up into two pieces.
5560 \xa\htmlize@grabblock\htmlize@rescanned\@htmlize@stop\htmlize@rdelim@ii%
5561 \let\@htmlize@cs\htmlize@blockinbraces%
5562 \edef\htmlize@cs@string{\xa\string\@htmlize@cs}%
5563 % The first piece, \htmlize@blockinbraces, will contain the single token in \@htmlize@cs.
5564 % We'll need to keep the second part, \htmlize@remainder, since it probably
5565 % contains arguments to the cs in \@htmlize@cs.
5566 %\edef\ds{Encountered '\xa\string\@htmlize@cs'}\show\ds
5567 %
5568 % N.B. that \@htmlize@cs is a macro *containing* a single control sequence.
5569 % This is good for testing with \ifx.
5570 % \htmlize@cs@string contains the cs as a string, e.g., the characters "\emph".
5571 %
5572 \ifx\@htmlize@cs\@@begin@cs
5573 %This is a \begin. Begin environment-handling routine.
5574 %
5575 % Grab the first {...} from \htmlize@remainder, which is the argument
5576 % to \begin.
5577 \xa\htmlize@grabblock\htmlize@remainder\@htmlize@stop\htmlize@rdelim@ii%
5578 \let\htmlize@envname=\htmlize@blockinbraces%
5579 %We do not need the rest, so we won't pay any attention to the new
5580 %content of \htmlize@remainder.
5581 %
5582 %Now environments are non-expandable,
5583 %so there are only two possibilities: action or pass.
5584 \xa\ifinlist\xa{\htmlize@envname}{\htmlize@env@actionlist}%
5585 {% Action environment!
5586 %\bgroup
5587 %\def\ds{Encountered active environment \string\begin\{{\htmlize@envname}\}}\show\ds
5588 \def\htmlize@next@i{\xa\htmlize@do@actionenv\htmlize@rescanned\@htmlize@stop\htmlize@actionsequence@rdelim}%
5589 %The \bgroup is to active the environments.
5590 %The matching \egroup is found in \htmlize@do@actionenv.
5591 }{%An environment to pass to the HTML
5592 %We just pass the backslash from "\begin" and move on.
5593 \g@addto@macro\htmlize@output{#1}%
5594 \def\htmlize@next@i{\htmlize@recursive@i#2#3\htmlize@rdelim@i}%
5595 }%
5596 \else%
5597 %This is not an environment. Begin macro-handling routine.
5598 \htmlize@actioncsfalse
5599 \htmlize@expandcsfalse
5600 \htmlize@passcsfalse
5601 \xa\ifinlist\xa{\htmlize@cs@string}{\htmlize@cs@actionlist}%
5602 {%Action sequence!
5603 \htmlize@actioncstrue}%
5604 {% Not action sequence!
5605 \xa\ifinlist\xa{\htmlize@cs@string}{\htmlize@cs@expandlist}%
5606 {%CS to be expanded!
5607 \htmlize@expandcstrue%
5608 }%
5609 {%CS to be transcribed to XML
5610 \htmlize@passcstrue%
5611 }%
5612 }%
5613 %Now exactly one of \ifhtmlize@actioncs, \ifhtmlize@expandcs, and \ifhtmlize@passcs is true.
5614 \ifhtmlize@actioncs
5615 % It's an action-sequence.
5616 %\edef\ds{Must let \xa\string\@htmlize@cs\ act!}\show\ds
5617 %\show\htmlize@rescanned
5618 \def\htmlize@next@i{\xa\htmlize@do@actioncs\htmlize@rescanned\@htmlize@stop\htmlize@actionsequence@rdelim}%
5619 %\show\htmlize@rescanned
5620 % Note that \htmlize@do@actioncs should patch the command to have it
5621 % restart the scanning in time.
5622 \else
5623 \ifhtmlize@expandcs
5624 % control sequence to be expanded
5625 %\edef\ds{Must expand \xa\string\@htmlize@cs}\show\ds
5626 \bgroup
5627 \htmlize@redefine@expansionmacros
5628 %The \expandafters first expand \htmlize@rescanned,
5629 %and then expand its first token just once.
5630 \xa\xa\xa\gdef\xa\xa\xa\htmlize@scrap\xa\xa\xa{\htmlize@rescanned}%
5631 \egroup
5632 \xa\ultradetokenize@to@macro\xa\htmlize@remaining@text\xa{\htmlize@scrap}%
5633 \def\htmlize@next@i{\xa\htmlize@recursive@i\htmlize@remaining@text\@htmlize@stop\@htmlize@stop\@htmlize@stop\htmlize@rdelim@i}%
5634 \else
5635 % control sequence to be transcribed to \XML.
5636 %\edef\ds{Must pass on \xa\string\@htmlize@cs}\show\ds
5637 \g@addto@macro\htmlize@output{#1}%
5638 \def\htmlize@next@i{\htmlize@recursive@i#2#3\htmlize@rdelim@i}%
5639 \fi% \ifhtmlize@expandcs
5640 \fi% \ifhtmlize@actioncs
5641 \fi% \ifx\@htmlize@cs\@@begin@cs
5642 \else%
5643 \ifx\test@i\@othertilde%
5644 % The ~ becomes non-breaking space &nbsp; outside of math mode
5645 \moodle@ifmathmode{\g@addto@macro\htmlize@output{\@othertilde}}%
5646 {\g@addto@macro\htmlize@output{\otherampersand nbsp;}}%
5647 \def\htmlize@next@i{\htmlize@recursive@i#2#3\htmlize@rdelim@i}%
5648 \else
5649 \ifx\test@i\@lsinglequote%
5650 \ifx\test@ii\@lsinglequote%
5651 % Double left quote
5652 \g@addto@macro\htmlize@output{\otherampersand ldquo;}%
5653 \def\htmlize@next@i{\htmlize@recursive@i#3\htmlize@rdelim@i}%
5654 \else
5655 \g@addto@macro\htmlize@output{\otherampersand lsquo;}%
5656 \def\htmlize@next@i{\htmlize@recursive@i#2#3\htmlize@rdelim@i}%
5657 \fi% \ifx\test@ii\@lsinglequote%
5658 \else
5659 \ifx\test@i\@rsinglequote%
5660 \ifx\test@ii\@rsinglequote% Double right quote
5661 %AAedit 2021.01.06: in math mode, you should write 2 single right quotes, for second derivatives
5662 \moodle@ifmathmode{\g@addto@macro\htmlize@output{''}}%
5663 {\g@addto@macro\htmlize@output{\otherampersand rdquo;}}%
5664 \def\htmlize@next@i{\htmlize@recursive@i#3\htmlize@rdelim@i}%
5665 \else% Single right quote
5666 \moodle@ifmathmode{\g@addto@macro\htmlize@output{'}}%
5667 {\g@addto@macro\htmlize@output{\otherampersand rsquo;}}%
5668 \def\htmlize@next@i{\htmlize@recursive@i#2#3\htmlize@rdelim@i}%
5669 \fi% \ifx\test@ii\@rsinglequote%
5670 \else
5671 \ifx\test@i\@doublequote
5672 \g@addto@macro\htmlize@output{\otherampersand quot;}%
5673 \def\htmlize@next@i{\htmlize@recursive@i#2#3\htmlize@rdelim@i}%
5674 \else
5675 \ifx\test@i\@lt
5676 \g@addto@macro\htmlize@output{\otherampersand lt;}
5677 \def\htmlize@next@i{\htmlize@recursive@i#2#3\htmlize@rdelim@i}%
5678 \else
5679 \ifx\test@i\@gt
5680 \g@addto@macro\htmlize@output{\otherampersand gt;}%
5681 \def\htmlize@next@i{\htmlize@recursive@i#2#3\htmlize@rdelim@i}%
5682 \else
5683 \ifx\test@i\@dash
5684 \ifx\test@ii\@dash% en-dash (--)
5685 \moodle@ifmathmode{\g@addto@macro\htmlize@output{--}}%
5686 {\g@addto@macro\htmlize@output{\otherampersand ndash;}}%
5687 \def\htmlize@next@i{\htmlize@recursive@i#3\htmlize@rdelim@i}%
5688 \else
5689 \g@addto@macro\htmlize@output{-}%
5690 \def\htmlize@next@i{\htmlize@recursive@i#2#3\htmlize@rdelim@i}%
5691 \fi
5692 \else
5693 \ifx\test@i\@otherequal
5694 \ifmoodle@clozemode
5695 \moodle@ifmathmode{\g@addto@macro\htmlize@output{=}}%
5696 {\g@addto@macro\htmlize@output{\otherampersand\otherhash 61;}}%
5697 \else
5698 \g@addto@macro\htmlize@output{=}%
5699 \fi
5700 \def\htmlize@next@i{\htmlize@recursive@i#2#3\htmlize@rdelim@i}%
5701 \else
5702 % Default case: write first token to output, call self on remaining tokens.
5703 \g@addto@macro\htmlize@output{#1}%
5704 \def\htmlize@next@i{\htmlize@recursive@i#2#3\htmlize@rdelim@i}%
5705 \fi% \ifx\test@i\@otherequal
5706 \fi% \ifx\test@i\@dash
5707 \fi% \ifx\test@i\@gt
5708 \fi% \ifx\test@i\@lt
5709 \fi% \ifx\test@i\@doublequote
5710 \fi% \ifx\test@i\@rsinglequote%
5711 \fi% \ifx\test@i\@lsinglequote%
5712 \fi% \ifx\test@i\@othertilde%
5713 \fi% \ifx\test@i\@otherbackslash%
5714 \fi% \ifx\test@i\@otherdollar%
5715 \fi% \ifx\test@i\@otherlbrace%
5716 \fi% \ifx\test@i\@@htmlize@stop
5717 \htmlize@next@i
5718 }%
5719
5720 \def\@lsinglequote{`}%
5721 \def\@rsinglequote{'}%
5722 \def\@doublequote{"}%
5723 % \end{macrocode}
5724 %
5725 % \subsection{Math Mode handling}
5726 %
5727 % In the following, note that the |\|\meta{*}|mathrightdelim|'s gobble an argument.
5728 % This is so ``|$a$ is...|" can turn into
5729 % ``\ldots |a\|\meta{*}|mathrightdelim{} is...|"
5730 % and preserve a trailing space.
5731 % \begin{macrocode}
5732 \edef\inlinemathleftdelim{\otherbackslash(}%
5733 \def\inlinemathrightdelim#1{\advancemathmodecounter{-1}%
5734 \g@addto@macro\htmlize@output{\otherbackslash)}}%
5735 \edef\displaymathleftdelim{<CENTER>\otherbackslash[}%
5736 \def\displaymathrightdelim#1{\advancemathmodecounter{-1}%
5737 \g@addto@macro\htmlize@output{\otherbackslash]</CENTER>}}%
5738 \long\def\htmlize@inlinemath@recursive@i#1#2#3\htmlize@rdelim@i{%
5739 % inspired by \htmlize@recursive@i
5740 \def\test@i{#1}%
5741 \ifx\test@i\@@htmlize@stop
5742 \let\htmlize@next@i=\relax
5743 \else
5744 \ifx\test@i\@otherbackslash
5745 \g@addto@macro\mathtext{#1#2}%
5746 \def\htmlize@next@i{\xa\htmlize@inlinemath@recursive@i#3\htmlize@rdelim@i}%
5747 \else
5748 \ifx\test@i\@otherdollar
5749 \let\htmlize@next@i=\relax
5750 \g@addto@macro\aftertext{#2#3}%
5751 \else
5752 \g@addto@macro\mathtext{#1}%
5753 \def\htmlize@next@i{\xa\htmlize@inlinemath@recursive@i#2#3\htmlize@rdelim@i}%
5754 \fi
5755 \fi
5756 \fi
5757 \htmlize@next@i
5758 }
5759 {\catcode`\$=12\relax%
5760 \gdef\htmlize@inlinemathshift@replace#1#2\htmlize@rdelim@iii{%
5761 %\def\ds{inline math shift has '#1' and '#2'}\show\ds
5762 \xa\g@addto@macro\xa\htmlize@output\xa{\inlinemathleftdelim}%
5763 \advancemathmodecounter{1}%
5764 \gdef\mathtext{}%
5765 \gdef\aftertext{}%
5766 \htmlize@inlinemath@recursive@i#2\htmlize@rdelim@i%
5767 \xdef\htmlize@remaining@text{\expandonce\mathtext%
5768 \otherbackslash inlinemathrightdelim{}%
5769 \expandonce\aftertext}%
5770 %\show\htmlize@remaining@text
5771 }%
5772 \gdef\htmlize@displaymathshift@replace$$#1$$#2\htmlize@rdelim@iii{%
5773 \xa\g@addto@macro\xa\htmlize@output\xa{\displaymathleftdelim}%
5774 \advancemathmodecounter{1}%
5775 \def\mathtext{#1}%
5776 \def\aftertext{#2}%
5777 \xdef\htmlize@remaining@text{\expandonce\mathtext%
5778 \otherbackslash displaymathrightdelim{}%
5779 \expandonce\aftertext}%
5780 }%
5781 }
5782
5783 % \end{macrocode}
5784 %
5785 % \subsection{Engines for Control Sequences}
5786 %
5787 % There are three kinds of control sequences that need special handling:
5788 % \begin{enumerate}
5789 % \item Action environments
5790 % \item Action command sequences
5791 % \item Expansion macros
5792 % \end{enumerate}
5793 %
5794 % \subsubsection{Engine for running action environments}
5795 % \begin{macrocode}
5796 \long\def\htmlize@do@actionenv#1#2\@htmlize@stop\htmlize@actionsequence@rdelim{%
5797 \bgroup %The corresponding \egroup is given in \htmlize@proceedwiththerest,
5798 %to localize the changes to the environment definitions.
5799 \htmlize@activate@environments
5800 \gdef\htmlize@afteraction@hook{}%
5801 #1#2\@htmlize@stop\htmlize@actionsequence@rdelim%
5802 }
5803
5804 \def\htmlize@patchendenvironment{\swaptotrueendenvironment{\xa\htmlize@proceedwiththerest\htmlize@afteraction@hook}}%
5805
5806 \def\swaptotrueendenvironment#1#2\if@ignore\@ignorefalse\ignorespaces\fi{#2\if@ignore\@ignorefalse\ignorespaces\fi#1}%
5807
5808 \long\def\htmlize@record@environment#1{%
5809 \listadd{\htmlize@env@actionlist}{#1}%
5810 }
5811 \long\def\html@newenvironment#1#2{%
5812 \listadd{\htmlize@env@actionlist}{#1}%
5813 \g@addto@macro\htmlize@activate@environments{%
5814 \xa\let\csname #1\endcsname\relax%
5815 \xa\let\csname end#1\endcsname\relax%
5816 \NewEnviron{#1}{%
5817 #2%
5818 }[\htmlize@patchendenvironment]%
5819 }%
5820 }
5821
5822 \def\htmlize@activate@environments{}%
5823 % \end{macrocode}
5824 %
5825 % \subsubsection{Engine for running action command sequences}
5826 %
5827 % The following automatically adds the ``engine'' to do the command
5828 % and then resume processing the \LaTeX\ into \HTML.
5829 % It uses the |xpatch| package, which says it works with anything
5830 % defined using |\newcommand| etc. and |\newenvironment| etc.
5831 % \begin{macrocode}
5832 \gdef\htmlize@afteraction@hook{}%
5833
5834 \long\def\htmlize@do@actioncs#1#2\htmlize@actionsequence@rdelim{%
5835 % #1#2 contains the current string to be rendered into HTML;
5836 % N.B. it has been tokenized at this point,
5837 % so TeX can process it directly.
5838 % #1 = the command sequence we need to execute
5839 % #2 = the rest of the string
5840 %
5841 % First, we patch the desired command so that, when it is over,
5842 % it calls \htmlize@proceedwiththerest.
5843 % We do this within the group, so as not to permanently change the command.
5844 \bgroup
5845 % The matching \egroup is issued in \htmlize@proceedwiththerest,
5846 % so that the changes made by \htmlize@activate@css are localized to just the command itself.
5847 \gdef\htmlize@afteraction@hook{}%
5848 \htmlize@activate@css%
5849 \def\test@i{#1}%
5850 \ifx\test@i\@relax
5851 \def#1{\xa\htmlize@proceedwiththerest\htmlize@afteraction@hook}%
5852 \else
5853 \xapptocmd#1{\xa\htmlize@proceedwiththerest\htmlize@afteraction@hook}{}{\PackageError{Could not patch the command \string#1!}}%
5854 \fi
5855 % Now we call that patched command.
5856 #1#2\htmlize@actionsequence@rdelim%
5857 %The matching \egroup now is built into the command #1.
5858 }
5859 \long\def\htmlize@proceedwiththerest#1\htmlize@actionsequence@rdelim{%
5860 % The action cs has done its work.
5861 % Now we gather up the remaining tokens, detokenize them,
5862 % remove the \@htmlize@stop, and get back to work transcribing it.
5863 \egroup %This \egroup matches the \bgroup that was issued either in \htmlize@do@actioncs or in \htmlize@do@actionenv
5864 \ultradetokenize@to@macro\htmlize@remainder@detokenized{#1}%
5865 %This will contain an extra \@htmlize@stop, so we remove it.
5866 \xa\xa\xa\def\xa\xa\xa\htmlize@remainder@detokenized\xa\xa\xa{\xa\htmlize@remove@stopcode\htmlize@remainder@detokenized}%
5867 %Now we get back to work transcribing the remainder.
5868 \xa\htmlize@recursive@i\htmlize@remainder@detokenized\@htmlize@stop\@htmlize@stop\@htmlize@stop\htmlize@rdelim@i%
5869 }
5870
5871 \long\def\htmlize@record@action#1{%
5872 \xa\listadd\xa\htmlize@cs@actionlist\xa{\string#1}%
5873 }
5874
5875 \def\htmlize@activate@css{}%
5876 \long\def\html@action@def#1{%
5877 \htmlize@record@action{#1}%
5878 \xa\def\xa\htmlize@scrap\xa{\xa\let\xa#1\csname html@\string#1\endcsname}%
5879 \xa\g@addto@macro\xa\htmlize@activate@css\xa{\htmlize@scrap}%
5880 \xa\def\csname html@\string#1\endcsname% %And this \def\html@\oldcsname is follows by the remainder of the definition.
5881 }
5882 \def\html@action@newcommand#1[#2][#3]#4{%
5883 %\message{>>> Defining #1[#2][#3]{...} ^^J}
5884 \ifmoodle@draftmode
5885 \else
5886 \xa\html@action@def\csname #1\endcsname{\csname moodle@#1@int\endcsname}%
5887 \fi
5888 % Note that \htmlize@do@actioncs will 'patch' this by putting
5889 % '\xa\htmlize@proceedwiththerest\htmlize@afteraction@hook'
5890 % at the end. We want those 3 tokens to occur instead after
5891 % the graphics filename.
5892 \xa\csdef{moodle@#1@int}##1##2##3{\csname moodle@#1@int@int\endcsname}%
5893 % This gobbles up those three spurious tokens,
5894 % which we will re-insert after our work is done.
5895 \xa\newcommand\csname moodle@#1@int@int\endcsname[#2][#3]{%
5896 #4%
5897 % Now we re-insert the code to get the HTMLizing going again.
5898 \xa\htmlize@proceedwiththerest\htmlize@afteraction@hook
5899 }%
5900 }
5901 % \end{macrocode}
5902 %
5903 % \subsubsection{Engine for expansion control sequences}
5904 %
5905 % Calling |\htmlize@redefine@expansionmacros| will redefine
5906 % the macros for us. It starts out empty.
5907 % \begin{macrocode}
5908 \long\def\htmlize@redefine@expansionmacros{}%
5909 % \end{macrocode}
5910 % If |\mymacro| needs no changes to be suited for expansion,
5911 % you can simply call |\htmlize@record@expand{\mymacro}|
5912 % or |\htmlregister{\mymacro}|
5913 % to record that it should be expanded on its way to the \HTML.
5914 % Examples would be user-built macros such as |\inv|$\to$|^{-1}|
5915 % or |\N|$\to$|\mathbb{N}|.
5916 % \begin{macrocode}
5917 \long\def\htmlize@record@expand#1{%
5918 \xa\listadd\xa\htmlize@cs@expandlist\xa{\string#1}%
5919 }
5920 \let\htmlregister=\htmlize@record@expand
5921 % \end{macrocode}
5922 % Often users define a list of macros at the end of the preamble.
5923 % It can be cumbersome to record individually these macros for expansion.
5924 % By calling |\moodleregisternewcommands| they trigger the automatic
5925 % expansion of macros defined subsequently using |\newcommand|,
5926 % |\renewcommand|, |\providecommand| or their starred variants.
5927 % \begin{macrocode}
5928 \def\moodleregisternewcommands{%
5929 %% INSPIRED FROM
5930 %https://tex.stackexchange.com/questions/73271/how-to-redefine-or-patch-the-newcommand-command
5931 \newcommand*{\saved@ifdefinable}{}
5932 \let\saved@ifdefinable\@ifdefinable
5933 \renewcommand{\@ifdefinable}[2]{%
5934 \saved@ifdefinable{##1}{##2}%
5935 \htmlregister{##1}
5936 }%
5937 \let\@@ifdefinable\@ifdefinable
5938 }%
5939 % \end{macrocode}
5940 % On the other hand, if an alternate version of the macro is
5941 % needed for \HTML\ purposes, you can define its \HTML\ version with
5942 % |\html@def\mymacro...|
5943 % Parameters are okay.
5944 % An example would be
5945 % |\html@def\emph#1{<EM>#1</EM>}|.
5946 % \begin{macrocode}
5947 \long\def\html@def#1{%
5948 \htmlize@record@expand{#1}%
5949 \xa\def\xa\htmlize@scrap\xa{\xa\let\xa#1\csname html@\string#1\endcsname}%
5950 \xa\g@addto@macro\xa\htmlize@redefine@expansionmacros\xa{\htmlize@scrap}%
5951 \xa\def\csname html@\string#1\endcsname%
5952 }
5953 % \end{macrocode}
5954 % Note that when |\html@def| expands out, it ends with |\def\html@\oldcsname|
5955 % which abuts directly on the remainder of the definition.
5956 %
5957 % \subsection{Specific Control Sequences for Action and Expansion}
5958 %
5959 % Now that we have that machinery in place,
5960 % we define specific environments, action control sequences, and macros to
5961 % expand to accomplish our purposes.
5962 %
5963 % \subsubsection{Action Environments}
5964 % \begin{macrocode}
5965 \htmlize@record@environment{clozemulti}
5966 \htmlize@record@environment{multi}
5967 \htmlize@record@environment{clozenumerical}
5968 \htmlize@record@environment{numerical}
5969 \htmlize@record@environment{clozeshortanswer}
5970 \htmlize@record@environment{shortanswer}
5971
5972 \html@newenvironment{center}{\xdef\htmlize@afteraction@hook{\noexpand\HTMLtag{CENTER}\expandonce\BODY\noexpand\HTMLtag{/CENTER}}}%
5973
5974 \html@newenvironment{quote}{\xdef\htmlize@afteraction@hook{\noexpand\HTMLtag{BLOCKQUOTE}\expandonce\BODY\noexpand\HTMLtag{/BLOCKQUOTE}}}%
5975
5976 \html@newenvironment{quotation}{\xdef\htmlize@afteraction@hook{\noexpand\HTMLtag{BLOCKQUOTE}\expandonce\BODY\noexpand\HTMLtag{/BLOCKQUOTE}}}%
5977
5978 \def\moodle@save@getitems@state{%
5979 \global\xa\xdef\csname moodle@currentitemnumber@level@\the\moodle@listdepth\xa\endcsname\xa{\thecurrentitemnumber}%
5980 \global\xa\xdef\csname moodle@numgathereditems@level@\the\moodle@listdepth\xa\endcsname\xa{\thenumgathereditems}%
5981 \moodle@saveitems{\thenumgathereditems}%
5982 }%
5983 \def\moodle@restore@getitems@state{%
5984 \setcounter{numgathereditems}{\csname moodle@numgathereditems@level@\the\moodle@listdepth\endcsname}%
5985 \setcounter{currentitemnumber}{\csname moodle@currentitemnumber@level@\the\moodle@listdepth\endcsname}%
5986 \moodle@restoreitems{\thenumgathereditems}%
5987 }%
5988 \def\moodle@saveitems#1{%
5989 \ifnum#1>0\relax
5990 \global\csletcs{moodle@level@\the\moodle@listdepth @item@#1}{getitems@item@#1}%
5991 \xa\moodle@saveitems\xa{\number\numexpr#1-1\expandafter}%
5992 \fi
5993 }%
5994 \def\moodle@restoreitems#1{%
5995 \ifnum#1>0\relax
5996 \global\csletcs{getitems@item@#1}{moodle@level@\the\moodle@listdepth @item@#1}%
5997 \global\xa\let\csname moodle@level@\the\moodle@listdepth @item@#1\endcsname=\@undefined
5998 \xa\moodle@restoreitems\xa{\number\numexpr#1-1\expandafter}%
5999 \fi
6000 }%
6001 \def\moodle@makelistenv#1#2{%
6002 \html@newenvironment{#1}{%
6003 \advance\moodle@listdepth by 1\relax
6004 \moodle@save@getitems@state%
6005 \xa\gatheritems\xa{\BODY}%
6006 \gdef\htmlize@afteraction@hook{\HTMLtag{#2}}%
6007 \loopthroughitemswithcommand{\moodle@itemtoLI}%
6008 \g@addto@macro\htmlize@afteraction@hook{\HTMLtag{/#2}}%
6009 \moodle@restore@getitems@state%
6010 \advance\moodle@listdepth by -1\relax
6011 }%
6012 }%
6013
6014 \moodle@makelistenv{enumerate}{OL}%
6015 \moodle@makelistenv{itemize}{UL}%
6016
6017 \def\moodle@itemtoLI#1{%
6018 \g@addto@macro\htmlize@afteraction@hook{\HTMLtag{LI}#1}%
6019 \trim@spaces@in\htmlize@afteraction@hook%
6020 \g@addto@macro\htmlize@afteraction@hook{\HTMLtag{/LI}}%
6021 }%
6022
6023 % \end{macrocode}
6024 %
6025 % \subsubsection{Action Control Sequences}
6026 %
6027 % \begin{macrocode}
6028 \def\advancemathmodecounter#1{%
6029 \global\advance\moodle@mathmodedepth by #1\relax
6030 }
6031 \def\openclozemode{%
6032 \global\moodle@clozemodetrue\relax
6033 }
6034 \def\endclozemode{%
6035 \global\moodle@clozemodefalse\relax
6036 }
6037 \htmlize@record@action{\advancemathmodecounter}%
6038 \htmlize@record@action{\openclozemode}%
6039 \htmlize@record@action{\endclozemode}%
6040 \htmlize@record@action{\relax}%
6041
6042 \html@action@def\HTMLtag#1{%
6043 \xa\g@addto@macro\xa\htmlize@output\xa{<#1>}%
6044 }%
6045 \html@action@def\%{%
6046 \moodle@ifmathmode{\g@addto@macro\htmlize@output{\otherbackslash\otherpercent}}%
6047 {\g@addto@macro\htmlize@output{\otherpercent}}%
6048 }%
6049 \html@action@def\#{\g@addto@macro\htmlize@output{\otherhash}}%
6050 \html@action@def\&{\g@addto@macro\htmlize@output{\otherampersand}}%
6051 \html@action@def\\{%
6052 \moodle@ifmathmode{\g@addto@macro\htmlize@output{\otherbackslash\otherbackslash}}%
6053 {\g@addto@macro\htmlize@output{<BR/>}}
6054 }%
6055 \html@action@def\{{%
6056 \moodle@ifmathmode{\g@addto@macro\htmlize@output{\otherbackslash\otherlbrace}}%
6057 {\g@addto@macro\htmlize@output{\otherlbrace}}%
6058 }%
6059 \html@action@def\}{%
6060 \moodle@ifmathmode{\g@addto@macro\htmlize@output{\otherbackslash\otherrbrace}}%
6061 {\ifmoodle@clozemode\g@addto@macro\htmlize@output{\otherbackslash\otherrbrace}%
6062 \else\g@addto@macro\htmlize@output{\otherrbrace}\fi}%
6063 }%
6064 \html@action@def\[{%
6065 \advancemathmodecounter{1}
6066 \g@addto@macro\htmlize@output{<CENTER>\otherbackslash\otherlbracket}%
6067 }%
6068 \html@action@def\]{%
6069 \g@addto@macro\htmlize@output{\otherbackslash\otherrbracket</CENTER>}%
6070 \advancemathmodecounter{-1}
6071 }%
6072 \html@action@def\({%
6073 \advancemathmodecounter{1}
6074 \g@addto@macro\htmlize@output{\otherbackslash(}%
6075 }%
6076 \html@action@def\){%
6077 \g@addto@macro\htmlize@output{\otherbackslash)}%
6078 \advancemathmodecounter{-1}
6079 }%
6080 \html@action@def\ldots{%
6081 \moodle@ifmathmode{\g@addto@macro\htmlize@output{\string\ldots}}%
6082 {\g@addto@macro\htmlize@output{\otherampersand hellip\othersemicol}}%
6083 }%
6084 \html@action@def\dots{%
6085 \moodle@ifmathmode{\g@addto@macro\htmlize@output{\string\dots}}%
6086 {\g@addto@macro\htmlize@output{\otherampersand hellip\othersemicol}}%
6087 }%
6088 \html@action@def\ {%
6089 \moodle@ifmathmode{\g@addto@macro\htmlize@output{\otherbackslash\otherspace}}%
6090 {\g@addto@macro\htmlize@output{\otherspace}}%
6091 }%
6092 \html@action@def\,{%
6093 \moodle@ifmathmode{\g@addto@macro\htmlize@output{\string\,}}%
6094 {\g@addto@macro\htmlize@output{\otherampersand\otherhash 8239\othersemicol}}%
6095 }%
6096 \html@action@def\thinspace{%
6097 \moodle@ifmathmode{\g@addto@macro\htmlize@output{\string\thinspace\otherspace}}%
6098 {\g@addto@macro\htmlize@output{\otherampersand\otherhash 8239\othersemicol}}%
6099 }%
6100 \html@action@def\>{%
6101 \moodle@ifmathmode{\g@addto@macro\htmlize@output{\otherbackslash\otherampersand gt;}}%
6102 {\g@addto@macro\htmlize@output{\otherampersand emsp14\othersemicol}}%
6103 }%
6104 \html@action@def\:{%
6105 \moodle@ifmathmode{\g@addto@macro\htmlize@output{\string\:}}%
6106 {\g@addto@macro\htmlize@output{\otherampersand emsp14\othersemicol}}%
6107 }%
6108 \html@action@def\medspace{%
6109 \moodle@ifmathmode{\g@addto@macro\htmlize@output{\string\:}}%
6110 {\g@addto@macro\htmlize@output{\otherampersand emsp14\othersemicol}}%
6111 }%
6112 \html@action@def\;{%
6113 \moodle@ifmathmode{\g@addto@macro\htmlize@output{\otherbackslash\othersemicol}}%
6114 {\g@addto@macro\htmlize@output{\otherampersand emsp13\othersemicol}}%
6115 }%
6116 \html@action@def\thickspace{%
6117 \moodle@ifmathmode{\g@addto@macro\htmlize@output{\otherbackslash\othersemicol}}%
6118 {\g@addto@macro\htmlize@output{\otherampersand emsp13\othersemicol}}%
6119 }%
6120 \html@action@def\enspace{%
6121 \moodle@ifmathmode{\g@addto@macro\htmlize@output{\string\enspace\otherspace}}%
6122 {\g@addto@macro\htmlize@output{\otherampersand ensp\othersemicol}}%
6123 }%
6124 \html@action@def\quad{%
6125 \moodle@ifmathmode{\g@addto@macro\htmlize@output{\string\quad\otherspace}}%
6126 {\g@addto@macro\htmlize@output{\otherampersand emsp\othersemicol}}%
6127 }%
6128 \html@action@def\qquad{%
6129 \moodle@ifmathmode{\g@addto@macro\htmlize@output{\string\qquad\otherspace}}%
6130 {\g@addto@macro\htmlize@output{\otherampersand emsp\othersemicol\otherampersand emsp\othersemicol}}%
6131 }%
6132 \html@action@def\${%
6133 \g@addto@macro\htmlize@output{\otherdollar}%
6134 }%
6135 \html@action@def\textquotesingle{%
6136 \g@addto@macro\htmlize@output{'}%
6137 }%
6138 \html@action@def\@dquote{%
6139 \g@addto@macro\htmlize@output{"}%
6140 }%
6141 \html@action@def\textquotedbl{%
6142 \g@addto@macro\htmlize@output{"}%
6143 }%
6144 \html@action@def\clozetilde{%
6145 \xa\g@addto@macro\xa\htmlize@output\xa{\othertilde}%
6146 }%
6147 \html@action@def\clozecorrect{%
6148 \xa\g@addto@macro\xa\htmlize@output\xa{\otherequal}%
6149 }%
6150 \html@action@def\clozelbrace{%
6151 \openclozemode
6152 \xa\g@addto@macro\xa\htmlize@output\xa{\otherlbrace}%
6153 }%
6154 \html@action@def\clozerbrace{%
6155 \xa\g@addto@macro\xa\htmlize@output\xa{\otherrbrace}%
6156 \endclozemode
6157 }%
6158 \html@action@def\TeX{%
6159 \g@addto@macro\htmlize@output{\otherbackslash(\otherbackslash rm\otherbackslash TeX\otherbackslash)}%
6160 }%
6161 \html@action@def\LaTeX{%
6162 \g@addto@macro\htmlize@output{\otherbackslash(\otherbackslash rm\otherbackslash LaTeX\otherbackslash)}%
6163 }%
6164
6165 {\catcode`;=12\relax\gdef\othersemicol{;}}
6166
6167 %Diacritical marks over vowels
6168 {\catcode`|=3\relax
6169 \gdef\htmlize@vowels{a|e|i|o|u|A|E|I|O|U|}}%
6170 \def\htmlize@define@diacritic#1#2{%
6171 \htmlize@record@action{#1}%
6172 \g@addto@macro\htmlize@activate@css{%
6173 \def#1##1{%
6174 \ifinlist{##1}{\htmlize@vowels}%
6175 {\g@addto@macro\htmlize@output{\otherampersand##1#2\othersemicol}}%
6176 {\xa\g@addto@macro\htmlize@output\xa{\string#1##1}}%
6177 }%
6178 }%
6179 }
6180 \htmlize@define@diacritic{\^}{circ}%
6181 \htmlize@define@diacritic{\'}{acute}%
6182 \htmlize@define@diacritic{\`}{grave}%
6183
6184 %Diaeresis/Tréma/Umlaut
6185 {\catcode`|=3\relax
6186 \gdef\htmlize@diaeresis{a|e|i|o|u|y|A|E|I|O|U|Y|}}%
6187 \html@action@def\"#1{%
6188 \ifinlist{#1}{\htmlize@diaeresis}%
6189 {\g@addto@macro\htmlize@output{\otherampersand#1uml\othersemicol}}%
6190 {\xa\g@addto@macro\htmlize@output\xa{\string\"#1}}%
6191 }%
6192
6193 %Hungarian long-umlaut diacritics
6194 \def\@o{o}\def\@O{O}\def\@u{u}\def\@U{U}%
6195 \html@action@def\H#1{%
6196 \bgroup
6197 \def\test@i{#1}%
6198 \ifx\test@i\@O
6199 \def\toadd{\otherampersand\otherhash336\othersemicol}%
6200 \else
6201 \ifx\test@i\@o
6202 \def\toadd{\otherampersand\otherhash337\othersemicol}%
6203 \else
6204 \ifx\test@i\@U
6205 \def\toadd{\otherampersand\otherhash368\othersemicol}%
6206 \else
6207 \ifx\test@i\@u
6208 \def\toadd{\otherampersand\otherhash369\othersemicol}%
6209 \else
6210 \def\toadd{\otherbackslash H\otherlbrace#1\otherrbrace}%
6211 \fi
6212 \fi
6213 \fi
6214 \fi
6215 \xa\g@addto@macro\xa\htmlize@output\xa{\toadd}%
6216 \egroup
6217 }%
6218
6219 %Cedilla
6220 \def\@c{c}\def\@C{C}\def\@s{s}\def\@S{S}\def\@t{t}\def\@T{T}%
6221 \html@action@def\c#1{%
6222 \bgroup
6223 \def\test@i{#1}%
6224 \ifx\test@i\@c
6225 \def\toadd{\otherampersand ccedil\othersemicol}%
6226 \else
6227 \ifx\test@i\@C
6228 \def\toadd{\otherampersand Ccedil\othersemicol}%
6229 \else
6230 \ifx\test@i\@s
6231 \def\toadd{\otherampersand\otherhash351\othersemicol}%
6232 \else
6233 \ifx\test@i\@S
6234 \def\toadd{\otherampersand\otherhash350\othersemicol}%
6235 \else
6236 \ifx\test@i\@t
6237 \def\toadd{\otherampersand\otherhash355\othersemicol}%
6238 \else
6239 \ifx\test@i\@T
6240 \def\toadd{\otherampersand\otherhash354\othersemicol}%
6241 \else
6242 \def\toadd{\otherbackslash c\otherlbrace#1\otherrbrace}%
6243 \fi
6244 \fi
6245 \fi
6246 \fi
6247 \fi
6248 \fi
6249 \xa\g@addto@macro\xa\htmlize@output\xa{\toadd}%
6250 \egroup
6251 }%
6252
6253 %Tilde over a, n, o
6254 {\catcode`|=3\relax
6255 \gdef\htmlize@tilde{A|N|O|a|n|o|}}%
6256 \html@action@def\~#1{%
6257 \ifinlist{#1}{\htmlize@tilde}%
6258 {\g@addto@macro\htmlize@output{\otherampersand#1tilde\othersemicol}}%
6259 {\xa\g@addto@macro\htmlize@output\xa{\string\~#1}}%
6260 }%
6261
6262 % breve diacritics
6263 {\catcode`|=3\relax
6264 \gdef\htmlize@breve{A|G|U|a|g|u|}}%
6265 \def\@e{e}\def\@E{E}\def\@i{i}\def\@ii{\i}\def\@I{I}\def\@o{o}\def\@O{O}%
6266 \html@action@def\u#1{%
6267 \ifinlist{#1}{\htmlize@breve}%
6268 {\g@addto@macro\htmlize@output{\otherampersand#1breve\othersemicol}}%
6269 {%
6270 \bgroup
6271 \def\test@i{#1}%
6272 \ifx\test@i\@E
6273 \def\toadd{\otherampersand\otherhash276\othersemicol}%
6274 \else
6275 \ifx\test@i\@e
6276 \def\toadd{\otherampersand\otherhash277\othersemicol}%
6277 \else
6278 \ifx\test@i\@I
6279 \def\toadd{\otherampersand\otherhash300\othersemicol}%
6280 \else
6281 \ifx\test@i\@i
6282 \def\toadd{\otherampersand\otherhash301\othersemicol}%
6283 \else
6284 \ifx\test@i\@ii
6285 \def\toadd{\otherampersand\otherhash301\othersemicol}%
6286 \else
6287 \ifx\test@i\@O
6288 \def\toadd{\otherampersand\otherhash334\othersemicol}%
6289 \else
6290 \ifx\test@i\@o
6291 \def\toadd{\otherampersand\otherhash335\othersemicol}%
6292 \else
6293 \def\toadd{\otherbackslash u\otherlbrace#1\otherrbrace}%
6294 \fi
6295 \fi
6296 \fi
6297 \fi
6298 \fi
6299 \fi
6300 \fi
6301 \xa\g@addto@macro\xa\htmlize@output\xa{\toadd}%
6302 \egroup
6303 }%
6304 }%
6305
6306 % caron diacritics
6307 {\catcode`|=3\relax
6308 \gdef\htmlize@caron{C|D|E|L|N|R|S|T|Z|c|d|e|l|n|r|s|t|z|}}%
6309 \html@action@def\v#1{%
6310 \ifinlist{#1}{\htmlize@caron}%
6311 {\g@addto@macro\htmlize@output{\otherampersand#1caron\othersemicol}}%
6312 {\xa\g@addto@macro\htmlize@output\xa{\string\v#1}}%
6313 }%
6314
6315 % Ogonek diacritics
6316 {\catcode`|=3\relax
6317 \gdef\htmlize@ogonek{A|E|I|U|a|e|i|u|}}%
6318 \html@action@def\k#1{%
6319 \ifinlist{#1}{\htmlize@ogonek}%
6320 {\g@addto@macro\htmlize@output{\otherampersand#1ogon\othersemicol}}%
6321 {%
6322 \bgroup
6323 \def\test@i{#1}%
6324 \ifx\test@i\@O
6325 \def\toadd{\otherampersand\otherhash490\othersemicol}%
6326 \else
6327 \ifx\test@i\@o
6328 \def\toadd{\otherampersand\otherhash491\othersemicol}%
6329 \else
6330 \def\toadd{\otherbackslash k\otherlbrace#1\otherrbrace}%
6331 \fi
6332 \fi
6333 \xa\g@addto@macro\xa\htmlize@output\xa{\toadd}%
6334 \egroup
6335 }%
6336 }%
6337
6338 % macron diacritics
6339 {\catcode`|=3\relax
6340 \gdef\htmlize@macron{A|E|I|O|U|a|e|i|o|u|}}%
6341 \def\@g{g}\def\@G{G}\def\@y{y}\def\@Y{Y}%
6342 \html@action@def\=#1{%
6343 \ifinlist{#1}{\htmlize@macron}%
6344 {\g@addto@macro\htmlize@output{\otherampersand#1macr\othersemicol}}%
6345 {%
6346 \bgroup
6347 \def\test@i{#1}%
6348 \ifx\test@i\@g
6349 \def\toadd{\otherampersand\otherhash7713\othersemicol}%
6350 \else
6351 \ifx\test@i\@G
6352 \def\toadd{\otherampersand\otherhash7712\othersemicol}%
6353 \else
6354 \ifx\test@i\@y
6355 \def\toadd{\otherampersand\otherhash563\othersemicol}%
6356 \else
6357 \ifx\test@i\@Y
6358 \def\toadd{\otherampersand\otherhash562\othersemicol}%
6359 \else
6360 \def\toadd{\otherbackslash =\otherlbrace#1\otherrbrace}%
6361 \fi
6362 \fi
6363 \fi
6364 \fi
6365 \xa\g@addto@macro\xa\htmlize@output\xa{\toadd}%
6366 \egroup
6367 }%
6368 }%
6369
6370 % macron below diacritics
6371 \def\@b{b}\def\@B{B}\def\@d{d}\def\@D{D}\def\@k{k}\def\@K{K}\def\@l{l}%
6372 \def\@L{L}\def\@n{n}\def\@N{N}\def\@t{t}\def\@T{T}\def\@z{z}\def\@Z{Z}%
6373 \html@action@def\b#1{%
6374 \bgroup
6375 \def\test@i{#1}%
6376 \ifx\test@i\@b
6377 \def\toadd{\otherampersand\otherhash7687\othersemicol}%
6378 \else
6379 \ifx\test@i\@B
6380 \def\toadd{\otherampersand\otherhash7686\othersemicol}%
6381 \else
6382 \ifx\test@i\@d
6383 \def\toadd{\otherampersand\otherhash7695\othersemicol}%
6384 \else
6385 \ifx\test@i\@D
6386 \def\toadd{\otherampersand\otherhash7694\othersemicol}%
6387 \else
6388 \ifx\test@i\@k
6389 \def\toadd{\otherampersand\otherhash7733\othersemicol}%
6390 \else
6391 \ifx\test@i\@K
6392 \def\toadd{\otherampersand\otherhash7732\othersemicol}%
6393 \else
6394 \ifx\test@i\@l
6395 \def\toadd{\otherampersand\otherhash7739\othersemicol}%
6396 \else
6397 \ifx\test@i\@L
6398 \def\toadd{\otherampersand\otherhash7738\othersemicol}%
6399 \else
6400 \ifx\test@i\@n
6401 \def\toadd{\otherampersand\otherhash7753\othersemicol}%
6402 \else
6403 \ifx\test@i\@N
6404 \def\toadd{\otherampersand\otherhash7752\othersemicol}%
6405 \else
6406 \ifx\test@i\@r
6407 \def\toadd{\otherampersand\otherhash7775\othersemicol}%
6408 \else
6409 \ifx\test@i\@R
6410 \def\toadd{\otherampersand\otherhash7774\othersemicol}%
6411 \else
6412 \ifx\test@i\@t
6413 \def\toadd{\otherampersand\otherhash7791\othersemicol}%
6414 \else
6415 \ifx\test@i\@T
6416 \def\toadd{\otherampersand\otherhash7790\othersemicol}%
6417 \else
6418 \ifx\test@i\@z
6419 \def\toadd{\otherampersand\otherhash7829\othersemicol}%
6420 \else
6421 \ifx\test@i\@Z
6422 \def\toadd{\otherampersand\otherhash7828\othersemicol}%
6423 \else
6424 \def\toadd{\otherbackslash b\otherlbrace#1\otherrbrace}%
6425 \fi
6426 \fi
6427 \fi
6428 \fi
6429 \fi
6430 \fi
6431 \fi
6432 \fi
6433 \fi
6434 \fi
6435 \fi
6436 \fi
6437 \fi
6438 \fi
6439 \fi
6440 \fi
6441 \xa\g@addto@macro\xa\htmlize@output\xa{\toadd}%
6442 \egroup
6443 }%
6444
6445 % Overdot diacritics
6446 {\catcode`|=3\relax
6447 \gdef\htmlize@dotabove{C|E|G|I|Z|c|e|g|z|}}%
6448 \def\@i{i}%
6449 \html@action@def\.#1{%
6450 \ifinlist{#1}{\htmlize@dotabove}%
6451 {\g@addto@macro\htmlize@output{\otherampersand#1dot\othersemicol}}%
6452 {
6453 \bgroup
6454 \def\test@i{#1}%
6455 \ifx\test@i\@i
6456 \def\toadd{i}%
6457 \else
6458 \def\toadd{\otherbackslash .\otherlbrace#1\otherrbrace}%
6459 \fi
6460 \xa\g@addto@macro\xa\htmlize@output\xa{\toadd}%
6461 \egroup
6462 }%
6463 }%
6464
6465 % Underdot diacritics
6466 \def\@A{A}\def\@a{a}\def\@B{B}\def\@b{b}%
6467 \html@action@def\d#1{%
6468 \bgroup
6469 \def\test@i{#1}%
6470 \ifx\test@i\@a
6471 \def\toadd{\otherampersand\otherhash7841\othersemicol}%
6472 \else
6473 \ifx\test@i\@A
6474 \def\toadd{\otherampersand\otherhash7840\othersemicol}%
6475 \else
6476 \ifx\test@i\@b
6477 \def\toadd{\otherampersand\otherhash7685\othersemicol}%
6478 \else
6479 \ifx\test@i\@B
6480 \def\toadd{\otherampersand\otherhash7684\othersemicol}%
6481 \else
6482 \def\toadd{\otherbackslash d\otherlbrace#1\otherrbrace}%
6483 \fi
6484 \fi
6485 \fi
6486 \fi
6487 \xa\g@addto@macro\xa\htmlize@output\xa{\toadd}%
6488 \egroup
6489 }%
6490
6491 % Overring
6492 {\catcode`|=3\relax
6493 \gdef\htmlize@ring{A|U|a|u|}}%
6494 \html@action@def\r#1{%
6495 \ifinlist{#1}{\htmlize@ring}%
6496 {\g@addto@macro\htmlize@output{\otherampersand#1ring\othersemicol}}%
6497 {\xa\g@addto@macro\htmlize@output\xa{\string\r#1}}%
6498 }%
6499 % \end{macrocode}
6500 %
6501 % \subsubsection{Command sequences for Expansion}
6502 %
6503 % First, commands defined by this package.
6504 % \begin{macrocode}
6505 \def\blank{\rule{1in}{0.5pt}}%
6506 % TODO: Make an optional argument for width? This wouldn't affect Moodle,
6507 % only the appearance in the PDF. It doesn't seem worth it.
6508 \html@def\blank{____________}%
6509 \htmlize@record@action\inlinemathrightdelim
6510 \htmlize@record@action\displaymathrightdelim
6511 % \end{macrocode}
6512 % Second, native \LaTeX\ commands.
6513 % \begin{macrocode}
6514 \html@def\emph#1{\HTMLtag{EM}#1\HTMLtag{/EM}}%
6515 \html@def\textbf#1{\HTMLtag{B}#1\HTMLtag{/B}}%
6516 \html@def\textit#1{\HTMLtag{I}#1\HTMLtag{/I}}%
6517 \html@def\textsc#1{\HTMLtag{SPAN STYLE="font-variant: small-caps;"}#1\HTMLtag{/SPAN}}%
6518 \html@def\textsuperscript#1{\HTMLtag{SUP}#1\HTMLtag{/SUP}}%
6519 \html@def\textsubscript#1{\HTMLtag{SUB}#1\HTMLtag{/SUB}}%
6520 \html@def\texttt#1{\HTMLtag{CODE}#1\HTMLtag{/CODE}}%
6521 \html@action@def\underline#1{%
6522 \moodle@ifmathmode{\g@addto@macro\htmlize@output{\string\underline{#1}}}%
6523 {\g@addto@macro\htmlize@output{<SPAN STYLE="text-decoration: underline;">#1</SPAN>}}%
6524 }%
6525 % \end{macrocode}
6526 % Third, popular \LaTeX\ commands from packages.
6527 % \begin{macrocode}
6528 \html@def\url#1{\HTMLtag{A href=\@dq #1\@dq}#1\HTMLtag{/A}}% url or hyperref
6529 \html@def\href#1#2{\HTMLtag{A href=\@dq #1\@dq}#2\HTMLtag{/A}}% hyperref
6530 \html@def\up#1{\HTMLtag{SUP}#1\HTMLtag{/SUP}}% \pkg{babel}, option \optn{french}
6531 \html@def\fup#1{\HTMLtag{SUP}#1\HTMLtag{/SUP}}% \pkg{babel}, option \optn{french}
6532 % \end{macrocode}
6533 % Fourth, \LaTeX\ commands for ligature and other glyphs.
6534 % \begin{macrocode}
6535 \html@def\aa{\&aring;}%
6536 \html@def\AA{\&Aring;}%
6537 \html@def\ae{\&aelig;}%
6538 \html@def\AE{\&AElig;}%
6539 \html@def\dh{\&eth;}%
6540 \html@def\DH{\&ETH;}%
6541 \html@def\dj{\&dstrok;}%
6542 \html@def\DJ{\&Dstrok;}%
6543 \html@def\i{\&imath;}%
6544 \html@def\ij{\&ijlig;}%
6545 \html@def\IJ{\&IJlig;}%
6546 \html@def\j{\&jmath;}%
6547 \html@def\l{\&lstrok;}%
6548 \html@def\L{\&Lstrok;}%
6549 \html@def\ng{\&eng;}%
6550 \html@def\NG{\&ENG;}%
6551 \html@def\o{\&oslash;}%
6552 \html@def\O{\&Oslash;}%
6553 \html@def\oe{\&oelig;}%
6554 \html@def\OE{\&OElig;}%
6555 \html@def\ss{\&szlig;}%
6556 \html@def\SS{\&\#7838;}%
6557 \html@def\th{\&thorn;}%
6558 \html@def\TH{\&THORN;}%
6559 % \end{macrocode}
6560 % Fifth, \LaTeX\ commands for horizontal spacing and line breaks.
6561 % In a number of situations, paragraph breaks translated into
6562 % |</p><p>| would bring trouble in the \HTML\ code. Examples:
6563 % \begin{itemize}
6564 % \item fields of cloze subquestions
6565 % \item inside environments like |center|, |itemize|, or |enumerate|.
6566 % \end{itemize}
6567 % \begin{macrocode}
6568 \html@def\space{ }%
6569 \html@def\textvisiblespace{\&blank;}%
6570 \html@def\newline{\HTMLtag{BR/}}%
6571 \html@def\par{\HTMLtag{BR/}}%
6572 % \end{macrocode}
6573 % Sixth, \LaTeX\ commands for various symbols.
6574 % \begin{macrocode}
6575 \html@def\textbackslash{\&\#92;}%
6576 \html@def\_{\&\#95;}%
6577 \html@def\textquestiondown{\&iquest;}%
6578 \html@def\textexclamdown{\&iexcl;}%
6579 \html@def\euro{\&euro;}%
6580 \html@def\texteuro{\&euro;}%
6581 \html@def\S{\&sect;}%
6582 % \end{macrocode}
6583 % Seventh, \LaTeX\ commands for various quotation marks.
6584 % \begin{macrocode}
6585 \html@def\textquoteleft{\&lsquo;}%
6586 \html@def\textquoteright{\&rsquo;}%
6587 \html@def\textquotedblleft{\&ldquo;}%
6588 \html@def\textquotedblright{\&rdquo;}%
6589 \html@def\guilsinglleft{\&lsaquo;}%
6590 \html@def\guilsinglright{\&rsaquo;}%
6591 \html@def\guillemotleft{\&laquo;}%
6592 \html@def\guillemotright{\&raquo;}%
6593 \html@def\quotesinglbase{\&sbquo;}%
6594 \html@def\quotedblbase{\&bdquo;}%
6595 \html@def\flq{\&lsaquo;}%
6596 \html@def\frq{\&rsaquo;}%
6597 \html@def\flqq{\&laquo;}%
6598 \html@def\frqq{\&raquo;}%
6599 \html@def\og{\&laquo;\&\#8239;}%
6600 \html@def\fg{\&\#8239;\&raquo;}%
6601 \html@def\glq{\&sbquo;}%
6602 \html@def\grq{\&lsquo;}%
6603 \html@def\glqq{\&bdquo;}%
6604 \html@def\grqq{\&ldquo;}%
6605 \html@def\dq{\&quot;}%
6606 % \end{macrocode}
6607 %
6608 % \subsubsection{Passing Code to \XML\ Only}
6609 % Users may want to include pieces of \HTML\ code to the \XML\ file only.
6610 % When producing the traditional output, the optional argument, empty
6611 % by default, is used.
6612 % \begin{macrocode}
6613 \newcommand\htmlonly[2][]{#1}%
6614 % \end{macrocode}
6615 % When producing the \XML\ file, the mandatory argument is passed as-is.
6616 % \begin{macrocode}
6617 \html@action@newcommand{htmlonly}[2][]{%
6618 \g@addto@macro\htmlize@output{#2}%
6619 }%
6620 % \end{macrocode}
6621 %
6622 % \subsection{Graphics via {\ttfamily\string\includegraphics}}
6623 %
6624 % \subsubsection{Finding Media Files}
6625 % The following code is adapted from the command |\Ginclude@graphics| as
6626 % found in \filenm{graphics.sty}.
6627 % Calling |\moodle@media@find|\marg{filename} looks for the file the
6628 % same way |\includegraphics| does, with or without extension provided,
6629 % in the current folder and in folders specified with |\graphicspath{}|.
6630 % The allowed extensions and their relative priorities can be set
6631 % via |\DeclareGraphicsExtensions{}|.
6632 % The outcome is that the macros |\moodle@media@base| and |\moodle@media@ext|
6633 % are set with the basename, including path, and extension, respectively.
6634 %
6635 % \begin{macrocode}
6636 \AtEndPreamble{%
6637 \@ifpackageloaded{graphics}{%
6638 \@ifpackagelater{graphics}{2019/10/08 v1.3c}{}%
6639 {\PackageError{moodle}{`moodle' is made to interact with the `graphics'\MessageBreak
6640 package not older than 2019/10/08.}\@eha\endinput}%
6641
6642 }{}%
6643 }%
6644 \def\moodle@media@find#1{%
6645 \ifx\detokenize\@undefined\else
6646 \edef\Gin@extensions{\detokenize\expandafter{\Gin@extensions}}%
6647 \fi
6648 \begingroup
6649 \let\input@path\Ginput@path
6650 \set@curr@file{#1}%
6651 \expandafter\filename@parse\expandafter{\@curr@file}%
6652 \ifx\filename@ext\Gin@gzext
6653 \expandafter\filename@parse\expandafter{\filename@base}%
6654 \ifx\filename@ext\relax
6655 \let\filename@ext\Gin@gzext
6656 \else
6657 \edef\Gin@ext{\Gin@ext\Gin@sepdefault\Gin@gzext}%
6658 \fi
6659 \fi
6660 \ifx\filename@ext\relax
6661 \@for\Gin@temp:=\Gin@extensions\do{%
6662 \ifx\Gin@ext\relax
6663 \Gin@getbase\Gin@temp
6664 \fi}%
6665 \else
6666 \Gin@getbase{\Gin@sepdefault\filename@ext}%
6667 \ifnum0%
6668 \ifx\Gin@ext\relax 1%
6669 \else \@ifundefined{Gin@rule@\Gin@ext}{1}{0}%
6670 \fi >0
6671 \let\Gin@ext\relax
6672 \let\Gin@savedbase\filename@base
6673 \let\Gin@savedext\filename@ext
6674 \edef\filename@base{\filename@base\Gin@sepdefault\filename@ext}%
6675 \let\filename@ext\relax
6676 \@for\Gin@temp:=\Gin@extensions\do{%
6677 \ifx\Gin@ext\relax
6678 \Gin@getbase\Gin@temp
6679 \fi}%
6680 \ifx\Gin@ext\relax
6681 \let\filename@base\Gin@savedbase
6682 \let\filename@ext\Gin@savedext
6683 \fi
6684 \fi
6685 \ifx\Gin@ext\relax
6686 \@warning{File `#1' not found}%
6687 \def\Gin@base{\filename@area\filename@base}%
6688 \edef\Gin@ext{\Gin@sepdefault\filename@ext}%
6689 \fi
6690 \fi
6691 \ifx\Gin@ext\relax
6692 \@latex@error{File `#1' not found}%
6693 {I could not locate the file with any of these extensions:^^J%
6694 \Gin@extensions^^J\@ehc}%
6695 \else
6696 % begin modified part
6697 \xdef\moodle@media@base{\detokenize\xa{\Gin@base}}%
6698 \xdef\moodle@media@ext{\detokenize\xa{\Gin@ext}}%
6699 % end modified part
6700 \fi
6701 \endgroup
6702 }
6703 % \end{macrocode}
6704 % \begin{macrocode}
6705 %See
6706 % * https://developer.mozilla.org/en-US/docs/Web/Media/Formats/Image_types
6707 % * https://developer.mozilla.org/en-US/docs/Web/Media/Formats/Containers
6708 \def\moodle@media@formats{}
6709 \newcommand{\DeclareMediaFormat}[3]{%
6710 \xdef\moodle@media@formats{\ifx\moodle@media@formats\empty\else\moodle@media@formats,\fi#1}%
6711 \csgdef{moodle@media@#1list}{#2}%
6712 \csgdef{moodle@media@#1mime}{#3}%
6713 }%
6714 % Image Formats
6715 \DeclareMediaFormat{PNG}{.png,.PNG}{image/png}%
6716 \DeclareMediaFormat{JPEG}{.jpg,.JPG,.jpeg,.JPEG}{image/jpeg}%
6717 \DeclareMediaFormat{SVG}{.svg,.SVG}{image/svg+xml}%
6718 \DeclareMediaFormat{GIF}{.gif}{image/gif}%
6719 % Audio Formats
6720 \DeclareMediaFormat{WAV}{.wav,.WAV}{audio/wave}%
6721 \DeclareMediaFormat{MP3}{.mp3,.MP3}{audio/mpeg}%
6722 \DeclareMediaFormat{OGG}{.ogg,.opus,.og&}{audio/ogg}%
6723 %\DeclareMediaFormat{FLAC}{.flac,.FLAC}{audio/flac}%
6724 % Video Formats
6725 \DeclareMediaFormat{WEBM}{.webm,.webm}{video/webm}%
6726 \DeclareMediaFormat{MP4}{.mp4,.MP4,.m4v,.M4V}{video/mp4}%
6727 \DeclareMediaFormat{OGV}{.ogv,.OGV}{video/ogg}%
6728 % \end{macrocode}
6729 % \begin{macrocode}
6730 \def\moodle@media@mime@identify#1{%
6731 \edef\test@i{\detokenize\xa{#1}}%
6732 \let\moodle@media@mime@current\relax
6733 \edef\moodle@media@formats{\detokenize\xa{\moodle@media@formats}}%
6734 \@for\@format:=\moodle@media@formats\do{%
6735 \edef\@templist{\csname moodle@media@\@format list\endcsname}%
6736 \@for\@ext:=\@templist\do{%
6737 \ifx\moodle@media@mime@current\relax
6738 \edef\@ext{\detokenize\xa{\@ext}}%
6739 \ifx\test@i\@ext
6740 \message{<<extension \@ext (\@format) identified>>^^J}%
6741 \xdef\moodle@media@mime@current{\csname moodle@media@\@format mime\endcsname}%
6742 \xdef\moodle@media@ext@current{#1}%
6743 \fi
6744 \fi
6745 }%
6746 }%
6747 }
6748 % \end{macrocode}
6749 %
6750 % \subsubsection{External program command lines}
6751 % We first set up commands for the external programs.
6752 % \begin{macrocode}
6753 \def\htmlize@setexecutable#1{%
6754 % Defines macro #1 to be #2 in a verbatim mode suitable for filenames
6755 \def\htmlize@executable@macro{#1}%
6756 \bgroup\catcode`\|=0\catcode`\\=12\relax%
6757 \htmlize@setexecutable@int
6758 }
6759 \def\htmlize@setexecutable@int#1{%
6760 \egroup
6761 \expandafter\def\htmlize@executable@macro{#1}%
6762 }
6763
6764 \def\ghostscriptcommand{\htmlize@setexecutable\gs}%
6765 \def\baselxivcommand{\htmlize@setexecutable\baselxiv}%
6766 \def\imagemagickcommand{\htmlize@setexecutable\htmlize@imagemagick@convert}%
6767 \def\optipngcommand{\htmlize@setexecutable\optipng}%
6768 \def\PDFtoSVGcommand{\htmlize@setexecutable\PDFtoSVG}%
6769 \def\SVGtoPDFcommand{\htmlize@setexecutable\SVGtoPDF}%
6770 \def\optiSVGcommand{\htmlize@setexecutable\optiSVG}%
6771 \def\DeleteFilecommand{\htmlize@setexecutable\DeleteFiles}%
6772 \def\MoveFilecommand{\htmlize@setexecutable\MoveFiles}%
6773 \def\DevNullcommand{\htmlize@setexecutable\DevNull}%
6774
6775 \ifwindows%
6776 \ghostscriptcommand{gswin64c.exe -dBATCH -dNOPAUSE -sDEVICE=pngalpha}%
6777 \baselxivcommand{certutil}%
6778 % Uses scour from inkscape default installation
6779 % The \Inkscape\bin directory has to be in the users path and provides both:
6780 % {inkscape,python}.exe the scour-Package which is found by python in Inkscape\lib\python3.x\site-packages\
6781 \optiSVGcommand{python -m scour.scour -q --enable-id-stripping --enable-comment-stripping
6782 --shorten-ids --indent=none --remove-descriptive-elements}%
6783 \DeleteFilecommand{del}%
6784 \MoveFilecommand{move}%
6785 \DevNullcommand{NUL}%
6786 \imagemagickcommand{magick -colorspace RGB}%
6787 \else%
6788 \ghostscriptcommand{gs -dBATCH -dNOPAUSE -sDEVICE=pngalpha}%
6789 \baselxivcommand{base64}%
6790 \optiSVGcommand{scour -q --enable-id-stripping --enable-comment-stripping
6791 --shorten-ids --indent=none --remove-descriptive-elements}%
6792 \DeleteFilecommand{rm -f}%
6793 \MoveFilecommand{mv}%
6794 \DevNullcommand{/dev/null}%
6795 \imagemagickcommand{convert -colorspace RGB}%
6796 \fi%
6797 \optipngcommand{optipng -clobber -strip all -quiet}%
6798 \PDFtoSVGcommand{inkscape --export-type=svg --export-area-page --vacuum-defs}%--pdf-poppler
6799 % remove the "--pdf-poppler" import option if you want to preserve text (avoid conversion to path)
6800 \SVGtoPDFcommand{inkscape --export-type=pdf --export-area-page}%
6801 % \end{macrocode}
6802 %
6803 % \subsubsection{Conversion and inclusion of non-native formats}
6804 % \begin{macrocode}
6805 \AtEndPreamble{%
6806 \@ifpackageloaded{graphics}{%
6807 \def\@firstofthree#1#2#3{#1}%
6808 \def\@secondofthree#1#2#3{#2}%
6809 \newcommand{\DeclareGraphicsAlien}[3]{%
6810 \edef\Gin@extensions{\Gin@extensions,#1}%
6811 \DeclareGraphicsRule{#1}{\@gobble#1}{#1}{}%
6812 \csdef{Gread@\@gobble#1}##1{%
6813 \edef\SourceFile{\Gin@base\Gin@ext}%
6814 \edef\Gin@base{\Gin@base-\@gobble#1-converted-to}%
6815 \edef\Gin@ext{#2}%
6816 \edef\OutputFile{\Gin@base\Gin@ext}%
6817 \edef\targetfmt{\expandafter\expandafter\expandafter
6818 \@firstofthree\csname Gin@rule@\Gin@ext\endcsname\relax}%
6819 \edef\targetext{\expandafter\expandafter\expandafter
6820 \@secondofthree\csname Gin@rule@\Gin@ext\endcsname\relax}%
6821 \IfFileExists{\OutputFile}{}{\ShellEscape{#3}}%
6822 \csletcs{Ginclude@\@gobble#1}{Ginclude@\targetfmt}%
6823 \csname Gread@\targetfmt\endcsname{\Gin@base\targetext}%
6824 }%
6825 }%
6826 % Support for \GIF\ files: passed as-is in \XML\ but converted in \PNG\ for PDF output.
6827 % In case the \GIF\ is animated, we pick up the first frame in this conversion.
6828 % While the picture will be animated after Moodle import, it will not be in the PDF
6829 % output, whatever the viewer is.
6830 \DeclareGraphicsAlien{.gif}{.png}{\htmlize@imagemagick@convert\otherspace \SourceFile[0]\otherspace \OutputFile}%
6831 }{
6832 \newcommand\includegraphics[2][]{\PackageError{moodle}{"\string\includegraphics" is not defined}%
6833 {Add "\string\usepackage{graphicx}" to you preamble.}}{}%}%
6834 }%
6835 }%
6836 % \end{macrocode}
6837 % \subsubsection{Graphics key-handling}
6838 % Next, we get ready to handle keys like |height=4cm| or |width=3cm| or |ppi=72|.
6839 % \begin{macrocode}
6840 \define@cmdkeys{moodle@includegraphics}[moodle@graphics@]{ppi}
6841 \define@cmdkey{moodle}[moodle@graphics@]{ppi}{}% This is so the ppi key can be set at the document, quiz, or question level.
6842 \define@cmdkeys{Gin}{ppi}% This is so the original \includegraphics will not object to a key of ppi.
6843 \setkeys{moodle@includegraphics}{ppi=103}
6844
6845 \newdimen\moodle@graphics@temp@dimen
6846 \newcount\moodle@graphics@height@pixels
6847 \newcount\moodle@graphics@width@pixels
6848 \def\moodle@graphics@dimentopixels#1#2{%
6849 \moodle@graphics@temp@dimen=#2\relax
6850 \moodle@graphics@temp@dimen=0.013837\moodle@graphics@temp@dimen
6851 \xa\moodle@graphics@temp@dimen\xa=\moodle@graphics@ppi\moodle@graphics@temp@dimen
6852 #1=\moodle@graphics@temp@dimen
6853 \divide #1 by 65536\relax
6854 }
6855 \define@key{moodle@includegraphics}{height}[]{%
6856 \moodle@graphics@dimentopixels{\moodle@graphics@height@pixels}{#1}%
6857 }
6858 \define@key{moodle@includegraphics}{width}[]{%
6859 \moodle@graphics@dimentopixels{\moodle@graphics@width@pixels}{#1}%
6860 }
6861 \setkeys{moodle@includegraphics}{height=0pt,width=0pt}
6862 % \end{macrocode}
6863 %
6864 % \subsubsection{Graphics conversion to HTML}
6865 % If the |tikz| option is loaded, we define the |embedaspict| command.
6866 % Furthermore, |includegraphics| is packed into a TikZ node.
6867 % This allows externalization with regular options for |includegraphics|.
6868 % Otherwise, |includegraphics| is redefined with a limited set of options supported.
6869 %
6870 % Option SVG
6871 % \begin{macrocode}
6872 \ifmoodle@svg
6873 \AtEndPreamble{%
6874 % Declaring \SVG\ to PDF conversion rule for includegraphics
6875 % \edef\Gin@extensions{\Gin@extensions,.svg,.SVG}%
6876 % \DeclareGraphicsRule{.svg}{pdf}{.pdf}{%
6877 % `\SVGtoPDF\otherspace '#1' \noexpand\[email protected]}%
6878 % \DeclareGraphicsRule{.SVG}{pdf}{.pdf}{%
6879 % `\SVGtoPDF\otherspace '#1' \noexpand\[email protected]}%
6880 \DeclareGraphicsAlien{.svg}{.pdf}{%
6881 \SVGtoPDF\otherspace \SourceFile\otherspace -o \otherspace\OutputFile\otherspace 2>\DevNull}%
6882 \DeclareGraphicsAlien{.SVG}{.pdf}{%
6883 \SVGtoPDF\otherspace \SourceFile\otherspace -o \otherspace\OutputFile\otherspace 2>\DevNull}%
6884 }%
6885 \fi
6886 \def\moodle@checkconversionsuccess#1#2{%
6887 \IfFileExists{#1}{}{%
6888 \PackageError{moodle}{#2 failed}%
6889 {If the XML file is not of importance to you: use package option "draft"}%
6890 }%
6891 }%
6892 \ifmoodle@tikz
6893 \AfterEndPreamble{%
6894 %\htmlize@record@expand{\embedaspict}%
6895 \let\oldincludegraphics=\includegraphics
6896 % patching includegraphics to trigger externalization
6897 \renewcommand{\includegraphics}[2][]{%
6898 %\message{moodle.sty: Processing \string\includegraphics[#1]{#2} for HTML^^J}%
6899 \tikz{\node[inner sep=0pt]{\oldincludegraphics[#1]{#2}};}%
6900 }%
6901 % externalized images must be included with the regular command
6902 \pgfkeys{/pgf/images/include external/.code={\oldincludegraphics{#1}}}%
6903 \html@action@newcommand{includegraphics}[2][]{%
6904 \message{moodle.sty: Processing \string\includegraphics[#1]{#2} ^^J}
6905 \global\advance\numpicturesread by 1\relax
6906 \edef\htmlize@imagetag{<IMG SRC="data:\TikzExportMIME;base64,\csname picbaselxiv@\the\numpicturesread\endcsname">}%
6907 \xa\g@addto@macro\xa\htmlize@output\xa{\htmlize@imagetag}%
6908 }%
6909 }%
6910 \else
6911 \html@action@newcommand{includegraphics}[2][]{%
6912 \bgroup% The grouping is to localize the changes caused by \setkeys.
6913 \message{moodle.sty: Processing \string\includegraphics[#1]{#2} for HTML...^^J}
6914 \setkeys*{moodle@includegraphics}{#1}%
6915 % Height or width should be given in TeX dimensions like cm or pt or in,
6916 % and are converted to pixels for web use using the ppi key.
6917 % TODO: Can we modify \includegraphics to accept height or width in
6918 % pixels?
6919 % TODO: What about \includegraphics[scale=0.7] ?
6920 % Other keys: keepaspectratio=true|false, angle (rotation), clip & trim
6921 % -> the package option 'tikz' offers a workaround for this
6922 \ifnum\moodle@graphics@height@pixels=0\relax
6923 \ifnum\moodle@graphics@width@pixels=0\relax
6924 % No size specified. Default to height of 200 pixels.
6925 \def\moodle@graphics@geometry{x200}%
6926 \def\moodle@graphics@htmlgeometry{}%
6927 \else
6928 % Width only specified.
6929 \edef\moodle@graphics@geometry{\number\moodle@graphics@width@pixels}%
6930 \edef\moodle@graphics@htmlgeometry{width=\number\moodle@graphics@width@pixels}%
6931 \fi
6932 \else
6933 \ifnum\moodle@graphics@width@pixels=0\relax
6934 % Height only specified. The `x' is part of the syntax.
6935 \edef\moodle@graphics@geometry{x\number\moodle@graphics@height@pixels}%
6936 \edef\moodle@graphics@htmlgeometry{height=\number\moodle@graphics@height@pixels}%
6937 \else
6938 % Height and width both specified. The `!' is part of the syntax.
6939 \edef\moodle@graphics@geometry{\number\moodle@graphics@width@pixels x\number\moodle@graphics@height@pixels!}%
6940 \edef\moodle@graphics@htmlgeometry{width=\number\moodle@graphics@width@pixels\otherspace height=\number\moodle@graphics@height@pixels}%
6941 \fi
6942 \fi
6943 %Look for the file, even if no extension is provided
6944 \moodle@media@find{#2}%
6945 %\message{<<\moodle@media@base>>^^J}
6946 %\message{<<\moodle@media@ext>>^^J}
6947 %Try to identify corresponding MIME-type
6948 \moodle@media@mime@identify{\moodle@media@ext}%
6949 \ifx\moodle@media@mime@current\relax
6950 % conversion needed
6951 \edef\moodle@media@pdf{\detokenize{.pdf}}%
6952 \edef\moodle@media@ext{\detokenize\xa{\moodle@media@ext}}%
6953 \ifnum0\ifx\moodle@media@ext\moodle@media@pdf1\fi\ifmoodle@svg1\fi=11\relax% PDF file and \SVG\ option active
6954 \def\moodle@media@ext@current{-moodle.svg}%
6955 \edef\moodle@media@mime@current{\moodle@media@SVGmime}%
6956 \edef\cmdline{\PDFtoSVG\otherspace "\moodle@media@base\moodle@media@ext" -o "\moodle@media@base\moodle@media@ext@current" 2>\DevNull}%
6957 \message{moodle.sty: Converting '#2' to SVG...^^J}%
6958 \xa\ShellEscape\xa{\cmdline}%
6959 \moodle@checkconversionsuccess{\moodle@media@base\moodle@media@ext@current}{PDFtoSVG conversion}%
6960 %Next, optimize inline
6961 \ifwindows\else
6962 \edef\cmdline{\optiSVG < "\moodle@media@base\moodle@media@ext@current" >
6963 "\moodle@[email protected]" && \MoveFiles\otherspace "\moodle@[email protected]"
6964 "\moodle@media@base\moodle@media@ext@current"}%
6965 \message{moodle.sty: Optimizing '\moodle@media@base\moodle@media@ext@current'...^^J}%
6966 \xa\ShellEscape\xa{\cmdline}%
6967 \moodle@checkconversionsuccess{\moodle@media@base\moodle@media@ext@current}{SVG optimization}%
6968 \fi
6969 \else% call ImageMagick
6970 \def\moodle@media@ext@current{-moodle.png}%
6971 \def\moodle@media@mime@current{image/png}%
6972 \edef\cmdline{\htmlize@imagemagick@convert\otherspace "\moodle@media@base\moodle@media@ext" -resize \moodle@graphics@geometry\otherspace "\moodle@media@base\moodle@media@ext@current"}%
6973 \message{moodle.sty: Converting '#2' to PNG...^^J}%
6974 \xa\ShellEscape\xa{\cmdline}%
6975 \moodle@checkconversionsuccess{\moodle@media@base\moodle@media@ext@current}{ImageMagick conversion}%
6976 %Next, optimize inline
6977 \edef\cmdline{\optipng\otherspace "\moodle@media@base\moodle@media@ext@current"}%
6978 \message{moodle.sty: Optimizing '\moodle@media@base\moodle@media@ext@current'...^^J}%
6979 \xa\ShellEscape\xa{\cmdline}%
6980 \moodle@checkconversionsuccess{\moodle@media@base\moodle@media@ext@current}{PNG optimization}%
6981 \fi
6982 \fi
6983 %Next, convert the file to base64 encoding
6984 \ConvertToBaseLXIV{\moodle@media@base}{\moodle@media@ext@current}%
6985 %Now, save that base64 encoding in a TeX macro
6986 \def\moodle@newpic@baselxiv{}%
6987 \message{moodle.sty: Reading base64 file '\moodle@[email protected]'...^^J}%
6988 \openin\baseLXIVdatafile="\moodle@[email protected]"\relax
6989 \ifeof\baseLXIVdatafile
6990 \PackageError{moodle}{reading '\moodle@[email protected]' failed}%
6991 {If the XML file is not of importance to you: use package option "draft"}%
6992 \else
6993 \savebaselxivdata@recursive
6994 \fi
6995 \closein\baseLXIVdatafile
6996 %Clean up files
6997 \ifx\moodle@media@ext@current\moodle@media@ext
6998 \ifwindows
6999 \ShellEscape{powershell.exe "del ""\moodle@[email protected]"""}%
7000 \else
7001 \ShellEscape{\DeleteFiles\otherspace "\moodle@[email protected]"}%
7002 \fi
7003 \else
7004 \ifwindows
7005 \ShellEscape{powershell.exe "del ""\moodle@[email protected]"""}%
7006 \ShellEscape{powershell.exe "del ""\moodle@media@base\moodle@media@ext@current"""}%
7007 \else
7008 \ShellEscape{\DeleteFiles\otherspace "\moodle@[email protected]" "\moodle@media@base\moodle@media@ext@current"}%
7009 \fi
7010 \fi
7011 \xa\global\xa\let\csname picbaselxiv@graphics@#2\endcsname=\moodle@newpic@baselxiv%
7012 \ifmoodle@pluginfile
7013 \edef\htmlize@imagetag{<IMG \moodle@graphics@htmlgeometry\otherspace SRC="@@PLUGINFILE@@/\moodle@media@base\moodle@media@ext@current">}%
7014 \xa\filename@parse\xa{\moodle@media@base}%
7015 \xdef\moodle@media@path{\filename@area}%
7016 \xdef\moodle@media@base{\filename@base}%
7017 \xa\g@addto@macro\xa\htmlize@embeddedfiletags\xa{<file name="\moodle@media@base}%
7018 \xa\g@addto@macro\xa\htmlize@embeddedfiletags\xa{\moodle@media@ext@current"}
7019 \xa\g@addto@macro\xa\htmlize@embeddedfiletags\xa{ path="/\moodle@media@path" encoding="base64">}%
7020 \xa\g@addto@macro\xa\htmlize@embeddedfiletags\xa{\csname picbaselxiv@graphics@#2\endcsname</file>}%
7021 \else
7022 \edef\htmlize@imagetag{<IMG \moodle@graphics@htmlgeometry\otherspace SRC="data:\moodle@media@mime@current;base64,\csname picbaselxiv@graphics@#2\endcsname">}%
7023 \fi
7024 \xa\g@addto@macro\xa\htmlize@output\xa{\htmlize@imagetag}%
7025 \message{moodle.sty: <IMG> tag inserted.^^J}%
7026 \egroup
7027 }%
7028 \fi
7029 % \end{macrocode}
7030 % This macro is in charge of throwing a system call to convert local files to base64.
7031 % \begin{macrocode}
7032 \def\ConvertToBaseLXIV#1#2{%
7033 \message{moodle.sty: Converting '#1#2' to base64...^^J}%
7034 \ConvertToBaseLXIV@int{#1}{#2}
7035 \xa\ShellEscape\xa{\cmdline}%
7036 \moodle@checkconversionsuccess{#1.enc}{Base64 conversion}%
7037 }%
7038 \ifwindows
7039 \def\ConvertToBaseLXIV@int#1#2{%
7040 \def\cmdline{\baselxiv\otherspace -encode "#1#2"\otherspace tmp.b64 && findstr /vbc:"---" tmp.b64 > "#1.enc" && powershell.exe "del tmp.b64"}%
7041 }% Starting from Windows 7, CertUtil is included by default. There should be no windows XP still running
7042 \else
7043 \ifmacosx
7044 \def\ConvertToBaseLXIV@int#1#2{%
7045 \def\cmdline{\baselxiv\otherspace -b 64 -i "#1#2"\otherspace -o "#1.enc"}%
7046 }%
7047 \else % Linux, Cygwin
7048 \def\ConvertToBaseLXIV@int#1#2{%
7049 \def\cmdline{\baselxiv\otherspace "#1#2"\otherspace > "#1.enc"}%
7050 }% base64 is part of coreutils, add "-w 64" to get exactly the previous behavior %
7051 \fi
7052 \fi
7053 % \end{macrocode}
7054 % The following code accomplishes the reading of an \filenm{.enc} file into memory.
7055 % It is also used by the \TikZ\ code below.
7056 % \begin{macrocode}
7057 \newread\baseLXIVdatafile
7058 \def\savebaselxivdata@recursive{%
7059 \ifeof\baseLXIVdatafile
7060 \let\baselxiv@next=\relax
7061 \else
7062 \read\baseLXIVdatafile to \datalinein
7063 %\message{<<\datalinein>>^^J}
7064 \ifx\datalinein\@moodle@par
7065 \let\baselxiv@next=\relax
7066 \else
7067 %We add tokens manually, rather than with \g@addto@macro, to save time.
7068 \xa\xa\xa\gdef\xa\xa\xa\moodle@newpic@baselxiv\xa\xa\xa{\xa\moodle@newpic@baselxiv\datalinein^^J}%
7069 \let\baselxiv@next=\savebaselxivdata@recursive
7070 \fi
7071 \fi
7072 \baselxiv@next
7073 }
7074 % \end{macrocode}
7075 %
7076 % \subsection{\TikZ\ Picture Handling}
7077 % If the user is not using the \TikZ\ package, there is no need to waste time
7078 % loading it. Without \TikZ\ loaded, however, many of the following commands
7079 % are undefined.
7080 % Our solution is to wait until |\AtBeginDocument| and then test whether
7081 % \TikZ\ is loaded. If so, we make the appropriate definitions.
7082 % \begin{macro}{TikZ}
7083 % \changes{v0.7}{2020/07/14}{Support \emph{tikz}\ command}
7084 % \begin{macrocode}
7085 \AtBeginDocument{
7086 \ifx\tikzpicture\@undefined
7087 \moodle@tikzloadedfalse
7088 \else
7089 \moodle@tikzloadedtrue
7090 \fi
7091 \ifmoodle@draftmode
7092 \long\def\tikzifexternalizing#1#2{#2}%
7093 \else
7094 \ifmoodle@tikzloaded
7095 \usetikzlibrary{external}%
7096 \tikzexternalize%
7097 \tikzset{external/force remake}%
7098 \def\moodle@basename{\tikzexternalrealjob-tikztemp-\the\numconvertedpictures}%
7099 \ifmoodle@svg
7100 \def\TikzExportExtension{.svg}%
7101 \def\TikzExportMIME{image/svg+xml}%
7102 \ifpdfoutput% tex engines defaulting to PDF output (pdflatex, xelatex, lualatex)
7103 \def\ExportTikz{ \message{moodle.sty: Converting picture '\[email protected]' to SVG...^^J}%
7104 \edef\cmdline{\PDFtoSVG\otherspace "\[email protected]" -o "\moodle@basename\TikzExportExtension" 2>\DevNull}%
7105 \message{\cmdline}
7106 \xa\ShellEscape\xa{\cmdline}%
7107 \moodle@checkconversionsuccess{\moodle@basename\TikzExportExtension}{PDFtoSVG conversion}%
7108 }%
7109 \else % latex
7110 \def\ExportTikz{ \message{moodle.sty: Converting picture '\[email protected]' to SVG...^^J}%
7111 \edef\cmdline{\PDFtoSVG\otherspace "\[email protected]" -o "\moodle@basename\TikzExportExtension" 2>\DevNull}%
7112 \message{\cmdline}
7113 \xa\ShellEscape\xa{\cmdline}%
7114 \moodle@checkconversionsuccess{\moodle@basename\TikzExportExtension}{PStoSVG conversion}%
7115 }%
7116 \fi
7117 \ifwindows
7118 \def\OptimizeExport{ \message{moodle.sty: Optimizing '\[email protected]'...^^J}%
7119 \edef\cmdline{\optiSVG\otherspace < "\moodle@basename\TikzExportExtension" >
7120 "\[email protected]" && powershell.exe "move ""\[email protected]""" %
7121 """\moodle@basename\TikzExportExtension"""}%
7122 \message{\cmdline}
7123 \xa\ShellEscape\xa{\cmdline}%
7124 \moodle@checkconversionsuccess{\moodle@basename\TikzExportExtension}{SVG optimization}%
7125 }%
7126 \else
7127 \def\OptimizeExport{ \message{moodle.sty: Optimizing '\[email protected]'...^^J}%
7128 \edef\cmdline{\optiSVG\otherspace < "\moodle@basename\TikzExportExtension" >
7129 "\[email protected]" && \MoveFiles\otherspace "\[email protected]"
7130 "\moodle@basename\TikzExportExtension" }%
7131 \message{\cmdline}
7132 \xa\ShellEscape\xa{\cmdline}%
7133 \moodle@checkconversionsuccess{\moodle@basename\TikzExportExtension}{SVG optimization}%
7134 }%
7135 \fi
7136 \else
7137 \def\TikzExportExtension{.png}%
7138 \def\TikzExportMIME{image/png}%
7139 \ifpdfoutput% tex engines defaulting to PDF output (pdflatex, xelatex, lualatex)
7140 \def\ExportTikz{ \message{moodle.sty: Converting picture '\[email protected]' to PNG...^^J}%
7141 \edef\gscmdline{\gs\otherspace -sOutputFile=\moodle@basename\TikzExportExtension\otherspace -r150 \[email protected]}%
7142 \xa\ShellEscape\xa{\gscmdline}%
7143 \moodle@checkconversionsuccess{\moodle@basename\TikzExportExtension}{Ghostscript conversion}%
7144 }%
7145 \else % latex
7146 \def\ExportTikz{ \message{moodle.sty: Converting picture '\[email protected]' to PNG...^^J}%
7147 \edef\gscmdline{\gs\otherspace -sOutputFile=\moodle@basename\TikzExportExtension\otherspace -r150 \\[email protected]}%
7148 \xa\ShellEscape\xa{\gscmdline}%
7149 \moodle@checkconversionsuccess{\moodle@basename\TikzExportExtension}{Ghostscript conversion}%
7150 }%
7151 \fi
7152 \def\OptimizeExport{ \message{moodle.sty: Optimizing '\[email protected]'...^^J}%
7153 \edef\cmdline{\optipng\otherspace \moodle@basename\TikzExportExtension}%
7154 \xa\ShellEscape\xa{\cmdline}%
7155 \moodle@checkconversionsuccess{\moodle@basename\TikzExportExtension}{PNG optimization}%
7156 }%
7157 \fi
7158 \let\moodle@oldtikzpicture=\tikzpicture
7159 %The following code lets us run things *before* the normal \begin{tikzpicture}.
7160 \renewenvironment{tikzpicture}{%
7161 \global\advance\numconvertedpictures by 1\relax
7162 %\jobnamewithsuffixtomacro{\htmlize@picbasename}{-tikztemp-\the\numconvertedpictures}%
7163 %\xa\tikzsetnextfilename\xa{\htmlize@picbasename}%
7164 \tikzsetnextfilename{\tikzexternalrealjob-tikztemp-\the\numconvertedpictures}%
7165 \moodle@oldtikzpicture%
7166 }{}%
7167 % However, the tikz externalize library does *not* run \end{tikzpicture}.
7168 % In order to run commands after the tikz picture is done compiling, we need to
7169 % use a hook into \tikzexternal@closeenvironments.
7170 \g@addto@macro{\tikzexternal@closeenvironments}{%
7171 \moodle@endtikzpicture@hook
7172 }
7173 % The following could replace calls to \pdftopng, \pngoptim and \pngtobaselxiv
7174 % \tikzset{external/system call/.add={}{;
7175 % gs -dBATCH -dNOPAUSE -sDEVICE=pngalpha -sOutputFile="\image.png" -r150 "\image.pdf";
7176 % optipng -clobber -strip all -quiet "\image.png";
7177 % base64 "\image.png" > "\image.enc"
7178 % }
7179 % }
7180 % With the following mechanism, we could trigger something when the externalized images are included back.
7181 % \pgfkeys{/pgf/images/include external/.code={\pgfimage{#1}\@moodle@ifgeneratexml{\savebaselxivdata}{}}}
7182 %
7183 \def\moodle@endtikzpicture@hook{%
7184 \@moodle@ifgeneratexml{%
7185 \ExportTikz
7186 \OptimizeExport
7187 \ConvertToBaseLXIV{\moodle@basename}{\TikzExportExtension}%
7188 \IfFileExists{\[email protected]}{}{\PackageError{moodle}{Conversion failed}{Check your base64 conversion utiliy}}%
7189 \message{moodle.sty: Reading base64 file '\tikzexternalrealjob-tikztemp-\the\numconvertedpictures.enc'...^^J}%
7190 \savebaselxivdata
7191 \message{moodle.sty: base64 data saved.^^J}%
7192 }{}%
7193 }
7194 \ifmoodle@tikz
7195 \tikzset{external/optimize=false}% due to redefinition, includegraphics must not be optimized away
7196 \else
7197 \tikzset{external/optimize=true}%
7198 \tikzset{external/optimize command away={\VerbatimInput}{1}}%
7199 \fi
7200 %
7201 % The HTMLizer version of the tikzpicture environment,
7202 % which writes an <IMG> tag to the \XML\ file.
7203 \htmlize@record@environment{tikzpicture}%
7204 \g@addto@macro\htmlize@activate@environments{%
7205 \let\tikzpicture\relax\let\endtikzpicture\relax
7206 \NewEnviron{tikzpicture}[1][]{%
7207 \global\advance\numpicturesread by 1\relax
7208 \ifmoodle@pluginfile
7209 \edef\htmlize@imagetag{<IMG SRC="@@PLUGINFILE@@/tikz/\tikzexternalrealjob-tikztemp-\the\numpicturesread\TikzExportExtension">}%
7210 \xa\g@addto@macro\xa\htmlize@embeddedfiletags\xa{<file name="\tikzexternalrealjob-tikztemp-}%
7211 \xa\g@addto@macro\xa\htmlize@embeddedfiletags\xa{\the\numpicturesread}%
7212 \xa\g@addto@macro\xa\htmlize@embeddedfiletags\xa{\TikzExportExtension"}
7213 \xa\g@addto@macro\xa\htmlize@embeddedfiletags\xa{ path="/tikz/" encoding="base64">}%
7214 \xa\g@addto@macro\xa\htmlize@embeddedfiletags\xa{\csname picbaselxiv@\the\numpicturesread\endcsname</file>}%
7215 \else
7216 \edef\htmlize@imagetag{<IMG SRC="data:\TikzExportMIME;base64,\csname picbaselxiv@\the\numpicturesread\endcsname">}%
7217 \fi
7218 \xa\g@addto@macro\xa\htmlize@output\xa{\htmlize@imagetag}%
7219 }[\htmlize@patchendenvironment]%
7220 }%
7221 \html@action@newcommand{tikz}[2][]{%
7222 % \message{>>> Processing \string\tikz[#1]{...} ^^J}
7223 \global\advance\numpicturesread by 1\relax
7224 \ifmoodle@pluginfile
7225 \edef\htmlize@imagetag{<IMG SRC="@@PLUGINFILE@@/tikz/\tikzexternalrealjob-tikztemp-\the\numpicturesread\TikzExportExtension">}%
7226 \xa\g@addto@macro\xa\htmlize@embeddedfiletags\xa{<file name="\tikzexternalrealjob-tikztemp-}%
7227 \xa\g@addto@macro\xa\htmlize@embeddedfiletags\xa{\the\numpicturesread}%
7228 \xa\g@addto@macro\xa\htmlize@embeddedfiletags\xa{\TikzExportExtension"}
7229 \xa\g@addto@macro\xa\htmlize@embeddedfiletags\xa{ path="/tikz/" encoding="base64">}%
7230 \xa\g@addto@macro\xa\htmlize@embeddedfiletags\xa{\csname picbaselxiv@\the\numpicturesread\endcsname</file>}%
7231 \else
7232 \edef\htmlize@imagetag{<IMG SRC="data:\TikzExportMIME;base64,\csname picbaselxiv@\the\numpicturesread\endcsname">}%
7233 \fi
7234 \xa\g@addto@macro\xa\htmlize@output\xa{\htmlize@imagetag}%
7235 }%
7236 \else
7237 %TikZ not loaded. Provide dummy definitions for commands.
7238 \long\def\tikzifexternalizing#1#2{#2}%
7239 \fi
7240 \fi
7241 \ifmoodle@tikz
7242 \tikzstyle{moodlepict}=[minimum height=1em,inner sep=0pt,execute at begin node={\begin{varwidth}{\linewidth}},execute at end node={\end{varwidth}}]
7243 \newcommand\embedaspict[1]{\tikz[baseline=-\the\dimexpr\fontdimen22\textfont2\relax]{\node[moodlepict]{\mbox{#1}};}}
7244 \htmlize@record@expand{\embedaspict}
7245 \fi
7246 }
7247
7248 \newcount\numconvertedpictures
7249 \numconvertedpictures=0\relax
7250 \newcount\numpicturesread
7251 \numpicturesread=0\relax
7252
7253 \def\savebaselxivdata{%
7254 \def\moodle@newpic@baselxiv{}%
7255 \openin\baseLXIVdatafile=\tikzexternalrealjob-tikztemp-\the\numconvertedpictures.enc\relax
7256 \ifeof\baseLXIVdatafile
7257 \PackageError{moodle}{reading '\moodle@[email protected]' failed}%
7258 {If the XML file is not of importance to you: use package option "draft"}%
7259 \else
7260 \savebaselxivdata@recursive
7261 \fi
7262 \closein\baseLXIVdatafile
7263 \xa\global\xa\let\csname picbaselxiv@\the\numconvertedpictures\endcsname=\moodle@newpic@baselxiv%
7264 }
7265
7266 \ifmoodle@tikz
7267 \ifmoodle@tikzloaded
7268 \PackageWarning{moodle}{With package option 'tikz', you should not load TikZ manually.}%
7269 \fi
7270 \RequirePackage{tikz}%
7271 \RequirePackage{varwidth}% for the command |embedaspict|
7272 \fi
7273 % \end{macrocode}
7274 % Finally, we clean up our mess by deleting the temporary PDF, \PNG, and ENC
7275 % files we created.
7276 % With XeTeX, we cannot clean pictures pdf's because they are actually included in the final pdf afterwards, by xdvipdfmx.
7277 % With LuaTeX, it looks like |\AtEndDocument| is too early to for this cleaning step.
7278 % \begin{macrocode}
7279 \AfterEndDocument{%
7280 \ifmoodle@tikzloaded
7281 \@moodle@ifgeneratexml{%
7282 \ifXeTeX
7283 % we must keep picture pdf's for subsequent linking (xdvipdfmx)
7284 \ifwindows
7285 \ShellEscape{powershell.exe "del * -include \tikzexternalrealjob-tikztemp-*.* -exclude *.pdf"}%
7286 \else
7287 \ShellEscape{find . -type f -name "\tikzexternalrealjob-tikztemp-*.*" -not -name "*.pdf" -delete}%
7288 \fi
7289 \else
7290 \ifwindows
7291 \ShellEscape{powershell.exe "del \tikzexternalrealjob-tikztemp-*.*"}%
7292 \else
7293 \ShellEscape{\DeleteFiles\otherspace \tikzexternalrealjob-tikztemp-*.*}%
7294 \fi
7295 \fi
7296 }{}%
7297 \fi
7298 }
7299 % \end{macrocode}
7300 % TODO:
7301 % * sizing options for TikZ pictures?
7302 %\end{macro}
7303 %
7304 % \subsection{Other Media}
7305 % Support for other media comes through the |\url|\marg{link} and |\href|\marg{link}\marg{text}
7306 % commands.
7307 % \begin{macrocode}
7308 \AtEndPreamble{%
7309 \@ifpackageloaded{hyperref}{%
7310 \let\oldhref\href
7311 \let\oldurl\url
7312 \def\moodle@hyper@readexternallink#1#2#3#4:#5:#6\\#7{%
7313 % 1) The link type (the string "link" in the cases I observed)
7314 % 2) The URL fragment (i.e. what comes after # in the end),
7315 % 3) the text replacement,
7316 % 4) the URL scheme (http, https, mailto, file, run etc),
7317 % 5) the URL details (in general, that is whole authority + path + query).
7318 % If the URL contains a column (specification of a password in userinfo or a
7319 % port in authority), we get here whatever comes before the first column (:)
7320 % 6) empty is URL contains no column. Otherwise, filled with whatever follows
7321 % a first column (:) after the scheme,
7322 % 7) the whole URL again (fragment removed).
7323 \def\filename@ext{}%
7324 \def\filename@area{}%
7325 \def\filename@base{}%
7326 \ifx\\#6\\% if ##6 is empty (the URL contains no column -> no scheme -> local)
7327 %\@hyper@linkfile file:#7\\{#3}{#2}{#7}% local file
7328 %Local file (##1|##2|##3|##4|##5|##6): ##7\par
7329 \filename@parse{#4}%
7330 \ConvertToBaseLXIV{\filename@area\filename@base}{.\filename@ext}%
7331 \else
7332 \ifx\\#4\\%if ##4 is empty (no scheme was specified -> local file)
7333 % %\@hyper@linkfile file:#7\\{#3}{#2}{#7}% Mac filename ?
7334 % Local file (Mac? ##1|##2|##3|##4|##5|##6): ##7\par
7335 \filename@parse{#4}%
7336 \ConvertToBaseLXIV{\filename@area\filename@base}{.\filename@ext}%
7337 \else
7338 \def\@pdftempa{#4}%
7339 \ifx\@pdftempa\@pdftempwordfile% scheme is "file:"
7340 % %\@hyper@linkfile#7\\{#3}{#2}{#7}% file
7341 % Local file (no column ##1|##2|##3|##4|##5|##6): ##7\par
7342 \filename@parse{#5}%
7343 \ConvertToBaseLXIV{\filename@area\filename@base}{.\filename@ext}%
7344 \else
7345 \ifx\@pdftempa\@pdftempwordrun% scheme is "run:"
7346 \ifHy@pdfa
7347 \Hy@Error{%
7348 PDF/A: Launch action is prohibited%
7349 }\@ehc
7350 \begingroup
7351 \leavevmode
7352 % ##2%
7353 \endgroup
7354 \else% not in PDF/A mode -> run is allowed
7355 %\@hyper@launch#7\\{#3}{#2}% run local file
7356 % Run local file (##1|##2|##3|##4|##5|##6): ##7\par
7357 \filename@parse{#5}%
7358 \ConvertToBaseLXIV{\filename@area\filename@base}{.\filename@ext}%
7359 \fi
7360 \else% scheme is neither "file" nor "run", assuming it is a web protocol
7361 %\hyper@linkurl{#3}{#7\ifx\\#2\\\else\hyper@hash#2\fi}% URL
7362 % URL (##1|##2|##3|##4|##5|##6): ##7\par
7363 \filename@parse{#7}%
7364 \fi
7365 \fi
7366 \fi
7367 \fi
7368 \xdef\moodle@media@ext{.\filename@ext}%
7369 \xdef\moodle@media@base{\filename@area\filename@base}%
7370 }%
7371 % \html@action@newcommand{href}[3][]{%
7372 % \bgroup% The grouping is to localize the changes caused by \setkeys.
7373 % \message{moodle.sty: Processing \string\href[#1]{#2}{#3} for HTML...^^J}%
7374 % the following macro is a modified version of hyperref's |\hyper@readexternallink|
7375 % \let\@hyper@readexternallink\moodle@hyper@readexternallink
7376 % \oldhref[#1]{#2}{#3}%
7377 %\message{<<\moodle@media@base>>^^J}
7378 %\message{<<\moodle@media@ext>>^^J}
7379 %Try to identify corresponding MIME-type
7380 % \moodle@media@mime@identify{\moodle@media@ext}%
7381 %\edef\moodle@media@mime@current{\detokenize\xa{\moodle@media@mime@current}}%
7382 % \xa\message\xa{moodle.sty: \moodle@media@mime@current^^J}%
7383 % \ifx\moodle@media@mime@current\relax
7384 % \xa\g@addto@macro\xa\htmlize@output\xa{<A href=\otherampersand\otherhash34;\moodle@media@base\moodle@media@ext\otherampersand\otherhash34;>#3</A>}%
7385 % \message{moodle.sty: <A> tag inserted.^^J}%
7386 % \else
7387 % \filename@parse{\moodle@media@mime@current}%
7388 % \def\@tmp{audio/}
7389 % \ifx\filename@area\@tmp
7390 % \IfFileExists{\moodle@[email protected]}{%
7391 % \def\moodle@newpic@baselxiv{}%
7392 % \openin\baseLXIVdatafile=\moodle@[email protected]\relax
7393 % \savebaselxivdata@recursive
7394 % \closein\baseLXIVdatafile
7395 % \xa\g@addto@macro\xa\htmlize@output\xa{<audio controls src="data:\moodle@media@mime@current;base64,\moodle@newpic@baselxiv">#3</audio>}%
7396 % }{%
7397 % \xa\g@addto@macro\xa\htmlize@output\xa{<audio controls src="\moodle@media@base\moodle@media@ext">#3</audio>}%
7398 % }%
7399 % \message{moodle.sty: <audio> tag inserted.^^J}%
7400 % \else
7401 % \def\@tmp{video/}
7402 % \ifx\filename@area\@tmp
7403 % \IfFileExists{\moodle@[email protected]}{%
7404 % \def\moodle@newpic@baselxiv{}%
7405 % \openin\baseLXIVdatafile=\moodle@[email protected]\relax
7406 % \savebaselxivdata@recursive
7407 % \closein\baseLXIVdatafile
7408 % \xa\g@addto@macro\xa\htmlize@output\xa{<video controls src="data:\moodle@media@mime@current;base64,\moodle@newpic@baselxiv">#3</video>}%
7409 % }{%
7410 % \xa\g@addto@macro\xa\htmlize@output\xa{<video controls src="\moodle@media@base\moodle@media@ext">#3</video>}%
7411 % }%
7412 % \message{moodle.sty: <video> tag inserted.^^J}%
7413 % \else
7414 % \PackageWarning{moodle}{cannot recognize MIME type of #2. Ignoring it.}%
7415 % \fi
7416 % \fi
7417 % \fi
7418 % \egroup
7419 % }%
7420 % \html@action@def\url#1{%
7421 % \bgroup% The grouping is to localize the changes caused by \setkeys.
7422 % \message{moodle.sty: Processing \string\url{#1} for HTML...^^J}%
7423 % the following macro is a modified version of hyperref's |\hyper@readexternallink|
7424 % \let\@hyper@readexternallink\moodle@hyper@readexternallink
7425 % \oldhref{#1}{#1}%
7426 % \xa\g@addto@macro\xa\htmlize@output\xa{<A href=\otherampersand\otherhash34;\moodle@media@base\moodle@media@ext\otherampersand\otherhash34;>#1</A>}%
7427 % \message{moodle.sty: <A> tag inserted.^^J}%
7428 % \egroup
7429 % }%
7430 }{}%
7431 }%
7432 % \end{macrocode}
7433 %
7434 % \subsection{Verbatim Code}
7435 %
7436 % We start by defining a macro to parameter a style for code box display in Moodle
7437 % \begin{macrocode}
7438 \def\xmlDisplayVerbatimBox{border-top: thin solid; border-bottom: thin solid}%
7439 % \end{macrocode}
7440 % Then we set a macro to escape some characters that would not play well with \HTML.
7441 % \begin{macrocode}
7442 \begingroup
7443 \catcode`\<=\active\relax
7444 \catcode`\>=\active\relax
7445 \catcode`\"=\active\relax
7446 \catcode`\'=\active\relax
7447 \catcode`\&=\active\relax
7448 \gdef\moodle@HackTML{%
7449 \catcode`\<=\active\relax
7450 \catcode`\>=\active\relax
7451 \catcode`\"=\active\relax
7452 \catcode`\'=\active\relax
7453 \catcode`\&=\active\relax
7454 \gdef<{\otherampersand lt;}%
7455 \gdef>{\otherampersand gt;}%
7456 \gdef"{\otherampersand quot;}%
7457 \gdef'{\otherampersand apos;}%
7458 \gdef&{\otherampersand amp;}%
7459 }%
7460 \endgroup
7461 % \end{macrocode}
7462 % First, let us handle |\verbatiminput| from the `verbatim' package
7463 % \begin{macrocode}
7464 \html@action@def\verbatiminput#1{%
7465 \message{moodle.sty: Processing \string\verbatiminput{#1} for HTML ^^J}%
7466 \g@addto@macro\htmlize@output{<PRE style="\xmlDisplayVerbatimBox"><CODE>}%
7467 %%%%%%%%%%%%%% from verbatim %%%%%%%%%%%%%%%%%
7468 \@bsphack
7469 \let\do\@makeother\dospecials
7470 \catcode`\^^M\active
7471 \moodle@HackTML
7472 \def\verbatim@processline{\xa\g@addto@macro\xa\htmlize@output\xa{\the\verbatim@line<BR/>}}
7473 \verbatim@readfile{#1}%
7474 \@esphack
7475 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7476 \g@addto@macro\htmlize@output{</CODE></PRE>}%
7477 }%
7478 % \end{macrocode}
7479 % Second, we deal with |\VerbatimInput| from `fancyvrb' or `fvextra'
7480 % \begin{macrocode}
7481 \@ifpackageloaded{minted}{\PackageError{moodle}{'moodle' should be loaded before 'minted'.}%
7482 {'moodle' loads 'fancybox' which, unfortunately, redefines verbatim commands.}}{\relax}%
7483 \@ifpackageloaded{fvextra}{\PackageError{moodle}{'moodle' should be loaded before 'fvextra'.}%
7484 {'moodle' loads 'fancybox' which, unfortunately, redefines verbatim commands.}}{\relax}%
7485 \@ifpackageloaded{fancyvrb}{\PackageError{moodle}{'moodle' should be loaded before 'fancyvrb'.}%
7486 {'moodle' loads 'fancybox' which, unfortunately, redefines verbatim commands.}}{\relax}%
7487
7488 \def\moodle@FV#1{%
7489 \html@action@newcommand{#1}[2][]{%
7490 \message{moodle.sty: Processing \@backslashchar#1[##1]{##2} for HTML ^^J}%
7491 \def\FV@KeyValues{##1}%
7492 \FV@UseKeyValues% import options defined in #1
7493 \def\FV@Input####1{
7494 \immediate\openin\FV@InFile ####1\relax
7495 \ifeof\FV@InFile
7496 \FV@Error{No verbatim file ####1}\FV@eha
7497 \immediate\closein\FV@InFile
7498 \else
7499 \FV@CatCodes
7500 \moodle@HackTML
7501 \expandafter\FV@@Input
7502 \fi}%
7503 \moodle@VerbatimInput{##2}%
7504 }%
7505 }
7506 \moodle@FV{VerbatimInput}%
7507 \moodle@FV{LVerbatimInput}%
7508 \moodle@FV{BVerbatimInput}%
7509 \def\moodle@VerbatimInput#1{%
7510 \g@addto@macro\htmlize@output{<PRE style="\xmlDisplayVerbatimBox"><CODE>}%
7511 %%%%%%%% using material from fancyvrb and fvextra %%%%%%%%
7512 %\begingroup
7513 \def\moodle@verbatim@addlinenumber##1{%
7514 \g@addto@macro\htmlize@output{<span style="font-size: 80\otherpercent;
7515 background-color: \otherhash f0f0f0; padding: 0 5px 0 5px; display:
7516 inline-block; width: 16pt; ##1">}%
7517 \if@FV@NumberBlankLines
7518 \xa\g@addto@macro\xa\htmlize@output\xa{\the\c@FancyVerbLine</span>}%
7519 \else
7520 \ifx\FV@Line\empty
7521 \xa\g@addto@macro\xa\htmlize@output\xa{\otherampersand nbsp;</span>}%
7522 \else
7523 \xa\g@addto@macro\xa\htmlize@output\xa{\the\c@FancyVerbLine</span>}%
7524 \fi
7525 \fi
7526 }
7527 % redefine the ProcessLine routine ('fancyvrb' and 'fvextra') for \XML\ output
7528 \def\FV@ProcessLine##1{%
7529 \ifcsname FV@HighlightLine:\number\c@FancyVerbLine\endcsname
7530 \xdef\moodle@FV@tagB{<mark>}% fvextra triggered highlighting for this line
7531 \xdef\moodle@FV@tagE{</mark>}%
7532 \else
7533 \xdef\moodle@FV@tagB{}% no highlighting
7534 \xdef\moodle@FV@tagE{}%
7535 \fi
7536 \catcode`\`=12%
7537 \def\FV@Line{##1}%
7538 \ifx\FV@LeftListNumber\relax
7539
7540 \else% line numbers displayed on the left side
7541 \moodle@verbatim@addlinenumber{text-align: right}%
7542 \fi
7543 \xa\g@addto@macro\xa\htmlize@output\xa{\moodle@FV@tagB}%
7544 \xa\g@addto@macro\xa\htmlize@output\xa{\FV@Line}%
7545 \xa\g@addto@macro\xa\htmlize@output\xa{\moodle@FV@tagE}%
7546 \ifx\FV@RightListNumber\relax\else% line numbers on the right side
7547 \moodle@verbatim@addlinenumber{text-align: left; float: right}%
7548 \fi
7549 \g@addto@macro\htmlize@output{<BR/>}%linebreak
7550 }
7551 \global\FV@CodeLineNo\z@% reset codeline counter
7552 \frenchspacing% Cancels special punctuation spacing.
7553 \FV@DefineWhiteSpace
7554 \def\FV@Space{\space}
7555 \FV@DefineTabOut% replace tabs with a series a whitespaces
7556 \ifdefined\FV@HighlightLinesPrep
7557 \FV@HighlightLinesPrep% prepare highlighting if 'fvextra' is loaded
7558 \fi
7559 \FV@Input{#1}%
7560 %\endgroup
7561 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7562 \g@addto@macro\htmlize@output{</CODE></PRE>}%
7563 }%
7564 \AtEndPreamble{%
7565 \@ifpackageloaded{fancyvrb}{%
7566 % custom settings for display
7567 \fvset{frame=lines,label={[Beginning of code]End of code},framesep=3mm,numbersep=9pt}%
7568 }{\relax}%
7569 }
7570 % \end{macrocode}
7571 % Third, we patch `minted' so that it also calls pygmentize to generate \HTML\ code.
7572 % \begin{macrocode}
7573 \AtEndPreamble{% this definition should prevail because `minted' gets loaded after `moodle'
7574 \@ifpackageloaded{minted}{%
7575 \newcounter{moodle@pygmentizecounter}%
7576 \@ifundefined{minted@defstyle}{% compatibility with minted prior to 2021/12/24 v2.6
7577 \let\minted@defstyle=\minted@checkstyle%
7578 }{}%
7579 \renewcommand{\minted@pygmentize}[2][\minted@outputdir\[email protected]]{%
7580 \minted@defstyle{\minted@get@opt{style}{default}}%
7581 \stepcounter{minted@pygmentizecounter}%
7582 \ifthenelse{\equal{\minted@get@opt{autogobble}{false}}{true}}%
7583 {\def\minted@codefile{\minted@outputdir\[email protected]}}%
7584 {\def\minted@codefile{#1}}%
7585 \ifthenelse{\boolean{minted@isinline}}%
7586 {\def\minted@optlistcl@inlines{%
7587 \minted@optlistcl@g@i
7588 \csname minted@optlistcl@lang\minted@lang @i\endcsname}}%
7589 {\let\minted@optlistcl@inlines\@empty}%
7590 \def\minted@cmdtemplate##1##2{%
7591 \ifminted@kpsewhich
7592 \ifwindows
7593 \detokenize{for /f "usebackq tokens=*"}\space\@percentchar\detokenize{a
7594 in (`kpsewhich}\space\minted@codefile\detokenize{`) do}\space
7595 \fi
7596 \fi
7597 \MintedPygmentize\space -l #2 -f ##1 -F tokenmerge
7598 \minted@optlistcl@g \csname minted@optlistcl@lang\minted@lang\endcsname
7599 \minted@optlistcl@inlines
7600 \minted@optlistcl@cmd -o \minted@outputdir##2\space
7601 \ifminted@kpsewhich
7602 \ifwindows
7603 \@percentchar\detokenize{a}%
7604 \else
7605 \detokenize{`}kpsewhich \minted@codefile\space
7606 \detokenize{||} \minted@codefile\detokenize{`}%
7607 \fi
7608 \else
7609 \minted@codefile
7610 \fi}%
7611 \def\minted@cmd{\minted@cmdtemplate{latex -P commandprefix=PYG}{\minted@infile}}
7612 % For debugging, uncomment: %%%%
7613 %\immediate\typeout{\minted@cmd}%
7614 % %%%%
7615 \def\minted@cmdHTML{\minted@cmdtemplate{html -P noclasses -P
7616 nowrap -P hl_lines="\FV@HighlightLinesList" -P
7617 style="\minted@get@opt{style}{default}"}{\csname minted@infileHTML\the\c@minted@pygmentizecounter\endcsname}}%
7618 \def\minted@cmdPNG{\minted@cmdtemplate{png -P
7619 line_numbers=True}{\minted@infilePNG}}%
7620 \def\minted@cmdSVG{\minted@cmdtemplate{svg -P
7621 linenos=True}{\minted@infileSVG}}%
7622 \ifthenelse{\boolean{minted@cache}}%
7623 {%
7624 \ifminted@frozencache
7625 \else
7626 \ifx\XeTeXinterchartoks\minted@undefined
7627 \ifthenelse{\equal{\minted@get@opt{autogobble}{false}}{true}}%
7628 {\edef\minted@hash{\pdf@filemdfivesum{#1}%
7629 \pdf@mdfivesum{\minted@cmd autogobble(\ifx\FancyVerbStartNum\z@
7630 0\else\FancyVerbStartNum\fi-\ifx\FancyVerbStopNum\z@
7631 0\else\FancyVerbStopNum\fi)}}}%
7632 {\edef\minted@hash{\pdf@filemdfivesum{#1}%
7633 \pdf@mdfivesum{\minted@cmd}}}%
7634 \else
7635 \ifx\mdfivesum\minted@undefined
7636 \immediate\openout\minted@code\[email protected]\relax
7637 \immediate\write\minted@code{\minted@cmd}%
7638 \ifthenelse{\equal{\minted@get@opt{autogobble}{false}}{true}}%
7639 {\immediate\write\minted@code{autogobble(\ifx\FancyVerbStartNum\z@
7640 0\else\FancyVerbStartNum\fi-\ifx\FancyVerbStopNum\z@
7641 0\else\FancyVerbStopNum\fi)}}{}%
7642 \immediate\closeout\minted@code
7643 \edef\minted@argone@esc{#1}%
7644 \StrSubstitute{\minted@argone@esc}{\@backslashchar}{\@backslashchar\@backslashchar}[\minted@argone@esc]%
7645 \StrSubstitute{\minted@argone@esc}{"}{\@backslashchar"}[\minted@argone@esc]%
7646 \edef\minted@tmpfname@esc{\minted@outputdir\minted@jobname}%
7647 \StrSubstitute{\minted@tmpfname@esc}{\@backslashchar}{\@backslashchar\@backslashchar}[\minted@tmpfname@esc]%
7648 \StrSubstitute{\minted@tmpfname@esc}{"}{\@backslashchar"}[\minted@tmpfname@esc]%
7649 %Cheating a little here by using ASCII codes to write `{` and `}`
7650 %in the Python code
7651 \def\minted@hashcmd{%
7652 \detokenize{python -c "import hashlib; import os;
7653 hasher = hashlib.sha1();
7654 f =
7655 open(os.path.expanduser(os.path.expandvars(\"}\minted@[email protected]\detokenize{\")),
7656 \"rb\");
7657 hasher.update(f.read());
7658 f.close();
7659 f =
7660 open(os.path.expanduser(os.path.expandvars(\"}\minted@argone@esc\detokenize{\")),
7661 \"rb\");
7662 hasher.update(f.read());
7663 f.close();
7664 f =
7665 open(os.path.expanduser(os.path.expandvars(\"}\minted@[email protected]\detokenize{\")),
7666 \"w\");
7667 macro = \"\\edef\\minted@hash\" + chr(123) + hasher.hexdigest()
7668 + chr(125) + \"\";
7669 f.write(\"\\makeatletter\" + macro +
7670 \"\\makeatother\\endinput\n\");
7671 f.close();"}}%
7672 \ShellEscape{\minted@hashcmd}%
7673 \minted@input{\minted@outputdir\[email protected]}%
7674 \else
7675 \ifthenelse{\equal{\minted@get@opt{autogobble}{false}}{true}}%
7676 {\edef\minted@hash{\mdfivesum file {#1}%
7677 \mdfivesum{\minted@cmd autogobble(\ifx\FancyVerbStartNum\z@
7678 0\else\FancyVerbStartNum\fi-\ifx\FancyVerbStopNum\z@
7679 0\else\FancyVerbStopNum\fi)}}}%
7680 {\edef\minted@hash{\mdfivesum file {#1}%
7681 \mdfivesum{\minted@cmd}}}%
7682 \fi
7683 \fi
7684 \edef\minted@infile{\minted@cachedir/\[email protected]}%
7685 \edef\minted@temp@infileHTML{\minted@cachedir/\[email protected]}%
7686 \global\cslet{minted@infileHTML\the\c@minted@pygmentizecounter}{\minted@temp@infileHTML}%
7687 %\global\edef\minted@infilePNG{\minted@cachedir/\[email protected]}%
7688 %\global\edef\minted@infileSVG{\minted@cachedir/\[email protected]}%
7689 \IfFileExists{\minted@infile}{}{%
7690 \ifthenelse{\equal{\minted@get@opt{autogobble}{false}}{true}}{%
7691 \minted@autogobble{#1}}{}%
7692 \ShellEscape{\minted@cmd}%
7693 \ShellEscape{\minted@cmdHTML}%
7694 %\ShellEscape{\minted@cmdPNG}%
7695 %\ShellEscape{\minted@cmdSVG}%
7696 }%
7697 \fi
7698 \ifthenelse{\boolean{minted@finalizecache}}%
7699 {%
7700 \edef\minted@cachefilename{listing\arabic{minted@pygmentizecounter}.pygtex}%
7701 \edef\minted@actualinfile{\minted@cachedir/\minted@cachefilename}%
7702 \ifwindows
7703 \StrSubstitute{\minted@infile}{/}{\@backslashchar}[\minted@infile@windows]
7704 \StrSubstitute{\minted@actualinfile}{/}{\@backslashchar}[\minted@actualinfile@windows]
7705 \ShellEscape{move /y
7706 \minted@outputdir\minted@infile@windows\space\minted@outputdir\minted@actualinfile@windows}%
7707 \else
7708 \ShellEscape{mv -f
7709 \minted@outputdir\minted@infile\space\minted@outputdir\minted@actualinfile}%
7710 \fi
7711 \let\minted@infile\minted@actualinfile
7712 \expandafter\minted@addcachefile\expandafter{\minted@cachefilename}%
7713 }%
7714 {\ifthenelse{\boolean{minted@frozencache}}%
7715 {%
7716 \edef\minted@cachefilename{listing\arabic{minted@pygmentizecounter}.pygtex}%
7717 \edef\minted@infile{\minted@cachedir/\minted@cachefilename}%
7718 \expandafter\minted@addcachefile\expandafter{\minted@cachefilename}}%
7719 {\expandafter\minted@addcachefile\expandafter{\[email protected]}}%
7720 }%
7721 \minted@inputpyg}%
7722 {%
7723 \ifthenelse{\equal{\minted@get@opt{autogobble}{false}}{true}}{%
7724 \minted@autogobble{#1}}{}%
7725 \ShellEscape{\minted@cmd}%
7726 \ShellEscape{\minted@cmdHTML}%
7727 %\ShellEscape{\minted@cmdPNG}%
7728 %\ShellEscape{\minted@cmdSVG}%
7729 \minted@inputpyg}%
7730 }%
7731 }{}%
7732 }%
7733 \html@action@newcommand{inputminted}[3][]{%
7734 \message{moodle.sty: Processing \string\inputminted[#1]{#2}{#3} for HTML ^^J}%
7735 % arguments #2 and #3 are thrown away: the job is done previously by minted when
7736 % calling pygmentize. The file |\minted@infileHTML| generated with our hack will be used.
7737 % Since minted is based upon `fvextra' the macro |\moodle@VerbatimInput| works here.
7738 \minted@configlang{#2}% grab options set for this specific language
7739 \setkeys{minted@opt@cmd}{#1}% grab options in #1
7740 \minted@fvset% import options
7741 \stepcounter{moodle@pygmentizecounter}
7742 \xa\moodle@VerbatimInput\xa{\csname minted@infileHTML\the\c@moodle@pygmentizecounter\endcsname}%
7743 }%
7744 % \end{macrocode}
7745 %
7746 % \subsection{Internationalization}
7747 % Here is an attempt to internationalize the PDF typesetting, relying on
7748 % the package 'translations'.
7749 % \begin{macrocode}
7750 \AtEndPreamble{%
7751 \@ifpackageloaded{translator}{\moodle@internationaltrue}{}%
7752 \@ifpackageloaded{translations}{\moodle@internationaltrue}{}%
7753 % polyglossia "fakes" babel
7754 \@ifpackageloaded{polyglossia}{%
7755 \moodle@internationaltrue
7756 % The following is commented because \xpg@bloaded is set very late and must be expanded
7757 %\PassOptionsToPackage{\xpg@bloaded}{translator}
7758 }{
7759 \@ifpackageloaded{babel}{%
7760 \moodle@internationaltrue
7761 % The following is commented because some languages of babel,
7762 % like lithuanian, are unknown to translator. Instead we
7763 % copied the aliases below.
7764 %\PassOptionsToPackage{\bbl@loaded}{translator}%
7765 }{}%
7766 }%
7767 \ifmoodle@international
7768 % By default, we load and rely on "translator".
7769 % The package is simple and has limited dependencies.
7770 % Since we borrow the syntax of "translations",
7771 % the switch is easy: just "\usepackage{translations}"
7772 % in the preamble.
7773 %\RequirePackage{translations}%
7774 \@ifpackageloaded{translations}{}{%
7775 \RequirePackage{translator}%
7776 % Borrow the syntax from 'translations'
7777 \newcommand\DeclareTranslation[3]{\deftranslation[to=#1]{#2}{#3}}%
7778 \newcommand\DeclareTranslationFallback[2]{\deftranslation[to=fallback]{#1}{#2}}%
7779 \let\GetTranslation=\translate
7780 % Set a fall-back if a translation is unknown (usually English, see below)
7781 \languagepath{\languagename,fallback}%
7782 % Set aliases (most of them taken directly from translator.sty)
7783 \languagealias{afrikaans} {Afrikaans,Dutch}%
7784 \languagealias{american} {AmericanEnglish,English}%
7785 \languagealias{austrian} {Austrian1997,Austrian,German1997,German}%
7786 \languagealias{brazil} {Brazilian,Portuguese}%
7787 \languagealias{brazilian} {Brazilian,Portuguese}%
7788 \languagealias{british} {BritishEnglish,English}%
7789 \languagealias{catalan} {Catalan}% unknown to translator
7790 \languagealias{canadian} {Canadian,English}%
7791 \languagealias{canadien} {Canadien,French}%
7792 \languagealias{croatian} {Croatian}%
7793 \languagealias{czech} {Czech}%
7794 \languagealias{danish} {Danish}%
7795 \languagealias{dutch} {Dutch}%
7796 \languagealias{english} {English}%
7797 \languagealias{estonian} {Estonian}%
7798 \languagealias{finnish} {Finnish}%
7799 \languagealias{french} {French}%
7800 \languagealias{german} {German1997,German}%
7801 \languagealias{hungarian} {Hungarian}%
7802 \languagealias{icelandic} {Icelandic}%
7803 \languagealias{italian} {Italian}%
7804 \languagealias{lithuanian}{Lithuanian}% unknown to translator
7805 \languagealias{magyar} {Magyar,Hungarian}% added Hungarian
7806 \languagealias{naustrian} {Austrian,German}%
7807 \languagealias{ngerman} {German}%
7808 \languagealias{norsk} {Norsk}%
7809 \languagealias{norwegian} {Norsk}% for polyglossia
7810 \languagealias{nynorsk} {Nynorsk,Norsk}%
7811 \languagealias{polish} {Polish}%
7812 \languagealias{portuges} {Portuguese}%
7813 \languagealias{portuguese}{Portuguese}%
7814 \languagealias{romanian} {Romanian}%
7815 \languagealias{slovak} {Slovak,Czech}% added Czech
7816 \languagealias{spanish} {Spanish}%
7817 \languagealias{swedish} {Swedish}%
7818 \languagealias{turkish} {Turkish}%
7819 \languagealias{UKenglish} {BritishEnglish,English}%
7820 \languagealias{USenglish} {AmericanEnglish,English}%
7821 }%
7822 \DeclareTranslation{Catalan}{True}{Vertader}%
7823 \DeclareTranslation{Catalan}{False}{Fals}%
7824 %\DeclareTranslation{Catalan}{cloze}{}%
7825 %\DeclareTranslation{Catalan}{description}{}%
7826 %\DeclareTranslation{Catalan}{essay}{}%
7827 %\DeclareTranslation{Catalan}{matching}{}%
7828 %\DeclareTranslation{Catalan}{multi}{}%
7829 %\DeclareTranslation{Catalan}{numerical}{}%
7830 %\DeclareTranslation{Catalan}{shortanswer}{}%
7831 %\DeclareTranslation{Catalan}{truefalse}{}%
7832 %\DeclareTranslation{Catalan}{Shuffle}{}%
7833 %\DeclareTranslation{Catalan}{Single}{}%
7834 %\DeclareTranslation{Catalan}{marked out of}{}%
7835 %\DeclareTranslation{Catalan}{penalty}{}%
7836 %\DeclareTranslation{Catalan}{tags}{}%
7837 %\DeclareTranslation{Catalan}{All-or-nothing}{}%
7838 %\DeclareTranslation{Catalan}{Case-Sensitive}{}%
7839 %\DeclareTranslation{Catalan}{Case-Insensitive}{}%
7840 %\DeclareTranslation{Catalan}{Drag and drop}{}%
7841 %\DeclareTranslation{Catalan}{Information for graders}{}%
7842 %\DeclareTranslation{Catalan}{Response template}{}%
7843 %\DeclareTranslation{Catalan}{editor}{}%
7844 %\DeclareTranslation{Catalan}{editorfilepicker}{}%
7845 %\DeclareTranslation{Catalan}{plain}{}%
7846 %\DeclareTranslation{Catalan}{monospaced}{}%
7847 %\DeclareTranslation{Catalan}{noinline}{}%
7848 %\DeclareTranslation{Catalan}{Total of marks}{}%
7849 \DeclareTranslation{Croatian}{True}{To\v{c}no}%
7850 \DeclareTranslation{Croatian}{False}{Neto\v{c}no}%
7851 %\DeclareTranslation{Croatian}{cloze}{}%
7852 %\DeclareTranslation{Croatian}{description}{}%
7853 %\DeclareTranslation{Croatian}{essay}{}%
7854 %\DeclareTranslation{Croatian}{matching}{}%
7855 %\DeclareTranslation{Croatian}{multi}{}%
7856 %\DeclareTranslation{Croatian}{numerical}{}%
7857 %\DeclareTranslation{Croatian}{shortanswer}{}%
7858 %\DeclareTranslation{Croatian}{truefalse}{}%
7859 %\DeclareTranslation{Croatian}{Shuffle}{}%
7860 %\DeclareTranslation{Croatian}{Single}{}%
7861 %\DeclareTranslation{Croatian}{Multiple}{}%
7862 %\DeclareTranslation{Croatian}{marked out of}{}%
7863 %\DeclareTranslation{Croatian}{penalty}{}%
7864 %\DeclareTranslation{Croatian}{tags}{}%
7865 %\DeclareTranslation{Croatian}{All-or-nothing}{}%
7866 %\DeclareTranslation{Croatian}{Case-Sensitive}{}%
7867 %\DeclareTranslation{Croatian}{Case-Insensitive}{}%
7868 %\DeclareTranslation{Croatian}{Drag and drop}{}%
7869 %\DeclareTranslation{Croatian}{Information for graders}{}%
7870 %\DeclareTranslation{Croatian}{Response template}{}%
7871 %\DeclareTranslation{Croatian}{editor}{}%
7872 %\DeclareTranslation{Croatian}{editorfilepicker}{}%
7873 %\DeclareTranslation{Croatian}{plain}{}%
7874 %\DeclareTranslation{Croatian}{monospaced}{}%
7875 %\DeclareTranslation{Croatian}{noinline}{}%
7876 %\DeclareTranslation{Croatian}{Total of marks}{}%
7877 \DeclareTranslation{Czech}{True}{Pravda}%
7878 \DeclareTranslation{Czech}{False}{Nepravda}%
7879 %\DeclareTranslation{Czech}{cloze}{}%
7880 %\DeclareTranslation{Czech}{description}{}%
7881 %\DeclareTranslation{Czech}{essay}{}%
7882 %\DeclareTranslation{Czech}{matching}{}%
7883 %\DeclareTranslation{Czech}{multi}{}%
7884 %\DeclareTranslation{Czech}{numerical}{}%
7885 %\DeclareTranslation{Czech}{shortanswer}{}%
7886 %\DeclareTranslation{Czech}{truefalse}{}%
7887 %\DeclareTranslation{Czech}{Shuffle}{}%
7888 %\DeclareTranslation{Czech}{Single}{}%
7889 %\DeclareTranslation{Czech}{Multiple}{}%
7890 %\DeclareTranslation{Czech}{marked out of}{}%
7891 %\DeclareTranslation{Czech}{penalty}{}%
7892 %\DeclareTranslation{Czech}{tags}{}%
7893 %\DeclareTranslation{Czech}{All-or-nothing}{}%
7894 %\DeclareTranslation{Czech}{Case-Sensitive}{}%
7895 %\DeclareTranslation{Czech}{Case-Insensitive}{}%
7896 %\DeclareTranslation{Czech}{Drag and drop}{}%
7897 %\DeclareTranslation{Czech}{Information for graders}{}%
7898 %\DeclareTranslation{Czech}{Response template}{}%
7899 %\DeclareTranslation{Czech}{editor}{}%
7900 %\DeclareTranslation{Czech}{editorfilepicker}{}%
7901 %\DeclareTranslation{Czech}{plain}{}%
7902 %\DeclareTranslation{Czech}{monospaced}{}%
7903 %\DeclareTranslation{Czech}{noinline}{}%
7904 %\DeclareTranslation{Czech}{Total of marks}{}%
7905 \DeclareTranslation{Danish}{True}{Sandt}%
7906 \DeclareTranslation{Danish}{False}{Falsk}%
7907 %\DeclareTranslation{Danish}{cloze}{}%
7908 %\DeclareTranslation{Danish}{description}{}%
7909 %\DeclareTranslation{Danish}{essay}{}%
7910 %\DeclareTranslation{Danish}{matching}{}%
7911 %\DeclareTranslation{Danish}{multi}{}%
7912 %\DeclareTranslation{Danish}{numerical}{}%
7913 %\DeclareTranslation{Danish}{shortanswer}{}%
7914 %\DeclareTranslation{Danish}{truefalse}{}%
7915 %\DeclareTranslation{Danish}{Shuffle}{}%
7916 %\DeclareTranslation{Danish}{Single}{}%
7917 %\DeclareTranslation{Danish}{Multiple}{}%
7918 %\DeclareTranslation{Danish}{marked out of}{}%
7919 %\DeclareTranslation{Danish}{penalty}{}%
7920 %\DeclareTranslation{Danish}{tags}{}%
7921 %\DeclareTranslation{Danish}{All-or-nothing}{}%
7922 %\DeclareTranslation{Danish}{Case-Sensitive}{}%
7923 %\DeclareTranslation{Danish}{Case-Insensitive}{}%
7924 %\DeclareTranslation{Danish}{Drag and drop}{}%
7925 %\DeclareTranslation{Danish}{Information for graders}{}%
7926 %\DeclareTranslation{Danish}{Response template}{}%
7927 %\DeclareTranslation{Danish}{editor}{}%
7928 %\DeclareTranslation{Danish}{editorfilepicker}{}%
7929 %\DeclareTranslation{Danish}{plain}{}%
7930 %\DeclareTranslation{Danish}{monospaced}{}%
7931 %\DeclareTranslation{Danish}{noinline}{}%
7932 %\DeclareTranslation{Danish}{Total of marks}{}%
7933 \DeclareTranslation{Dutch}{True}{Waar}%
7934 \DeclareTranslation{Dutch}{False}{Niet waar}%
7935 %\DeclareTranslation{Dutch}{cloze}{}%
7936 %\DeclareTranslation{Dutch}{description}{}%
7937 %\DeclareTranslation{Dutch}{essay}{}%
7938 %\DeclareTranslation{Dutch}{matching}{}%
7939 %\DeclareTranslation{Dutch}{multi}{}%
7940 %\DeclareTranslation{Dutch}{numerical}{}%
7941 %\DeclareTranslation{Dutch}{shortanswer}{}%
7942 %\DeclareTranslation{Dutch}{truefalse}{}%
7943 %\DeclareTranslation{Dutch}{Shuffle}{}%
7944 %\DeclareTranslation{Dutch}{Single}{}%
7945 %\DeclareTranslation{Dutch}{Multiple}{}%
7946 %\DeclareTranslation{Dutch}{marked out of}{}%
7947 %\DeclareTranslation{Dutch}{penalty}{}%
7948 %\DeclareTranslation{Dutch}{tags}{}%
7949 %\DeclareTranslation{Dutch}{All-or-nothing}{}%
7950 %\DeclareTranslation{Dutch}{Case-Sensitive}{}%
7951 %\DeclareTranslation{Dutch}{Case-Insensitive}{}%
7952 %\DeclareTranslation{Dutch}{Drag and drop}{}%
7953 %\DeclareTranslation{Dutch}{Information for graders}{}%
7954 %\DeclareTranslation{Dutch}{Response template}{}%
7955 %\DeclareTranslation{Dutch}{editor}{}%
7956 %\DeclareTranslation{Dutch}{editorfilepicker}{}%
7957 %\DeclareTranslation{Dutch}{plain}{}%
7958 %\DeclareTranslation{Dutch}{monospaced}{}%
7959 %\DeclareTranslation{Dutch}{noinline}{}%
7960 %\DeclareTranslation{Dutch}{Total of marks}{}%
7961 \DeclareTranslation{English}{True}{True}%
7962 \DeclareTranslation{English}{False}{False}%
7963 \DeclareTranslation{English}{cloze}{Embedded answers}%
7964 \DeclareTranslation{English}{description}{Description}%
7965 \DeclareTranslation{English}{essay}{Essay}%
7966 \DeclareTranslation{English}{matching}{Matching}%
7967 \DeclareTranslation{English}{multi}{Multiple choice}%
7968 \DeclareTranslation{English}{numerical}{Numerical}%
7969 \DeclareTranslation{English}{shortanswer}{Short answer}%
7970 \DeclareTranslation{English}{truefalse}{True/False}%
7971 \DeclareTranslation{English}{Shuffle}{Shuffle}%
7972 \DeclareTranslation{English}{Single}{One answer only}%
7973 \DeclareTranslation{English}{Multiple}{Multiple answers allowed}%
7974 \DeclareTranslation{English}{marked out of}{marked out of}%
7975 \DeclareTranslation{English}{penalty}{penalty}%
7976 \DeclareTranslation{English}{tags}{tags}%
7977 \DeclareTranslation{English}{All-or-nothing}{All-or-nothing}%
7978 \DeclareTranslation{English}{Case-Sensitive}{Case-Sensitive}%
7979 \DeclareTranslation{English}{Case-Insensitive}{Case-Insensitive}%
7980 \DeclareTranslation{English}{Drag and drop}{Drag and drop}%
7981 \DeclareTranslation{English}{Information for graders}{Information for graders}%
7982 \DeclareTranslation{English}{Response template}{Response template}%
7983 \DeclareTranslation{English}{editor}{HTML editor}%
7984 \DeclareTranslation{English}{editorfilepicker}{HTML editor + file picker}%
7985 \DeclareTranslation{English}{plain}{Plain text}%
7986 \DeclareTranslation{English}{monospaced}{Plain text, monospaced font}%
7987 \DeclareTranslation{English}{noinline}{File picker}%
7988 \DeclareTranslation{English}{Total of marks}{Total of marks}%
7989 \DeclareTranslation{Estonian}{True}{T\~oene}%
7990 \DeclareTranslation{Estonian}{False}{V\"a\"ar}%
7991 %\DeclareTranslation{Estonian}{cloze}{}%
7992 %\DeclareTranslation{Estonian}{description}{}%
7993 %\DeclareTranslation{Estonian}{essay}{}%
7994 %\DeclareTranslation{Estonian}{matching}{}%
7995 %\DeclareTranslation{Estonian}{multi}{}%
7996 %\DeclareTranslation{Estonian}{numerical}{}%
7997 %\DeclareTranslation{Estonian}{shortanswer}{}%
7998 %\DeclareTranslation{Estonian}{truefalse}{}%
7999 %\DeclareTranslation{Estonian}{Shuffle}{}%
8000 %\DeclareTranslation{Estonian}{Single}{}%
8001 %\DeclareTranslation{Estonian}{Multiple}{}%
8002 %\DeclareTranslation{Estonian}{marked out of}{}%
8003 %\DeclareTranslation{Estonian}{penalty}{}%
8004 %\DeclareTranslation{Estonian}{tags}{}%
8005 %\DeclareTranslation{Estonian}{All-or-nothing}{}%
8006 %\DeclareTranslation{Estonian}{Case-Sensitive}{}%
8007 %\DeclareTranslation{Estonian}{Case-Insensitive}{}%
8008 %\DeclareTranslation{Estonian}{Drag and drop}{}%
8009 %\DeclareTranslation{Estonian}{Information for graders}{}%
8010 %\DeclareTranslation{Estonian}{Response template}{}%
8011 %\DeclareTranslation{Estonian}{editor}{}%
8012 %\DeclareTranslation{Estonian}{editorfilepicker}{}%
8013 %\DeclareTranslation{Estonian}{plain}{}%
8014 %\DeclareTranslation{Estonian}{monospaced}{}%
8015 %\DeclareTranslation{Estonian}{noinline}{}%
8016 %\DeclareTranslation{Estonian}{Total of marks}{}%
8017 \DeclareTranslation{Finnish}{True}{Tosi}%
8018 \DeclareTranslation{Finnish}{False}{Ep\"atosi}%
8019 %\DeclareTranslation{Finnish}{cloze}{}%
8020 %\DeclareTranslation{Finnish}{description}{}%
8021 %\DeclareTranslation{Finnish}{essay}{}%
8022 %\DeclareTranslation{Finnish}{matching}{}%
8023 %\DeclareTranslation{Finnish}{multi}{}%
8024 %\DeclareTranslation{Finnish}{numerical}{}%
8025 %\DeclareTranslation{Finnish}{shortanswer}{}%
8026 %\DeclareTranslation{Finnish}{truefalse}{}%
8027 %\DeclareTranslation{Finnish}{Shuffle}{}%
8028 %\DeclareTranslation{Finnish}{Single}{}%
8029 %\DeclareTranslation{Finnish}{Multiple}{}%
8030 %\DeclareTranslation{Finnish}{marked out of}{}%
8031 %\DeclareTranslation{Finnish}{penalty}{}%
8032 %\DeclareTranslation{Finnish}{tags}{}%
8033 %\DeclareTranslation{Finnish}{All-or-nothing}{}%
8034 %\DeclareTranslation{Finnish}{Case-Sensitive}{}%
8035 %\DeclareTranslation{Finnish}{Case-Insensitive}{}%
8036 %\DeclareTranslation{Finnish}{Drag and drop}{}%
8037 %\DeclareTranslation{Finnish}{Information for graders}{}%
8038 %\DeclareTranslation{Finnish}{Response template}{}%
8039 %\DeclareTranslation{Finnish}{editor}{}%
8040 %\DeclareTranslation{Finnish}{editorfilepicker}{}%
8041 %\DeclareTranslation{Finnish}{plain}{}%
8042 %\DeclareTranslation{Finnish}{monospaced}{}%
8043 %\DeclareTranslation{Finnish}{noinline}{}%
8044 %\DeclareTranslation{Finnish}{Total of marks}{}%
8045 \DeclareTranslation{French}{True}{Vrai}%
8046 \DeclareTranslation{French}{False}{Faux}%
8047 \DeclareTranslation{French}{cloze}{R\'eponses int\'egr\'ees}%
8048 \DeclareTranslation{French}{description}{Description}%
8049 \DeclareTranslation{French}{essay}{Composition}%
8050 \DeclareTranslation{French}{matching}{Appariement}%
8051 \DeclareTranslation{French}{multi}{QCM}%
8052 \DeclareTranslation{French}{numerical}{Num\'erique}%
8053 \DeclareTranslation{French}{shortanswer}{R\'eponse courte}%
8054 \DeclareTranslation{French}{truefalse}{Vrai/Faux}%
8055 \DeclareTranslation{French}{Shuffle}{M\'elanger}%
8056 \DeclareTranslation{French}{Single}{R\'eponse unique}%
8057 \DeclareTranslation{French}{Multiple}{Plusieurs r\'eponses possibles}%
8058 \DeclareTranslation{French}{marked out of}{not\'e sur}%
8059 \DeclareTranslation{French}{penalty}{p\'enalit\'e}%
8060 \DeclareTranslation{French}{tags}{\'etiquettes}%
8061 \DeclareTranslation{French}{All-or-nothing}{Tout ou rien}%
8062 \DeclareTranslation{French}{Case-Sensitive}{Sensible \`a la casse}%
8063 \DeclareTranslation{French}{Case-Insensitive}{Insensible \`a la casse}%
8064 \DeclareTranslation{French}{Drag and drop}{Glisser-d\'eposer}%
8065 \DeclareTranslation{French}{Information for graders}{Information pour les évaluateurs}%
8066 \DeclareTranslation{French}{Response template}{Mod\`ele de r\'eponse}%
8067 \DeclareTranslation{French}{editor}{\'Editeur HTML}%
8068 \DeclareTranslation{French}{editorfilepicker}{\'Editeur \HTML\ + s\'electeur de fichier}%
8069 \DeclareTranslation{French}{plain}{\'Editeur texte}%
8070 \DeclareTranslation{French}{monospaced}{\'Editeur texte, police \`a chasse fixe}%
8071 \DeclareTranslation{French}{noinline}{S\'electeur de fichier}%
8072 \DeclareTranslation{French}{Total of marks}{Total des points}%
8073 \DeclareTranslation{German}{True}{Wahr}%
8074 \DeclareTranslation{German}{False}{Falsch}%
8075 \DeclareTranslation{German}{cloze}{L\"uckentext}%
8076 \DeclareTranslation{German}{description}{Beschreibung}%
8077 \DeclareTranslation{German}{essay}{Freitext}%
8078 \DeclareTranslation{German}{matching}{Zuordnung}%
8079 \DeclareTranslation{German}{multi}{Multiple-Choice}%
8080 \DeclareTranslation{German}{numerical}{Numerisch}%
8081 \DeclareTranslation{German}{shortanswer}{Kurzantwort}%
8082 \DeclareTranslation{German}{truefalse}{Wahr/Falsch}%
8083 \DeclareTranslation{German}{Shuffle}{Mischen}%
8084 \DeclareTranslation{German}{Single}{Nur eine Antwort erlaubt}%
8085 \DeclareTranslation{German}{Multiple}{Mehrere Antworten erlaubt}%
8086 \DeclareTranslation{German}{marked out of}{Punkte:}%
8087 \DeclareTranslation{German}{penalty}{Abzug}%
8088 \DeclareTranslation{German}{tags}{Tags}%
8089 \DeclareTranslation{German}{All-or-nothing}{Alles-oder-nichts}%
8090 \DeclareTranslation{German}{Case-Sensitive}{Gro\ss-/Kleinschreibung muss stimmen}%
8091 \DeclareTranslation{German}{Case-Insensitive}{Gro\ss-/Kleinschreibung unwichtig}%
8092 \DeclareTranslation{German}{Drag and drop}{Drag-and-Drop}%
8093 \DeclareTranslation{German}{Information for graders}{Information zur Bewertung}%
8094 \DeclareTranslation{German}{Response template}{Antwortvorlage}%
8095 \DeclareTranslation{German}{editor}{HTML Editor}%
8096 \DeclareTranslation{German}{editorfilepicker}{HTML Editor mit Dateiauswahl}%
8097 \DeclareTranslation{German}{plain}{Unformatierter Text}%
8098 \DeclareTranslation{German}{monospaced}{Unformatierter Text, Schriftart mit fester Laufweite}%
8099 \DeclareTranslation{German}{noinline}{Kein Textfeld}%
8100 \DeclareTranslation{German}{Total of marks}{Gesamtsumme der Punkte}%
8101 \DeclareTranslation{Hungarian}{True}{Igaz}%
8102 \DeclareTranslation{Hungarian}{False}{Hamis}%
8103 %\DeclareTranslation{Hungarian}{cloze}{}%
8104 %\DeclareTranslation{Hungarian}{description}{}%
8105 %\DeclareTranslation{Hungarian}{essay}{}%
8106 %\DeclareTranslation{Hungarian}{matching}{}%
8107 %\DeclareTranslation{Hungarian}{multi}{}%
8108 %\DeclareTranslation{Hungarian}{numerical}{}%
8109 %\DeclareTranslation{Hungarian}{shortanswer}{}%
8110 %\DeclareTranslation{Hungarian}{truefalse}{}%
8111 %\DeclareTranslation{Hungarian}{Shuffle}{}%
8112 %\DeclareTranslation{Hungarian}{Single}{}%
8113 %\DeclareTranslation{Hungarian}{Multiple}{}%
8114 %\DeclareTranslation{Hungarian}{marked out of}{}%
8115 %\DeclareTranslation{Hungarian}{penalty}{}%
8116 %\DeclareTranslation{Hungarian}{tags}{}%
8117 %\DeclareTranslation{Hungarian}{All-or-nothing}{}%
8118 %\DeclareTranslation{Hungarian}{Case-Sensitive}{}%
8119 %\DeclareTranslation{Hungarian}{Case-Insensitive}{}%
8120 %\DeclareTranslation{Hungarian}{Drag and drop}{}%
8121 %\DeclareTranslation{Hungarian}{Information for graders}{}%
8122 %\DeclareTranslation{Hungarian}{Response template}{}%
8123 %\DeclareTranslation{Hungarian}{editor}{}%
8124 %\DeclareTranslation{Hungarian}{editorfilepicker}{}%
8125 %\DeclareTranslation{Hungarian}{plain}{}%
8126 %\DeclareTranslation{Hungarian}{monospaced}{}%
8127 %\DeclareTranslation{Hungarian}{noinline}{}%
8128 %\DeclareTranslation{Hungarian}{Total of marks}{}%
8129 \DeclareTranslation{Icelandic}{True}{R\'ett}%
8130 \DeclareTranslation{Icelandic}{False}{Rangt}%
8131 %\DeclareTranslation{Icelandic}{cloze}{}%
8132 %\DeclareTranslation{Icelandic}{description}{}%
8133 %\DeclareTranslation{Icelandic}{essay}{}%
8134 %\DeclareTranslation{Icelandic}{matching}{}%
8135 %\DeclareTranslation{Icelandic}{multi}{}%
8136 %\DeclareTranslation{Icelandic}{numerical}{}%
8137 %\DeclareTranslation{Icelandic}{shortanswer}{}%
8138 %\DeclareTranslation{Icelandic}{truefalse}{}%
8139 %\DeclareTranslation{Icelandic}{Shuffle}{}%
8140 %\DeclareTranslation{Icelandic}{Single}{}%
8141 %\DeclareTranslation{Icelandic}{Multiple}{}%
8142 %\DeclareTranslation{Icelandic}{marked out of}{}%
8143 %\DeclareTranslation{Icelandic}{penalty}{}%
8144 %\DeclareTranslation{Icelandic}{tags}{}%
8145 %\DeclareTranslation{Icelandic}{All-or-nothing}{}%
8146 %\DeclareTranslation{Icelandic}{Case-Sensitive}{}%
8147 %\DeclareTranslation{Icelandic}{Case-Insensitive}{}%
8148 %\DeclareTranslation{Icelandic}{Drag and drop}{}%
8149 %\DeclareTranslation{Icelandic}{Information for graders}{}%
8150 %\DeclareTranslation{Icelandic}{Response template}{}%
8151 %\DeclareTranslation{Icelandic}{editor}{}%
8152 %\DeclareTranslation{Icelandic}{editorfilepicker}{}%
8153 %\DeclareTranslation{Icelandic}{plain}{}%
8154 %\DeclareTranslation{Icelandic}{monospaced}{}%
8155 %\DeclareTranslation{Icelandic}{noinline}{}%
8156 %\DeclareTranslation{Icelandic}{Total of marks}{}%
8157 \DeclareTranslation{Italian}{True}{Vero}%
8158 \DeclareTranslation{Italian}{False}{Falso}%
8159 \DeclareTranslation{Italian}{cloze}{Risposte inglobate}%
8160 \DeclareTranslation{Italian}{description}{Descrizione}%
8161 \DeclareTranslation{Italian}{essay}{Tema libero}%
8162 \DeclareTranslation{Italian}{matching}{Corrispondenza}%
8163 \DeclareTranslation{Italian}{multi}{Risposta multipla}%
8164 \DeclareTranslation{Italian}{numerical}{Numerica}%
8165 \DeclareTranslation{Italian}{shortanswer}{Risposta breve}%
8166 \DeclareTranslation{Italian}{truefalse}{Vero/Falso}%
8167 \DeclareTranslation{Italian}{Shuffle}{Ordine casuale}%
8168 \DeclareTranslation{Italian}{Single}{Una sola alternativa}%
8169 \DeclareTranslation{Italian}{Multiple}{Pi\`u alternative}%
8170 \DeclareTranslation{Italian}{marked out of}{punteggio max.}%
8171 \DeclareTranslation{Italian}{penalty}{penalit\`a}%
8172 \DeclareTranslation{Italian}{tags}{etichette}%
8173 \DeclareTranslation{Italian}{All-or-nothing}{Tutto o niente}%
8174 \DeclareTranslation{Italian}{Case-Sensitive}{Sensibile alle maiuscole}%
8175 \DeclareTranslation{Italian}{Case-Insensitive}{Maiuscolo/minuscolo indifferente}%
8176 \DeclareTranslation{Italian}{Drag and drop}{Drag and drop}%
8177 \DeclareTranslation{Italian}{Information for graders}{Informazioni per i valutatori}%
8178 \DeclareTranslation{Italian}{Response template}{Modello di risposta}%
8179 \DeclareTranslation{Italian}{editor}{Editor HTML}%
8180 \DeclareTranslation{Italian}{editorfilepicker}{Editor \HTML\ con file picker}%
8181 \DeclareTranslation{Italian}{plain}{Testo semplice}%
8182 \DeclareTranslation{Italian}{monospaced}{Testo semplice, caratteri a spaziatura fissa}%
8183 \DeclareTranslation{Italian}{noinline}{Solo file picker}%
8184 \DeclareTranslation{Italian}{Total of marks}{Punteggio complessivo}%
8185 \DeclareTranslation{Lithuanian}{True}{Tiesa}%
8186 \DeclareTranslation{Lithuanian}{False}{Netiesa}%
8187 %\DeclareTranslation{Lithuanian}{cloze}{}%
8188 %\DeclareTranslation{Lithuanian}{description}{}%
8189 %\DeclareTranslation{Lithuanian}{essay}{}%
8190 %\DeclareTranslation{Lithuanian}{matching}{}%
8191 %\DeclareTranslation{Lithuanian}{multi}{}%
8192 %\DeclareTranslation{Lithuanian}{numerical}{}%
8193 %\DeclareTranslation{Lithuanian}{shortanswer}{}%
8194 %\DeclareTranslation{Lithuanian}{truefalse}{}%
8195 %\DeclareTranslation{Lithuanian}{Shuffle}{}%
8196 %\DeclareTranslation{Lithuanian}{Single}{}%
8197 %\DeclareTranslation{Lithuanian}{Multiple}{}%
8198 %\DeclareTranslation{Lithuanian}{marked out of}{}%
8199 %\DeclareTranslation{Lithuanian}{penalty}{}%
8200 %\DeclareTranslation{Lithuanian}{tags}{}%
8201 %\DeclareTranslation{Lithuanian}{All-or-nothing}{}%
8202 %\DeclareTranslation{Lithuanian}{Case-Sensitive}{}%
8203 %\DeclareTranslation{Lithuanian}{Case-Insensitive}{}%
8204 %\DeclareTranslation{Lithuanian}{Drag and drop}{}%
8205 %\DeclareTranslation{Lithuanian}{Information for graders}{}%
8206 %\DeclareTranslation{Lithuanian}{Response template}{}%
8207 %\DeclareTranslation{Lithuanian}{editor}{}%
8208 %\DeclareTranslation{Lithuanian}{editorfilepicker}{}%
8209 %\DeclareTranslation{Lithuanian}{plain}{}%
8210 %\DeclareTranslation{Lithuanian}{monospaced}{}%
8211 %\DeclareTranslation{Lithuanian}{noinline}{}%
8212 %\DeclareTranslation{Lithuanian}{Total of marks}{}%
8213 \DeclareTranslation{Norsk}{True}{Riktig}%
8214 \DeclareTranslation{Norsk}{False}{Feil}%
8215 %\DeclareTranslation{Norsk}{cloze}{}%
8216 %\DeclareTranslation{Norsk}{description}{}%
8217 %\DeclareTranslation{Norsk}{essay}{}%
8218 %\DeclareTranslation{Norsk}{matching}{}%
8219 %\DeclareTranslation{Norsk}{multi}{}%
8220 %\DeclareTranslation{Norsk}{numerical}{}%
8221 %\DeclareTranslation{Norsk}{shortanswer}{}%
8222 %\DeclareTranslation{Norsk}{truefalse}{}%
8223 %\DeclareTranslation{Norsk}{Shuffle}{}%
8224 %\DeclareTranslation{Norsk}{Single}{}%
8225 %\DeclareTranslation{Norsk}{Multiple}{}%
8226 %\DeclareTranslation{Norsk}{marked out of}{}%
8227 %\DeclareTranslation{Norsk}{penalty}{}%
8228 %\DeclareTranslation{Norsk}{tags}{}%
8229 %\DeclareTranslation{Norsk}{All-or-nothing}{}%
8230 %\DeclareTranslation{Norsk}{Case-Sensitive}{}%
8231 %\DeclareTranslation{Norsk}{Case-Insensitive}{}%
8232 %\DeclareTranslation{Norsk}{Drag and drop}{}%
8233 %\DeclareTranslation{Norsk}{Information for graders}{}%
8234 %\DeclareTranslation{Norsk}{Response template}{}%
8235 %\DeclareTranslation{Norsk}{editor}{}%
8236 %\DeclareTranslation{Norsk}{editorfilepicker}{}%
8237 %\DeclareTranslation{Norsk}{plain}{}%
8238 %\DeclareTranslation{Norsk}{monospaced}{}%
8239 %\DeclareTranslation{Norsk}{noinline}{}%
8240 %\DeclareTranslation{Norsk}{Total of marks}{}%
8241 \DeclareTranslation{Polish}{True}{Prawda}%
8242 \DeclareTranslation{Polish}{False}{Fa\l sz}%
8243 %\DeclareTranslation{Polish}{cloze}{}%
8244 %\DeclareTranslation{Polish}{description}{}%
8245 %\DeclareTranslation{Polish}{essay}{}%
8246 %\DeclareTranslation{Polish}{matching}{}%
8247 %\DeclareTranslation{Polish}{multi}{}%
8248 %\DeclareTranslation{Polish}{numerical}{}%
8249 %\DeclareTranslation{Polish}{shortanswer}{}%
8250 %\DeclareTranslation{Polish}{truefalse}{}%
8251 %\DeclareTranslation{Polish}{Shuffle}{}%
8252 %\DeclareTranslation{Polish}{Single}{}%
8253 %\DeclareTranslation{Polish}{Multiple}{}%
8254 %\DeclareTranslation{Polish}{marked out of}{}%
8255 %\DeclareTranslation{Polish}{penalty}{}%
8256 %\DeclareTranslation{Polish}{tags}{}%
8257 %\DeclareTranslation{Polish}{All-or-nothing}{}%
8258 %\DeclareTranslation{Polish}{Case-Sensitive}{}%
8259 %\DeclareTranslation{Polish}{Case-Insensitive}{}%
8260 %\DeclareTranslation{Polish}{Drag and drop}{}%
8261 %\DeclareTranslation{Polish}{Information for graders}{}%
8262 %\DeclareTranslation{Polish}{Response template}{}%
8263 %\DeclareTranslation{Polish}{editor}{}%
8264 %\DeclareTranslation{Polish}{editorfilepicker}{}%
8265 %\DeclareTranslation{Polish}{plain}{}%
8266 %\DeclareTranslation{Polish}{monospaced}{}%
8267 %\DeclareTranslation{Polish}{noinline}{}%
8268 %\DeclareTranslation{Polish}{Total of marks}{}%
8269 \DeclareTranslation{Portuguese}{True}{Verdadeiro}%
8270 \DeclareTranslation{Portuguese}{False}{Falso}%
8271 %\DeclareTranslation{Portuguese}{cloze}{}%
8272 %\DeclareTranslation{Portuguese}{description}{}%
8273 %\DeclareTranslation{Portuguese}{essay}{}%
8274 %\DeclareTranslation{Portuguese}{matching}{}%
8275 %\DeclareTranslation{Portuguese}{multi}{}%
8276 %\DeclareTranslation{Portuguese}{numerical}{}%
8277 %\DeclareTranslation{Portuguese}{shortanswer}{}%
8278 %\DeclareTranslation{Portuguese}{truefalse}{}%
8279 %\DeclareTranslation{Portuguese}{Shuffle}{}%
8280 %\DeclareTranslation{Portuguese}{Single}{}%
8281 %\DeclareTranslation{Portuguese}{Multiple}{}%
8282 %\DeclareTranslation{Portuguese}{marked out of}{}%
8283 %\DeclareTranslation{Portuguese}{penalty}{}%
8284 %\DeclareTranslation{Portuguese}{tags}{}%
8285 %\DeclareTranslation{Portuguese}{All-or-nothing}{}%
8286 %\DeclareTranslation{Portuguese}{Case-Sensitive}{}%
8287 %\DeclareTranslation{Portuguese}{Case-Insensitive}{}%
8288 %\DeclareTranslation{Portuguese}{Drag and drop}{}%
8289 %\DeclareTranslation{Portuguese}{Information for graders}{}%
8290 %\DeclareTranslation{Portuguese}{Response template}{}%
8291 %\DeclareTranslation{Portuguese}{editor}{}%
8292 %\DeclareTranslation{Portuguese}{editorfilepicker}{}%
8293 %\DeclareTranslation{Portuguese}{plain}{}%
8294 %\DeclareTranslation{Portuguese}{monospaced}{}%
8295 %\DeclareTranslation{Portuguese}{noinline}{}%
8296 %\DeclareTranslation{Portuguese}{Total of marks}{}%
8297 \DeclareTranslation{Romanian}{True}{Adev\u{a}rat}%
8298 \DeclareTranslation{Romanian}{False}{Fals}%
8299 %\DeclareTranslation{Romanian}{cloze}{}%
8300 %\DeclareTranslation{Romanian}{description}{}%
8301 %\DeclareTranslation{Romanian}{essay}{}%
8302 %\DeclareTranslation{Romanian}{matching}{}%
8303 %\DeclareTranslation{Romanian}{multi}{}%
8304 %\DeclareTranslation{Romanian}{numerical}{}%
8305 %\DeclareTranslation{Romanian}{shortanswer}{}%
8306 %\DeclareTranslation{Romanian}{truefalse}{}%
8307 %\DeclareTranslation{Romanian}{Shuffle}{}%
8308 %\DeclareTranslation{Romanian}{Single}{}%
8309 %\DeclareTranslation{Romanian}{Multiple}{}%
8310 %\DeclareTranslation{Romanian}{marked out of}{}%
8311 %\DeclareTranslation{Romanian}{penalty}{}%
8312 %\DeclareTranslation{Romanian}{tags}{}%
8313 %\DeclareTranslation{Romanian}{All-or-nothing}{}%
8314 %\DeclareTranslation{Romanian}{Case-Sensitive}{}%
8315 %\DeclareTranslation{Romanian}{Case-Insensitive}{}%
8316 %\DeclareTranslation{Romanian}{Drag and drop}{}%
8317 %\DeclareTranslation{Romanian}{Information for graders}{}%
8318 %\DeclareTranslation{Romanian}{Response template}{}%
8319 %\DeclareTranslation{Romanian}{editor}{}%
8320 %\DeclareTranslation{Romanian}{editorfilepicker}{}%
8321 %\DeclareTranslation{Romanian}{plain}{}%
8322 %\DeclareTranslation{Romanian}{monospaced}{}%
8323 %\DeclareTranslation{Romanian}{noinline}{}%
8324 %\DeclareTranslation{Romanian}{Total of marks}{}%
8325 \DeclareTranslation{Spanish}{True}{Verdadero}%
8326 \DeclareTranslation{Spanish}{False}{Falso}%
8327 \DeclareTranslation{Spanish}{cloze}{Respuestas anidadas}%
8328 \DeclareTranslation{Spanish}{description}{Descripci\'on}%
8329 \DeclareTranslation{Spanish}{essay}{Ensayo}%
8330 \DeclareTranslation{Spanish}{matching}{Emparejamiento}%
8331 \DeclareTranslation{Spanish}{multi}{Opci\'on m\'ultiple}%
8332 \DeclareTranslation{Spanish}{numerical}{Num\'erica}%
8333 \DeclareTranslation{Spanish}{shortanswer}{Respuesta corta}%
8334 \DeclareTranslation{Spanish}{truefalse}{Verdadero/Falso}%
8335 \DeclareTranslation{Spanish}{Shuffle}{Barajar al azar}%
8336 \DeclareTranslation{Spanish}{Single}{S\'olo una respuesta}%
8337 \DeclareTranslation{Spanish}{Multiple}{Se permiten varias respuestas}%
8338 \DeclareTranslation{Spanish}{marked out of}{Punt\'ua como}%
8339 \DeclareTranslation{Spanish}{penalty}{penalizaci\'on}%
8340 \DeclareTranslation{Spanish}{tags}{marcas}%
8341 \DeclareTranslation{Spanish}{All-or-nothing}{Todo o nada}%
8342 \DeclareTranslation{Spanish}{Case-Sensitive}{May\'usculas y min\'usculas deben coincidir}%
8343 \DeclareTranslation{Spanish}{Case-Insensitive}{Igual may\'usculas que min\'usculas}%
8344 \DeclareTranslation{Spanish}{Drag and drop}{Arrastrar y soltar}%
8345 \DeclareTranslation{Spanish}{Information for graders}{Informaci\'on para evaluadores}%
8346 \DeclareTranslation{Spanish}{Response template}{Plantilla de respuesta}%
8347 \DeclareTranslation{Spanish}{editor}{Editor HTML}%
8348 \DeclareTranslation{Spanish}{editorfilepicker}{Editor \HTML\ con selector de archivos}%
8349 \DeclareTranslation{Spanish}{plain}{Texto sin formato}%
8350 \DeclareTranslation{Spanish}{monospaced}{Texto sin formato, tipografĂ­a monoespaciada}%
8351 \DeclareTranslation{Spanish}{noinline}{Sin texto}%
8352 \DeclareTranslation{Spanish}{Total of marks}{Total de puntos}%
8353 \DeclareTranslation{Swedish}{True}{Sant}%
8354 \DeclareTranslation{Swedish}{False}{Falskt}%
8355 %\DeclareTranslation{Swedish}{cloze}{}%
8356 %\DeclareTranslation{Swedish}{description}{}%
8357 %\DeclareTranslation{Swedish}{essay}{}%
8358 %\DeclareTranslation{Swedish}{matching}{}%
8359 %\DeclareTranslation{Swedish}{multi}{}%
8360 %\DeclareTranslation{Swedish}{numerical}{}%
8361 %\DeclareTranslation{Swedish}{shortanswer}{}%
8362 %\DeclareTranslation{Swedish}{truefalse}{}%
8363 %\DeclareTranslation{Swedish}{Shuffle}{}%
8364 %\DeclareTranslation{Swedish}{Single}{}%
8365 %\DeclareTranslation{Swedish}{Multiple}{}%
8366 %\DeclareTranslation{Swedish}{marked out of}{}%
8367 %\DeclareTranslation{Swedish}{penalty}{}%
8368 %\DeclareTranslation{Swedish}{tags}{}%
8369 %\DeclareTranslation{Swedish}{All-or-nothing}{}%
8370 %\DeclareTranslation{Swedish}{Case-Sensitive}{}%
8371 %\DeclareTranslation{Swedish}{Case-Insensitive}{}%
8372 %\DeclareTranslation{Swedish}{Drag and drop}{}%
8373 %\DeclareTranslation{Swedish}{Information for graders}{}%
8374 %\DeclareTranslation{Swedish}{Response template}{}%
8375 %\DeclareTranslation{Swedish}{editor}{}%
8376 %\DeclareTranslation{Swedish}{editorfilepicker}{}%
8377 %\DeclareTranslation{Swedish}{plain}{}%
8378 %\DeclareTranslation{Swedish}{monospaced}{}%
8379 %\DeclareTranslation{Swedish}{noinline}{}%
8380 %\DeclareTranslation{Swedish}{Total of marks}{}%
8381 \DeclareTranslation{Turkish}{True}{Do\u{g}ru}%
8382 \DeclareTranslation{Turkish}{False}{Yanl\i \c{s}}%
8383 %\DeclareTranslation{Turkish}{cloze}{}%
8384 %\DeclareTranslation{Turkish}{description}{}%
8385 %\DeclareTranslation{Turkish}{essay}{}%
8386 %\DeclareTranslation{Turkish}{matching}{}%
8387 %\DeclareTranslation{Turkish}{multi}{}%
8388 %\DeclareTranslation{Turkish}{numerical}{}%
8389 %\DeclareTranslation{Turkish}{shortanswer}{}%
8390 %\DeclareTranslation{Turkish}{truefalse}{}%
8391 %\DeclareTranslation{Turkish}{Shuffle}{}%
8392 %\DeclareTranslation{Turkish}{Single}{}%
8393 %\DeclareTranslation{Turkish}{Multiple}{}%
8394 %\DeclareTranslation{Turkish}{marked out of}{}%
8395 %\DeclareTranslation{Turkish}{penalty}{}%
8396 %\DeclareTranslation{Turkish}{tags}{}%
8397 %\DeclareTranslation{Turkish}{All-or-nothing}{}%
8398 %\DeclareTranslation{Turkish}{Case-Sensitive}{}%
8399 %\DeclareTranslation{Turkish}{Case-Insensitive}{}%
8400 %\DeclareTranslation{Turkish}{Drag and drop}{}%
8401 %\DeclareTranslation{Turkish}{Information for graders}{}%
8402 %\DeclareTranslation{Turkish}{Response template}{}%
8403 %\DeclareTranslation{Turkish}{editor}{}%
8404 %\DeclareTranslation{Turkish}{editorfilepicker}{}%
8405 %\DeclareTranslation{Turkish}{plain}{}%
8406 %\DeclareTranslation{Turkish}{monospaced}{}%
8407 %\DeclareTranslation{Turkish}{noinline}{}%
8408 %\DeclareTranslation{Turkish}{Total of marks}{}%
8409 \else% neither babel nor polyglossia loaded
8410 \newcommand\DeclareTranslationFallback[2]{\csdef{moodle@fallback@#1}{#2}}% Save fallback keys
8411 \def\GetTranslation#1{\csuse{moodle@fallback@#1}}% Use fallback keys
8412 \fi
8413 \DeclareTranslationFallback{True}{True}%
8414 \DeclareTranslationFallback{False}{False}%
8415 \DeclareTranslationFallback{cloze}{Embedded answers}%
8416 \DeclareTranslationFallback{description}{Description}%
8417 \DeclareTranslationFallback{essay}{Essay}%
8418 \DeclareTranslationFallback{matching}{Matching}%
8419 \DeclareTranslationFallback{multi}{Multiple choice}%
8420 \DeclareTranslationFallback{numerical}{Numerical}%
8421 \DeclareTranslationFallback{shortanswer}{Short answer}%
8422 \DeclareTranslationFallback{truefalse}{True/False}%
8423 \DeclareTranslationFallback{Shuffle}{Shuffle}%
8424 \DeclareTranslationFallback{Single}{One answer only}%
8425 \DeclareTranslationFallback{Multiple}{Multiple answers allowed}%
8426 \DeclareTranslationFallback{marked out of}{marked out of}%
8427 \DeclareTranslationFallback{penalty}{penalty}%
8428 \DeclareTranslationFallback{tags}{tags}%
8429 \DeclareTranslationFallback{All-or-nothing}{All-or-nothing}%
8430 \DeclareTranslationFallback{Case-Sensitive}{Case-Sensitive}%
8431 \DeclareTranslationFallback{Case-Insensitive}{Case-Insensitive}%
8432 \DeclareTranslationFallback{Drag and drop}{Drag and drop}%
8433 \DeclareTranslationFallback{Information for graders}{Information for graders}%
8434 \DeclareTranslationFallback{Response template}{Response template}%
8435 \DeclareTranslationFallback{editor}{HTML editor}%
8436 \DeclareTranslationFallback{editorfilepicker}{HTML editor + file picker}%
8437 \DeclareTranslationFallback{plain}{Plain text}%
8438 \DeclareTranslationFallback{monospaced}{Plain text, monospaced font}%
8439 \DeclareTranslationFallback{noinline}{File picker}%
8440 \DeclareTranslationFallback{Total of marks}{Total of marks}%
8441 }%
8442 % \end{macrocode}
8443 %
8444 % Users of the |babel| package loaded with specific options may experience problems
8445 % related to active characters and shorthands. We tell the problems and solutions we know.
8446 % \begin{macrocode}
8447 \AtBeginDocument{%
8448 \@ifpackageloaded{babel}{%
8449 \@ifundefined{bbl@loaded}{}{% polyglossia fakes babel
8450 \forcsvlist{\listadd\moodle@babel@german@list}{german,austrian,swissgerman,swissgerman.toss,ngerman,naustrian,nswissgerman,nswissgerman.toss}%
8451 \forcsvlist{\listadd\moodle@babel@french@list}{acadian,french,frenchb,francais}%
8452 \ifPDFTeX
8453 \def\moodle@babel@french@warn{%
8454 \PackageWarning{moodle}{Be careful when using pdflatex, moodle, and the
8455 babel package loaded with a French-related option. Autospacing
8456 yields undesired symbols in the XML. Here are three workarounds:
8457 \MessageBreak 1) compile with xelatex/lualatex,\MessageBreak 2)
8458 add `\NoAutoSpacing' after `\begin{quiz}', or\MessageBreak 3)
8459 avoid the babel option.^^J}}%
8460 \def\moodle@babel@german@warn{%
8461 \PackageWarning{moodle}{Be careful when using pdflatex, moodle, and
8462 the babel package loaded with a German-related option. The symbol
8463 `"' is made active and your umlauts will confuse moodle. Here are
8464 three workarounds:\MessageBreak 1) compile with xelatex/lualatex,
8465 \MessageBreak 2) add `\string\shorthandoff{"}' after `\begin{quiz}',
8466 or\MessageBreak 3) avoid the babel option.^^J}}%
8467 \fi
8468 \def\moodle@babel@turkish@warn{%
8469 \PackageWarning{moodle}{Be careful when using moodle and the babel
8470 package loaded with option `turkish'. Shorthands are likely to
8471 break compilation. Here are three workarounds:\MessageBreak 1)
8472 rely on `polyglossia' (XeTeX or LuaTeX),\MessageBreak 2) add
8473 `\shorthandoff{=:!}' after `\begin{quiz}', or\MessageBreak
8474 3) avoid the babel option.^^J}}%
8475 \def\do#1{%
8476 \ifstrequal{#1}{turkish}{\moodle@babel@turkish@warn}{%
8477 \ifinlist{#1}{\moodle@babel@french@list}%
8478 {\ifPDFTeX\moodle@babel@french@warn\fi}{%
8479 \ifinlist{#1}{\moodle@babel@german@list}{%
8480 \ifPDFTeX\moodle@babel@german@warn\else
8481 \gdef\moodle@babel@german@warn{%
8482 \PackageWarning{moodle}{Be careful when using moodle and
8483 the babel package loaded with a German-related option that make the
8484 symbol `"' active. We recommend typing umlauts with UTF-8
8485 characters. By default, `\string\"a' is poorly translated in the XML
8486 file. This is fixed if you define `\string\shorthandoff{"}' after
8487 `\begin{quiz}'. But then `"a` will no longer work as expected.^^J}%
8488 }%
8489 \gdef\moodle@babel@german@warn@single{%
8490 \moodle@babel@german@warn
8491 \gdef\moodle@babel@german@warn@single{}%\relax
8492 }%
8493 \pretocmd{\"}%
8494 {\moodle@babel@german@warn@single}%
8495 {}%
8496 { \PackageWarning{moodle}{Umlaut patch failed.}%
8497 \moodle@babel@german@warn@single
8498 }%
8499 \fi
8500 }{}%
8501 }
8502
8503 }
8504 }
8505 \expandafter\docsvlist\expandafter{\bbl@loaded}%
8506 }%
8507 }{}%
8508 }%
8509 % \end{macrocode}
8510 %
8511 % \subsection{Warning and Error Management}
8512 %
8513 % \begin{macrocode}
8514 \def\moodle@WarningOrError#1#2#3{%
8515 % #1 : major version
8516 % #2 : minor version
8517 % #3 : feature
8518 \ifnum\the\moodle@LMSmajor\the\moodle@LMSminor=\z@\relax
8519 \PackageWarning{moodle}{#3 is only supported by Moodle #1.#2+}%
8520 \else
8521 \ifnum\numexpr 1000*\the\moodle@LMSmajor+\the\moodle@LMSminor\relax<\numexpr 1000*#1+#2\relax
8522 \PackageError{moodle}{#3 is only supported by Moodle #1.#2+
8523 (you declared Moodle \the\moodle@LMSmajor.\the\moodle@LMSminor)}%
8524 \fi
8525 \fi
8526 }%
8527 % \end{macrocode}
8528 % \Finale
8529 \endinput