Skip to main content

The PreTeXt Guide

Section 4.13 Exercises and their Solutions

As described in Section 3.9 an <exercise> can be placed in many different locations, and a <project> has similar features. It is critical to understand that you want to author any hints, answers, or solutions immediately following the statement of an exercise. If your PreTeXt source is public, and you would like to keep some aspects of the solutions private, then read Section 36.1 for some practical advice. See Section 37.2 as well for information on creating a standalone Solutions Guide. We concentrate here on techniques for controlling visibility and location of the components of exercises within your primary output.

Subsection 4.13.1 Exercises, Original Versions

In a conversion to HTML, a <hint> to an <exercise> renders nicely in a knowl, right below the exercise statement. For a conversion to /PDF/print, you might wish to display a hint, visibly, as part of the exercise, or you may wish to park the hint in a Hints to Exercises division in the back matter. To control visibility of the components of exercises (and projects) there are twenty switches you can use. See Section 26.4 for more.

Subsection 4.13.2 Exercises, Solutions Versions

Exercises, and their components may be duplicated easily, to provide a back matter appendix with solutions, or within each division. For example, you can easily create an end-of-chapter division with solutions to every inline exercise throughout the chapter and solutions to all the divisional exercises from each section of the chapter.
The <solutions> element will create an entire division, semi-automatically. You can provide a <title>, an <introduction>, and <conclusion>. The remaining content is statements, hints, answers, and solutions to exercises (and projects).
If <solutions> is a child of <backmatter>, then an appendix will be generated, and covering <exercise> from the entire <book> or <article>. If <solutions> is a child of a division, then a new subdivision is created and the scope is all <exercise> for the division. So, for example, a <solutions> placed inside a <chapter> will render as a division that looks like a <section> and will include components of all the exercises (at any level) contained within the <chapter>.
An optional attribute is @scope, whose value is the @xml:id of a division. Then it is this division which is scanned for exercises and their solutions (rather than defaulting to the enclosing parent of the <solutions>). This allows for much greater flexibility. For a simple example, suppose a <chapter> contains two <exercises>, and you want to have two <solutions> within the chapter, each covering just one of the <exercises>. This can be accomplished with @scope, and you can arrange the four divisions (two <exercises> and two <solutions>) however you wish within the chapter.
An author filters the types of exercises, and their components, through attributes of the <solutions> element. For example
reading="hint answer"
would cause every <exercise> within each <reading-questions> to have its <hint> and <answer> displayed, but not its <statement> nor its <solution>. These are the attribute names and the possible values.
Table 4.13.1. Attributes (left) and Values (right) for <solutions> element
inline statement
divisional hint
reading answer
worksheet solution
project
So, PreTeXt source like
<section>
  <title>Tropical Bird of Paradise<title>
  ...
  <solutions worksheet="hint solution" project="hint solution">
    <title>Hints and Solutions to Worksheets and Projects<title>
  </solutions>
</section>
would generate an entire subsection with hints and solutions to every worksheet and every project, located anywhere (including in subsections and subsubsections) in the section on Birds of Paradise.
An @admit attribute specifies some feature of an exercise’s serial number to determine whether its components are admitted into the solutions division. (For example, the “serial number” of Exercise 1.2.3 is 3.) Presently, the only options are odd, even, and the default all. So, PreTeXt source like
<solutions divisional="answer" admit="odd">
would generate a subsection with answers to only the odd-numbered divisional exercises.