.. _mcq-moodle: ================================================================ MCQ-XeLaTeX: How to use it with Moodle and for online exams ================================================================ :Date: 2020-04-01 (updated 2024-01-19) 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 :download:`mcq.py ` and :download:`mcq.sty ` . Just in case, the OMR (Optical Mark Recognition) script can be found here: :download:`omarscan.py `. Multiple Choice Questions ------------------------- .. highlight:: latex As in the :ref:`MCQ-Latex` 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} .. highlight:: bash 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. .. highlight:: latex 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 :ref:`MCQ-Latex` 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. .. highlight:: latex So, write a tex file as described in :ref:`MCQ-Latex`, 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*} .. highlight:: bash Variants can be automatically generated by :ref:`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 ``}}``. .. highlight:: html Example of ``templatefile.html`` content (the first line is **necessary**)::

»Download the PDF document: ({PDF})«

The file I would use::

»Scaricare qui il testo in PDF: ({PDF})«

[PRIMA DELLA FINE CARICARE IL FILE PDF (document-scan) DEL COMPITO SVOLTO QUA SOTTO]
[Controllare di avere caricato correttamente il file prima di inviare tutto e terminare la prova]

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.