cloze multichoice question in the latex using the package 'moodle'

Unfortunately, I suspect it is a bug/limitation of the Cloze type of questions. This MWE

%
\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{moodle}

\begin{document}
\begin{quiz}{Test cloze} 
\begin{cloze}{Multiple questions}

    A $x$ is

    \begin{multi}[vertical]
        One two three
        \item*  one $u^1$
        \item  two
        \item three
    \end{multi}
\end{cloze}

\end{quiz}
\end{document}

works ok, and give the expected result in Moodle:

enter image description here

But if you add braces around the exponent:

\begin{document}
\begin{quiz}{Test cloze} 
\begin{cloze}{Multiple questions}

    A $x$ is

    \begin{multi}[vertical]
        One two three
        \item*  one $u^{1}$
        \item  two
        \item three
    \end{multi}
\end{cloze}

\end{quiz}
\end{document}

Moodle fails importing it with:

enter image description here

Now, the only difference between the two XML files generated is this one:

[romano:~/tmp] % diff quiz-hr-moodle\ \(copy\).xml quiz-hr-moodle.xml          
15c15
<     <text><![CDATA[<p></P><P>A \(x\) is </P><P>One two three {1:MULTICHOICE_V:=one \(u^{1}\)~two~three}</p>]]></text>
---
>     <text><![CDATA[<p></P><P>A \(x\) is </P><P>One two three {1:MULTICHOICE_V:=one \(u^1\)~two~three}</p>]]></text>

and so it seems that the parser of Moodle get confused by the closing brace in the formula. I really do not know how to escape it, and even if the problem is recognized in the Moodle doc, it seems that simply it will not work:

enter image description here

So basically my takeout is that you can't use formulas in answers in cloze questions. The manual says you can:

enter image description here

...but I didn't manage to get it going. Notice that if you go in the XML file and escape the { } with \{and \} then the XML file is accepted, but the formula is broken.

This does not happen in normal (no cloze) multi questions, fortunately.

So my stopgap solution would be to use Unicode formulas directly typed there, and switch to lualatex for the compilation.

Another stopgap solution is to use images for your formulas:

%
\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{graphicx}
\usepackage{moodle}

\begin{document}
\begin{quiz}{Test cloze} 
    \begin{cloze}{one cloze}
    A $x$ is

    \begin{multi}[vertical]
        One two three
    \item*  one \includegraphics[height=4ex]{formula1.png}
        \item  two
        \item three
    \end{multi}
\end{cloze}
\end{quiz}
\end{document}

will render as:

Output with embedded graph

Not ideal (can be probably made better with a bit of transparency or whatever) but if you need it...


I modified the moodle package to fix this bug. LaTeX equations can be used in cloze subquestion fields. See this fixed issue.

Here is a MWE:

% !TEX TS-program = lualatex
\documentclass[10pt,a4paper]{article}
\usepackage{moodle} % development version 0.8
\begin{document}
\begin{quiz}{Category}
\begin{cloze}{Question name}
Question text
\begin{multi}[vertical]
\item[feedback={$7.5K^{0.5}L^{-0.5}$ is correct}]*$7.5K^{0.5}L^{-0.5}$
\item[feedback={$7.5K^{-0.5}L^{0.5}$ is incorrect}] $7.5K^{-0.5}L^{0.5}$
\end{multi}
\end{cloze}
\end{quiz}
\end{document}

the resulting PDF is rendered like this PDF obtained from MWE

the resulting XML file is

<?xml version="1.0" encoding="UTF-8"?>
<!-- This file was generated on 2020-11-10 by LuaLaTeX -->
<!-- running on Linux with the package moodle v0.8 -->

<quiz>
 
<question type="category">
  <category>
    <text>$course$/top/Category</text>
  </category>
</question>
 
<question type="cloze">
  <name format="html">
    <text><![CDATA[Question name]]></text>
  </name>
  <questiontext format="html">
    <text><![CDATA[<p>Question text {1:MULTICHOICE_VS:=\(7.5K^{0.5\}L^{-0.5\}\)#\(7.5K^{0.5\}L^{-0.5\}\) is correct~\(7.5K^{-0.5\}L^{0.5\}\)#\(7.5K^{-0.5\}L^{0.5\}\) is incorrect}</p>]]></text>
  </questiontext>
  <defaultgrade>1</defaultgrade>
  <generalfeedback format="html"><text/></generalfeedback>
  <penalty>0.10</penalty>
  <hidden>0</hidden>
</question>
 
</quiz>

and after import in Moodle (3.5 here with MathJax LaTeX renderer) the question preview looks like that Question preview after import of XML in Moodle