Skip to main content

The PreTeXt Guide

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 Attributes (left) and Values (right) for <solutions> element
inline statement
divisional hint
reading answer
worksheet solution
So, PreTeXt source like
  <title>Tropical Bird of Paradise<title>
  <solutions worksheet="hint solution" project="hint solution">
    <title>Hints and Solutions to Worksheets and Projects<title>
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.