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
<exercise>renders nicely in a knowl, right below the exercise statement. For a conversion to LaTeX/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.
<solutions>element will create an entire division, semi-automatically. You can provide a
<conclusion>. The remaining content is statements, hints, answers, and solutions to exercises (and projects).
<solutions>is a child of
<backmatter>, then an appendix will be generated, and covering
<exercise>from the entire
<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
An optional attribute is
@scope, whose value is the
@xml:idof 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
<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
<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
would cause every
<reading-questions>to have its
<answer>displayed, but not its
<solution>. These are the attribute names and the possible values.
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.
@admitattribute 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
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.