2

I am using Moodle package. I would like to print a pdf without the correct answers. How can I do it ?

With the following code, the pdf contains the answers and the questions.

\documentclass[12pt]{article}
\usepackage{moodle}
\usepackage{amsmath}
\begin{document}

\begin{quiz}{Quizz 2}

\begin{numerical}[points=2]{Addition}
2+2=
\item 4
\end{numerical}  

\begin{shortanswer}[case sensitive=false]{Hugo}
Firstname of Hugo
\item  Victor
\end{shortanswer}

\end{quiz}
\end{document}

How can I have only the questions in the generated pdf file ?

Thanks for you help.

2
  • 1
    Welcome to TeX.SE! Clarification question: do you actually want to use the quiz on Moodle, or you are only interested in the PDF? If you want to use the quiz on Moodle, then why do you want a pdf without answers instead of your students looking at the question on Moodle itself? If you don't want to use the quiz on Moodle, then there are several other packages for making exams in LaTeX that have much better customization options than the moodle package. – Marijn May 14 '20 at 14:19
  • 1
    I want both ;-) I mean using this package to publish online questions and also to have a pdf to put questions on my website and to send by email for my students (some of them have trouble with internet so a pdf by email is easier) . I hope it would be possible. – Lafourcade Pascal May 15 '20 at 11:33
4

There is no package option for this as far as I can see. However, you can prevent the Latex output part of the internal answer processing routines from being executed by redefining the relevant commands as \relax (i.e., do nothing). There are five such commands, for short answers, numerical, multiple choice, matching, and essay questions.

For multiple choice questions it would be useful to still show the answers but don't show the tick mark for the correct answer. Therefore for this question type the answer processing should not be switched off completely by replacing the command with \relax. Instead you can redefine the command to first locally redefine the \checkmark command to print nothing, (\checkmark is from the amssymb package, this command is used to print the checkmark after the correct answer in Moodle), and then proceed with the rest of the code. In the code below this is done by copying the processing code to a second command using \let, then redefining the original command to first change the definition of \checkmark and then call the copy of the original command.

The definition of \checkmark inside of multi@latexprocessing allows you to use the checkmark symbol in the question itself or elsewhere in the document if needed, however it is no longer possible to use the symbol in one of the answers for any multiple choice question.

For matching questions the situation is a bit more complicated, because there ideally you want to show both the questions and the answers, but shuffled. During processing of a question-answer pair the other questions and answers are not easily available though, so that would require a more substantial rewrite of the code and is therefore not implemented in the code below.

MWE:

\documentclass[12pt]{article}
\usepackage{moodle}
\usepackage{amsmath}
\makeatletter
\def\moodle@shortanswer@latexprocessing{\relax}
\def\moodle@numerical@latexprocessing{\relax}
\let\origmultiprocessing\moodle@multi@latexprocessing
\def\moodle@multi@latexprocessing{\let\checkmark\relax\origmultiprocessing}
%\def\moodle@matching@latexprocessing{\relax} % it's complicated
\def\moodle@essay@latexprocessing{\relax}
\makeatother
\begin{document}

\begin{quiz}{Quizz 2}

\begin{numerical}[points=2]{Addition}
2+2=
\item 4
\end{numerical}  

\begin{shortanswer}[case sensitive=false]{Hugo}
Firstname of Hugo
\item  Victor
\end{shortanswer}

\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}

Result:

enter image description here

This does not affect the XML output, there the answers are still present.

<?xml version="1.0" encoding="UTF-8"?>
<quiz>
 
<question type="category">
  <category>
    <text>$module$/Quizz 2</text>
  </category>
</question>
 
<question type="numerical">
  <name>
    <text>Addition</text>
  </name>
  <questiontext format="html">
    <text><![CDATA[<p>2+2= </p>]]></text>
  </questiontext>
  <defaultgrade>2</defaultgrade>
  <generalfeedback format="html"><text/></generalfeedback>
  <penalty>0.1000000</penalty>
  <hidden>0</hidden>
  <answer fraction="100" format="plain_text">
    <text>4</text>
    <tolerance>0</tolerance>
  </answer>
</question>
<question type="shortanswer">
  <name>
    <text>Hugo</text>
  </name>
  <questiontext format="html">
    <text><![CDATA[<p>Firstname of Hugo </p>]]></text>
  </questiontext>
  <defaultgrade>1.0</defaultgrade>
  <generalfeedback format="html"><text/></generalfeedback>
  <penalty>0.1000000</penalty>
  <hidden>0</hidden>
  <usecase>0</usecase>
  <answer fraction="100" format="plain_text">
    <text>Victor</text>
  </answer>
</question>
<question type="multichoice">
  <name>
    <text>A first derivative</text>
  </name>
  <questiontext format="html">
    <text><![CDATA[<p>What is the first derivative of \(x^3\)? </p>]]></text>
  </questiontext>
  <defaultgrade>3</defaultgrade>
  <generalfeedback format="html"><text/></generalfeedback>
  <penalty>0.1000000</penalty>
  <hidden>0</hidden>
  <single>true</single>
  <shuffleanswers>1</shuffleanswers>
  <answernumbering>abc</answernumbering>
  <answer fraction="0" format="html">
    <text><![CDATA[<p>\(\frac {1}{4} x^4+C\)</p>]]></text>
  </answer>
  <answer fraction="100" format="html">
    <text><![CDATA[<p>\(3x^2\)</p>]]></text>
  </answer>
  <answer fraction="0" format="html">
    <text><![CDATA[<p>\(51\)</p>]]></text>
  </answer>
</question>
 
</quiz>
4
  • THANKS A LOT ! IT SOLVES MY ISSUE ! :-) – Lafourcade Pascal May 15 '20 at 15:11
  • @LafourcadePascal you're welcome :) – Marijn May 15 '20 at 15:12
  • The proposed solution works for essays, numerical and shortanswers, however, this is not useful if I want to hide only the tick after the correct answer in the multi environment without hiding the multiple choice. Is there a way to achieve that as well? Thanks in advance. – KArrow'sBest Aug 21 '20 at 14:44
  • @KArrow'sBest thank you for your comment, I didn't think about this when I wrote the answer. I have added a modification for multiple choice questions that keeps the answers but removes the tick mark. – Marijn Aug 22 '20 at 12:17
0

@Marijn's answer is a very good option if you use moodle version 0.5 and you neither care about cloze and matching type questions, nor about the shuffling options of multichoice type questions.

Otherwise, the desired feature was added to version 0.8 of the moodle package, as package option: handout.

From the documentation:

[...] if the package option handout is invoked (\usepackage[handout]{moodle}), the PDF file is generated clean from teacher-only information (answers, points, penalty, feedback, tags) and, hence, can be given to students for classroom work. In particular, as would Moodle do, answers in matching questions are shuffled and the option shuffle triggers the shuffling of choices offered (multi and matching). This is achieved thanks to the package randomlist, loaded if the option is invoked. The XML file is generated as usual.

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.