# Problems using moodle package in Latex with TexShop. The XML file generated is not accepted by MoodleCloud

I don't known where is the problem:

File

\documentclass[12pt]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{graphicx}
\usepackage{moodle}
\begin{document}
\begin{quiz}{My first quiz}
%What is $8+3$?
%\item 11
%\end{numerical}
What was Newton’s first name?
\item Isaac
\item[fraction=0, feedback={No, silly!}] Fig
\item{fraction=0} Sir
\begin{multi}[points=3]{A first derivative}
What is the first derivative of $x^3$?
\item  $\frac{1}{4} x^4+C$
\item* $3x^2$
\item  $51$
\end{multi}
\end{quiz}
\end{document}


Here is an screenshot of the error in moodlecloud:

• Well it looks like this is a Moodle problem rather than a TeX problem, so it's unlikely that anyone here can help ... unless ... I note that the example in the package documentation is not identical to yours. It loads no packages except moodle.sty. What happens if you delete all the packages you added (you will also need to replace the apostrophes with ordinary single right quotes)? Jun 19 '20 at 20:10
• ... my experience is that if you have non-ascii chars at all, you need to remove all the font encoding packages and use lualatex to compile. Jun 19 '20 at 23:30
• Thank you so much for your help! Jun 21 '20 at 12:14

The problems here are the following:

1. moodle.sty does not work with mainly any package. I left the amsmath packages here, for the sake of the PDF, but notice that the rendering of math formulas in Moodle is made by MathJax, not LaTeX itself; for simple formula there are no problem, but you need to check them.

2. Your apostrophe in "Newton’s name" is not an ASCII apostrophe, but Unicode Character 'RIGHT SINGLE QUOTATION MARK' (U+2019). moodle.sty is unable to process this with pdflatex; especially in the name of the quiz the resulting XML is confusing the (frankly poor) Moodle parser.

This file (still with your fancy apostrophe):

\documentclass[12pt]{article}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{graphicx}
\usepackage{moodle}
\begin{document}
\begin{quiz}{My first quiz}
What was Newton’s first name?
\item Isaac
\item[fraction=0, feedback={No, silly!}] Fig
\item{fraction=0} Sir
\begin{multi}[points=3]{A first derivative}
What is the first derivative of $x^3$?
\item  $\frac{1}{4} x^4+C$
\item* $3x^2$
\item  $51$
\end{multi}
\end{quiz}
\end{document}


if compiled with lualatex (probably with xelatex also, didn't check), gives a correct XML:

• Thank you so much! Jun 21 '20 at 22:33
• So after this I started downloading the TEX LIVE to have Xelaex. I am really giving my first steps to solve an issues on my own with your help! please be patients since I am really not used to things here. In fact I am confused why I need to install Mactex since I already have Texshop installed and it seems it came form same place. But indeed what happens is that doing this download didn't work since I have El Capitan system 10.11.6. So I did like for Unix I think and now I have the messages Jun 21 '20 at 22:37
• Add /usr/local/texlive/2020/texmf-dist/doc/man to MANPATH. Add /usr/local/texlive/2020/texmf-dist/doc/info to INFOPATH. Most importantly, add /usr/local/texlive/2020/bin/x86_64-darwinlegacy to your PATH for current and future sessions. Jun 21 '20 at 22:37
• And i really don't know what to do with this Jun 21 '20 at 22:37
• I also recommend the use of a UTF8 native TeX engine (XeLaTeX, LuaLaTeX). If pdflatex is required, there is a version of the moodle package that is still in development. With this version, the encoding of the XML file is properly declared as iso-8859-1 (latin1), such that the moodle import sometimes works (some characters given with UTF8 encoding will still lead to trouble). But in addition, support for more accented characters was added, the LaTeX way of writing. Development happens here.
– mgk
Nov 12 '20 at 13:52

I notice that this package is not compatible with UTF-8 source files. Even if you use a latin1 inputenc environment, the XML generates has UTF-8 declared as its encoding. You may manually change it to ISO-8859-1 or use some script I wrote:

#! /bin/bash

for i in *.xml; do
sed -i  's/UTF-8/ISO-8859-1/g' \$i;
done

exit 0;


Be aware that it will act on any XML file in that folder. After converting XML files thjing workd fine here.

Hope it helps.