3

I want to write exams where the questions and answers are randomized, and mcexam lets me do almost everything I want. However, I would also like each question to be picked randomly from a group of questions. For instance, I may want one question on the exam about the product rule, so from a group of 5 questions, one of them is randomly selected to be on the exam. I'm currently using pgfmath and I thought it was working great, but then I realized that sometimes it takes bits and parts of the questions and pieces them together.

In the code there are two questions to be picked from: "Which is not a fruit?" and "What color is an emerald?" What's happening is the output will have "Which is not a fruit?" but then the answer choices are the ones for "What color is an emerald?" or vice versa. Why is this happening and is there something I can do to fix this? I am not overly familiar with latex. Thanks!

enter image description here

\documentclass[12pt]{article}
    \usepackage{pgfmath}
    \usepackage{tikz,framed} 
    \usepackage[output=exam
               ,numberofversions=1
               ,version=1
               ,seed=6
               ,randomizequestions=true
               ,randomizeanswers=true
               ,writeRfile=false
               ]{mcexam}

\begin{document}
\begin{mcquestions}

\question  

\pgfmathrandom{2}  % store 1 or 2 in \pgfmathresult
\ifnum\pgfmathresult=2
{  
    Which is not a fruit?
    \begin{mcanswerslist}
        \answer[correct] Pepper
        \answer Apple
        \answer  Grape
        \answer Banana
    \end{mcanswerslist}
}
\else 
{   What color is an emerald?
    \begin{mcanswerslist}
        \answer[correct] Green
        \answer  Blue
        \answer Red
        \answer Yellow
    \end{mcanswerslist}
}
\fi

\question  
    This is the second question, needed in order to run. 
    \begin{mcanswerslist}
        \answer[correct] Answer 1
        \answer Answer 2
        \answer  Answer 3
        \answer Answer 4
    \end{mcanswerslist}  

\end{mcquestions}
\end{document}
  • 1
    Welcome to TeX.SE! – Mensch Mar 19 at 3:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.