5

I use both Moodle and latex to write all my quizzes. but, I use latex to generate formula rich questions in moodle. The latex package Moodle can do this. Then I import it as XML file to moodle. This works perfectly. Before import the quiz the latex compile the code and produce a PDF so can make sure everything ok. It works well for the close quiz question as well. But, when I have the all the question in the close quiz the 'multichoice' then when I import it as an xml then I get error message although latex compile it without any error. appreciate any help

Latex code:

\documentclass[10pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{graphicx}
\usepackage{moodle}
\begin{document}
\begin{quiz}{MRTS}
\begin{cloze}{MRTS Q1}\\
A production function is given as $ Q=15\sqrt{KL}$. Q=quantity of output, L = the units of labour, K = the units of capital. The marginal product of labour, $MP_L$ of this function is:
\begin{multi}[horizontal]
\item*$7.5K^{0.5}L^{-0.5}$
\item $7.5K^{-0.5}L^{0.5}$
\item $K^{0.5}L^{-0.5}$
\item $K^{-0.5}L^{0.5}$
\item $15K^{0.5}L^{-0.5}$
\item $15K^{-0.5}L^{0.5}$
\end{multi}
A production function is given as $ Q=15\sqrt{KL}$. Q=quantity of output, L = the units of labour, K = the units of capital. The marginal product of labour, $MP_K$ of this function is:? 
\begin{multi}[horizontal]
\item $7.5K^{0.5}L^{-0.5}$
\item *$7.5K^{-0.5}L^{0.5}$
\item $K^{0.5}L^{-0.5}$
\item $K^{-0.5}L^{0.5}$
\item $15K^{0.5}L^{-0.5}$
\item $15K^{-0.5}L^{0.5}$
\end{multi}
A production function is given as $ Q=15\sqrt{KL}$. Q=quantity of output, L = the units of labour, K = the units of capital.The marginal rate of technical substitution associated with this production function is?\\ Note: $MRTS=\displaystyle -\frac{\frac{\partial Q}{\partial L}}{\frac{\partial Q}{\partial K}}$
\begin{multi}[horizontal]
\item $\frac{K}{L}$
\item*$-\frac{K}{L}$
\item  $\sqrt{\frac{K}{L}}$
\item  $\sqrt{\frac{L}{K}}$
\item $-\sqrt{\frac{K}{L}}$
\item $-\sqrt{\frac{L}{K}}$
\end{multi}
\end{cloze}
\end{quiz}
\end{document}

Moodle output

7
  • Welcome to TeX.SX! Please, add the preamble to your code to make it compilable. I have used moodle and cloze questions recently, so maybe I could help.
    – Rmano
    May 16 '20 at 8:41
  • Just added. thanks
    – FJaleel
    May 16 '20 at 9:44
  • Hi Rmano, Thanks for your time and the replies. As in your first reply, I changed the XML file exponents to example k^0.5 ),and also tried k^(0.5) instead of ^{}, but none fo them didn't work and moodle still produces the same error message. yes, your second reply, include the formula image is a good suggestion. thanks again for your contribution. Much appreciated.
    – FJaleel
    May 16 '20 at 22:39
  • Hi Rmano, Finally it worked when escape the { } with \}. the XML file is accepted. Thank you so much.
    – FJaleel
    May 17 '20 at 4:30
  • yes, it is accepted but then the formula is mis-rendered --- ¿Can you share how you managed it? You can add an answer if you want.
    – Rmano
    May 18 '20 at 8:35
4

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...

2

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

3
  • Nice! What about contacting the original author and try to upload the changes on CTAN?
    – Rmano
    Nov 8 '20 at 23:18
  • @Rmano I have been in contact with the original author but he no longer answers emails. I might start soon to go through the many steps required by the LPPL. In the meanwhile, feedback, contributions and testing are welcome.
    – mgk
    Nov 9 '20 at 7:41
  • You can try to ask in chat (chat.stackexchange.com/rooms/41/tex-latex-and-friends) --- several core team developers hang around there, and maybe somebody can help. For testing, maybe you should make available a "packed" (a .tds file would be the best) downloadable without registering...
    – Rmano
    Nov 9 '20 at 9:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.