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




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

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

  • 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.