Over the years I have developed some scripts for generating banks of questions for Moodle so that students can challenge themselves and check their answers. Sometimes I have been dealing with hundreds of students so an automated procedure is needed.
After checking with colleagues from my department at UPC and many hours of trial and error, I finally ended with the following solution, which works for GNU/Linux systems (although I guess that also works for other systems).
Requirements
The process needs the following components:
A Python install (Python3).
The SymPy Python library for symbolic mathematics. Check the website for install and docs.
Lualatex, an extended version of pdfTeX using Lua as an embedded scripting language. For Ubuntu/Debian distributions, it can be found under the ‘texlive-lualatex’ systems. Pdflatex did not work for me because of UTF-8 encoding.
The moodle package for LaTeX. For Ubuntu/Debian systems, this package is included in ‘texlive-latex-extra’.
Steps
Update ‘sample-quiz-generator.py’ to tailor your wishes.
Execute this file using Python, for instance, in bash,
python ./sample-quiz-generator.py
This will generate a TeX file ‘chunks-moodle.tex’ which contains the different questions and is included within the main file ‘template-python-moodle.tex’
Run LuaLaTex to compile the file:
lualatex template-python-moodle.tex
This will create a PDF with solutions to preview and an XML to upload to Moodle.
Upload the XML file to the platform of your choice.