TeX - LaTeX Asked by Christoph Frings on February 15, 2021
I’m preparing a quiz for moodle using the moodle
package (+ LuaLaTeX).
When I input a percentage in the usual way (i.e. 40,%
), the LaTeX render is OK but the backslash is passed along to moodle and appears in the text:
As a workaround, I redefined %
to be char"0025
but this doesn’t work since the moodle package just doesn’t care.
I haven’t found any relevant entry in the manual.
Any suggestion?
MWE:
documentclass{article}
usepackage{moodle}
begin{document}
begin{quiz}{Révisions}
begin{numerical}
Calculer 40,% de 120.
item 48
end{numerical}
end{quiz}
end{document}
After adding
makeatletter%
html@action@def%g@addto@macrohtmlize@output{otherpercent}}%
makeatother
to the preamble as suggested by @mgk in the comments, the percent sign is now correctly rendered in the question text but the backslash remains present in any answer text.
documentclass{article}
usepackage{moodle}
makeatletterhtml@action@def%{g@addto@macrohtmlize@output{otherpercent}}makeatother
begin{document}
begin{quiz}{Révisions}
begin{shortanswer}{Q1}
Enter the string texttt{"40%"}.
item 40%
end{shortanswer}
end{quiz}
end{document}
You run into two problems with version 0.8
of the moodle
package.
%
is not declared for conversion to HTML.shortanswer
questions are passed as-is to the XML without going through conversion to HTML.You can solve both by adding this code to the preamble, after loading moodle
.
makeatletter
html@action@def%{g@addto@macrohtmlize@output{otherpercent}}
defsaveshortansweranswer@int@int#1moodle@answer@rdelim{%
defmoodle@answertext{#1}%
trim@spaces@inmoodle@answertext
moodle@checkfraction
addto@xml[2]{moodle@answers@xml}{<answer fraction="moodle@fraction"
format="plain_text">}%
xaconverttohtmlmacroxamoodle@answertext@htmlxa{moodle@answertext}%
addto@xml[4]{moodle@answers@xml}{
<text>moodle@answertext@html</text>}%
ifxmoodle@feedback@emptyrelaxelse
trim@spaces@inmoodle@feedback
xaconverttohtmlmacroxamoodle@feedback@htmlxa{moodle@feedback}%
addto@xml[4]{moodle@answers@xml}{ <feedback
format="html"><text><![CDATA[<p>moodle@feedback@html</p>]]></text></feedback>}%
fi
addto@xml[2]{moodle@answers@xml}{</answer>}%
}%
makeatother
With this patch, the following example questions gave satisfactory results (compilation with version 0.8
of moodle
, Moodle LMS import, and question test on Moodle) :
begin{shortanswer}{Q1}
Enter the string texttt{"40%"}.
item[fraction=100,feedback={correct}] 40%
item[fraction=50,feedback={incomplete}] 40
item[fraction=50,feedback={incomplete}] %
end{shortanswer}
begin{cloze}{Q2}
begin{shortanswer}
Enter the string texttt{"40%"}.
item[fraction=100,feedback={correct}] 40%
item[fraction=50,feedback={incomplete}] 40
item[fraction=50,feedback={incomplete}] %
end{shortanswer}
end{cloze}
Problem 1. was recently solved in the development version of the package. I opened an issue for Problem 2. It should be resolved soon.
Correct answer by mgk on February 15, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP