(There are a number of packages for making exams, and a variety of questions addressing related issues on this forum. However, I haven't found one solution to meet all my needs for making an exam. These functions I look for are commonly available from commercial packages for making exams; however, such programs often lack the convenience of typesetting mathematical content and the ease and precision of controlling the format as LaTeX has.)

I would like to make an exam consisting of primarily multiple-choice questions and occasionally questions with blanks to fill or short answers. Specifically, I would like to

  1. Have the option to generate an exam in a number of scrambled versions, where either the answer choices (A, B, C, D) or the questions themselves (or both) are randomized independently in each version. I would also like to generate a separate answer key for each scramble version (for my use when grading).
  2. Have the option to keep the position of some answer choices fixed during the scrambling. For example, an answer choice that says "All of the above" is only appropriate to be placed as choice D among four choices.

Above are the more essential requests. Below are some optional ones that can also be helpful:

  1. In the answer key pages, have the option to either print the answer key only (i.e., just the letters A, B, C, D) or print a short explanation for the answer along with the correct answer.
  2. Scramble questions only within each type of question (multiple-choice, fill-in-the-blank, short answer, etc.)
  3. Be able to label each question, and have the option of including the question label when printing (probably not useful for making exams, but helpful for my own document keeping).
  4. When generating scrambled versions, generate a separate sheet listing the question labels and their corresponding number in each of the scrambled versions.
  5. Be able to keep the position of some questions fixed while the rest are scrambled.

3 Answers 3


You can have a look at the esami package: you can scramble questions; you can scramble multiple choices answers, and you can fix the last ones; you can fix the position of the answers or the order of the questions.

Your number 3 request is possible, but not completely tested.

Your number 4 request is possible if you divide exercises by type.

Your number 5 and 6 requests are partially implemented, but it is not possible to print the label in the exam, only on an external file.

Your number 7 request is possible if you separate questions you want to fix from the ones you want to scramble.

  • Thank you for your answer! I took a look at the esami package, but find its documentation a little too advanced for me to understand. Is there some easier user guide that I may start with? Thank you!
    – tvk
    Commented Apr 4, 2017 at 23:18
  • 1
    Sorry, there is no other documentation available except for the one which comes with the package. However, there are some example files in the doc folder: you can try to copy them in a folder of your choice, compile and make adjustments on that model. They are extensively commented. Be sure to change the name of the master file, as you cannot compile it with the name master.tex.
    – grames
    Commented Apr 6, 2017 at 8:04

You can have a look at Auto Multiple Choice, which answers your needs number 1, 2, 3 (only for open questions), 4, 5, 7. You will also be able to mark the completed answer sheets automatically from their scans (on linux or macosx).


This is something I'm currently working on. I wrote the questions and possible answers in separate files, and use a short MATLAB/Octave script to concatenate them in a random order.

For example, if I have 10 question files Q.1,...,Q.10 and 4 possible answers for each one of them, A.1.1,...,A.1.4,...,A.10.1,...,A.10.4 (self-explanatory file names), I use something like

nl=fopen('newline','w');    %create a file with only a new line character, because it is useful

bq=fopen('beginq','w');    %file with '\begin{question}'

eq=fopen('endq','w');    %file with '\end{question}'

ba=fopen('begina','w');    %file with '\begin{answer}' (could be a '\begin{itemize}[label=(\alph*)] , for example, if using the `enumerate` package)

ea=fopen('enda','w');    %file with '\end{answer}'
Q = rand(10);    %randomize order of questions

for i=1:10
    R = rand(4);    %randomize order of answers

    %the next line uses a batch script to concatenate and create a file 'question<i>' with the i-th question
    system(sprintf('copy beginq+Q.%d+begina+A.%d.%d+A.%d.%d+A.%d.%d+A.%d.%d+enda+endq question%d',Q(i),Q(i),R(1),Q(i),R(2),Q(i),R(3),Q(i),R(4),i));

%now concatenate all questions into a file 'exam.tex'
system('copy question1+question2+question3+question4+question5+question6+question7+question8+question9+question10 exam.tex');

(My code is a little different, but the one above should work). You can add some more things, such as having a vector which remembers the correct answer (a simple way is to always make the first answer A.i.1 the right one; just check which entry of the R vector has a 1).

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .