About
Shop
LaTeX
Software
Books
Gallery
News
Contact
Blog
Settings
Latest news 2019-11-04: The giveaway of two signed copies of “Quack, quack, quack. Give my hat back!” has closed and the winning entrants have been selected. Thank you to everyone who took part.


9.2 The exsheets Package

Unlike the exam class described in the previous section, exsheets is a package, so you need to find a suitable class to use with it. For the examples, I'm just going to use the article class, but you will probably find it easier to use a more flexible class, such as one of the KOMA-Script classes.

As with the exam class, the exsheets documentation [62] is quite long because there are so many options, so this section is just intended as an introduction. Options can be specified via the package option list, or in the optional argument to environments provided by exsheets, or via

\SetupExSheets[module]{option list}

where the options listed in ⟨option list⟩ belong to the given module. If ⟨module⟩ is omitted, the module name is incorporated into the option list. For example, you can either do:

\SetupExSheets[question]{option⟩=⟨value}

or

\SetupExSheets{question/⟨option⟩=⟨value}

where ⟨option⟩ is some option defined for the question module and ⟨value⟩ is the value being assigned to that option. There are a lot of options related to the formatting of counters, question headings and subtitles, as well as options related to the table of contents.

Questions are written inside the question environment.

\begin{question}[options]{points}
question text
\end{question}

Note that the ⟨points⟩ argument is optional, despite the lack of square brackets. The other optional argument, ⟨options⟩, is the list of options. If ⟨points⟩ is omitted, no points will be associated with the question. The ⟨points⟩ may be in the form ⟨p⟩ or p⟩+⟨b or +b⟩, where ⟨p⟩ is the number of points and ⟨b⟩ is the number of bonus points.

Examples:

A question with no points allocated:

\begin{question}
How many kilocalories are there in 100 grammes of exploding 
chocolate?
\end{question}

A question worth five points:

\begin{question}{5}
How many kilocalories are there in 100 grammes of exploding 
chocolate?
\end{question}

A question worth five points and one bonus point:

\begin{question}{5+1}
How many kilocalories are there in 100 grammes of exploding 
chocolate?
\end{question}

The points for each question are added to the total marks. If you don't want the points added for a particular question, you need to put an exclamation mark ! before the points. (This prevents bonus points for the question.)

Example:

A question worth five points where the points aren't added to the running total:

\begin{question}{!5}
How many kilocalories are there in 100 grammes of exploding 
chocolate?
\end{question}

There are a number of key⟩=⟨value options available for the question environment. For a complete list, see the exsheets documentation [62], but here are a few:

type=⟨value
Determines the type of question. The value may be either exam or exercise. In the first case, the question number is preceded by “Question”, in the second case by “Exercise”.
name=⟨name
Replaces the default “Exercise” or “Question” to ⟨name⟩.
subtitle=⟨title
Adds a subtitle.
class=⟨class
Assigns a class to the question.
topic=⟨topic
Assigns a topic to the question.
ID=⟨label
Assigns an ID to the question for later reference.
print
boolean key. If true, the question is displayed. By default this is true.

The solution to a question should come after the question environment and should be placed inside the solution environment.

\begin{solution}[options]
solution text
\end{solution}

As with the question environment, the solution environment also allows the print boolean key in its ⟨options⟩, but by default it's false. The name key is also available in ⟨options⟩ and can be used to replace the default “Solution” text that precedes the solution number.

Example:

\begin{question}
What is the main drawback of ray guns?
\end{question}
\begin{solution}
Overheating.
\end{solution}

By default, the question will appear but the solution won't be displayed. The default result is:

Exercise 1.
What is the main drawback of ray guns?

End of Image.


If you want the solutions to appear where they are defined (that is, after their associated question), you can just add the following:

\SetupExSheets[solution]{print=true}

or

\SetupExSheets{solution/print=true}

However, if you want the solutions to appear later (for example, at the end of the document) you can use

\printsolutions[settings]

at the place where you want the solutions. Note that this command must only be used after all the solutions have been defined. The optional argument is a key=value list. Options include:

chapter
If no value is specified, all solutions to the questions defined in the current chapter are listed. If a value is specified, it may be a comma-separated list or range of chapter numbers. For example, chapter={1-7,10} means chapters one to seven and chapter ten. Remember to use braces around the value if it contains commas.

section
Analogous to the chapter option, but for sections. As above, the value may be omitted, in which case the current section is assumed, or may be a comma-separated list or range of values.

byID
The value should be a comma-separated list of IDs identifying the questions whose solutions should be printed. (Recall the ID option that can be used when you define a question.)
The solutions are sorted automatically according to their order of definition. If you want to prevent this sorting (so that they are, instead, listed in the order specified in the value of byID) you can use the sorted boolean key in the solution module. The sorted key isn't required if the byID key isn't used.

Questions can be assigned to a “class”, which could represent the difficulty level or similar attribute. As described earlier, this is done via the class key when you define a question. You can specify that only questions belonging to a certain class, or list of classes, should be included using the use-classes option. For example:

\SetupExSheets{use-classes={easy,medium,hard}}

indicates to only use those questions that have been assigned to one of the classes: easy, medium or hard. Any questions that haven't been assigned to one of those classes will be discarded.

Similarly, questions can be assigned to a topic using the topic key in the optional argument of the question environment. The option use-topics is analogous to use-classes. There are other commands that allow you to assign properties to questions, but for brevity these are omitted here.

As with the exam class, you can also access the total points and, as before, you need at least two LaTeX runs to get an up-to-date value.

\pointsum

Prints the total number of points (excluding bonus points). This command also has a starred version that omits the “unit”, which is “P.” by default.

\bonussum

Prints the total number of bonus points. As with the previous command, this command also has a starred version that omits the unit.

\totalpoints

Prints the total number of points (including bonus points). This command also has a starred version that omits the unit.

To typeset a number of points without adding it to the cumulative total use:

\points{number}

where ⟨number⟩ is the number of points. As above, this command has a starred version that omits the unit.

There are some other related commands described in the exsheets manual [62], but for brevity aren't covered here. The “unit” can be changed via the name and name-plural keys in the points module. Recall from earlier, that the option can be set using:

\SetupExSheets[points]{name={point},name-plural={points}}

or

\SetupExSheets{points/name={point},points/name-plural={points}}

There are also options for the bonus point unit: bonus-name and bonus-plural. For example:

\SetupExSheets[points]{bonus-name={bonus point},
   bonus-plural={bonus points}}

There are some other options related to the formatting of the points. See the exsheets manual for further details.

There is no provision for multiple choice questions, however you can use the inparaenum environment provided by the paralist package [78].

\begin{inparaenum}[format]
list items
\end{inparaenum}

This is analogous to the enumerate environment except that each item doesn't start a new paragraph (unless you explicitly insert a paragraph break). The optional argument determines the counter format. The tokens A, a, I, i and 1 indicate the counter formats \Alph, \alph, \Roman, \roman and \arabic. (The paralist package also modifies the enumerate environment so that it takes an optional argument that changes the counter format in the same manner.)

Example:

\begin{question}
  Which of the following ingredients are used in 
  mind-controlling cookies:
  \begin{inparaenum}[(A)]
    \item arsenic
    \item cyanide
    \item curare
    \item\label{correct-ingredient} secret genetically modified 
      sugar beet
  \end{inparaenum}
\end{question}
\begin{solution}
Correct choice: \ref{correct-ingredient}.
\end{solution}

You can put all your question and solution environments in an external file to form a databank. These solutions, either all or a subset, can then be included using:

\includequestions[options]{filenames}

where ⟨filenames⟩ is a comma-separated list of filenames. Note that the exsheets documentation comes with a caveat that this command is experimental. The optional argument is a key=value list. Available options are:

all
This is a boolean key. If true, all questions are selected.
IDs
Only those solutions whose ID is contained in the list of IDs. Since this value contains commas, remember to enclose the list with braces.
random
The value should be a number, ⟨n⟩, indicating that ⟨n⟩ questions should be randomly selected.
exclude
Exclude any questions whose ID is contained in this list. Again, since the value contains commas, remember to enclose the list with braces. This option can be combined with the random option.

Exercise 25. Creating an Exam Paper with the exsheets Package

Try rewriting Exercise 24 using the exsheets package instead of the exam class. (You may not be able to automatically implement some features, such as the grading table.) You can download or view a solution.


This book is also available as A4 PDF or 12.8cm x 9.6cm PDF or paperback (ISBN 978-1-909440-07-4).

© 2015 Dickimaw Books. "Dickimaw", "Dickimaw Books" and the Dickimaw parrot logo are trademarks. The Dickimaw parrot was painted by Magdalene Pritchett.

Terms of Use Privacy Policy Cookies Site Map FAQs