MCQ-XeLaTeX: How to use it with Moodle and for online exams¶
- Date
2020-04-01 (updated 2024-11-14)
Online exams, Multiple Choice Questions in XeLaTeX, and Moodle¶
Two types of assessment: multiple choice question, and mathematics essay.
The first: on-screen selection of answer from a set of possible choices. The second: a PDF with some exercises/open questions is given via moodle, then the student writes solutions/answers on a sheet of paper, document-scans them to a PDF file before the end of the exam, and uploads it as essay to moodle.
Needed files: last versions of
mcq.py
and
mcq.sty
.
Just in case, the OMR (Optical Mark Recognition) script can be found here:
omarscan.py
.
Multiple Choice Questions¶
As in the LaTeX documentation of mcq.sty documentation, create a XeLaTeX file with questions, default marking values, and answers. An example:
\documentclass{article}
\usepackage{mcq}
\moodlecategory{2020-04-21 test quiz}
%===================================================================
\headline{Example Course, No Date (16:00, U1-09)}
\puntigiusta{3} % points for a correct answer
\puntisbagliata{-1} % points for a wrong answer
\puntiempty{0} % points for non-response.
\begin{document}
\begin{esercizi}{}
\begin{exerm}
What is the color of Mars?
\begin{rispm}
\risp[=] red %This is the correct answer
\risp green
\risp blue
\risp white
\end{rispm}
\end{exerm}
\begin{exerm}
$1+3=$ ...
\begin{rispm}
\risp[=] 4 %This is the correct answer
\risp 3
\risp 2
\risp 5
\end{rispm}
\end{exerm}
\end{esercizi}
\end{document}
Then simply generate a .gift.txt
file:
$ mcq.py --gift filename.tex > filename.gift.txt
The output can be imported in MOODLE as plain/text file. Select format: GIFT.
If the command \moodlecategory{categoryname}
is used in the tex preamble, the questions
will be imported in the category categoryname
(if the names of the esercizi sections are empty) or categoryname/sectionname for each section name of groups of questions:
\begin{esercizi}{sectionmame}
...
\end{esercizi}
\begin{esercizi*}{sectionname2}
\end{esercizi}
The quiz can then easily be generated: each question score is normalized to 1. Just add all necessary questions to a Moodle quiz (permuted answers and questions, duration, …). Check LaTeX documentation of mcq.sty for full details.
Essay Questions¶
Being mathematics, you need to give a PDF document as exam, and expect the student to upload a PDF document at the end of the exam duration.
So, write a tex file as described in LaTeX documentation of mcq.sty, full of exercises with variants and solutions:
\usepackage[bubblesheet,doexe,sol]{mcq}
...
\begin{esercizi*}{}
...
\begin{exe}
\begin{varianti}
\varitem
Question 1 \blank{Answer 1}
\varitem
Question 2 \blank{Answer 2}
\varitem
Question 3 \blank{Answer 3}
\end{varianti}
\end{exe}
...
\end{esercizi*}
Variants can be automatically generated by CASengine, if necessary. Now, generate a number of copies (either with mcq CLI, or with the command):
$ mcq.py -n 50 filename.tex
$ xelatex filename_exam.tex
$ xelatex filename_exam.tex
Remove the sol
option to remove the warning.
Now, how to split the output filename_exam.pdf
into 50 single PDF documents, and assign
one to each to the students?
Just use the --split-for-moodle=
option in mcq:
$ mcq.py --split-for-moodle=templatefile.html filename_exam.pdf
The file templatefile.html
must exist, and its content is the HTML part of the essay
question given to moodle, with the following important two template variables:
{SecretFolder} = the "secret" folder were all the files
will be stored (local and remote)
{PDF} = the PDF of the exam
The syntax is the python strings format
mini-language: the only two variables are {SecretFolder}
and {PDF}
. If
one needs to include a brace character in the literal text, it can be escaped by doubling:
{{
and }}
.
Example of templatefile.html
content (the first line is necessary):
<p>
<a href="https://www.example.com/subdir/{SecretFolder}/{PDF}">
»Download the PDF document: ({PDF})«
</a>
</p>
The file I would use:
<p>
<a href="https://www.dlfer.xyz/var/{SecretFolder}/{PDF}">
»Scaricare qui il testo in PDF: ({PDF})«
</a>
</p>
<p>[PRIMA DELLA FINE <b>CARICARE IL FILE PDF</b> (document-scan)
DEL COMPITO SVOLTO QUA SOTTO]<br>
[Controllare di avere caricato correttamente il file
prima di inviare tutto e terminare la prova]
</p>
It will split the PDF
document into 50 documents, each tagged with the unique four-characters
code of the variant, and generate a moodle XML archive of 50 essay questions
each linking to the proper PDF in the external URL. The files are in a SecretFolder
,
which means are created and stored in a folder with a hashed name, such as 7Rse-RseH-seHD
.
Upload the folder with the PDF documents to a suitable public website, the one set in the template.
Create a category in moodle, or have it defined in tex by \moodlecategory{cat}
.
Import the XML questions file in the catogory, or get it taken from the moodle XML file.
Then create a moodle quiz with just one random question taken from the given category.
Important
The files are supposed to be hosted in an external web site (until I will understand how to predict uploaded file URLs, in moodle), if you want to use the generated moodle_xml. Otherwise, just manually create essay questions in moodle and attach each one of the PDF files to each one of manually created questions.