Skip to main content

The PreTeXt Guide

Section 16.3 Divisions of <exercise>s

You can also put several <exercise>s as part of an <exercises> element within a division, which is the typical way for creating a collection of exercises togther at the end of a division such as a chapter or section. The content of an <exercises> division is rather limited. It can begin with an <introduction> (perhaps a set of common instructions), followed by a mixture of <exercise> and <exercisegroup> (see Subsection 16.3.1) elements, followed by an optional <conclusion>. The sample code in Listing 16.3.1 illustrates this structure, which is rendered later as “16.4 Exercises”.
An alternative structure for an <exercises> division is to use a sequence of <subsexercises> elements, optionally preceded by an <introduction> and followed by a <conclusion>. The content of a <subexercises> element is identical to what was described above for an <exercises> element, but we emphasize that a strong rationale for using <subexercises> (as opposed to <exercisegroup>) is that a <subexercises> element can begin with a <title>, providing a clear way of organizing the <exercise>s for the reader.

Subsection 16.3.1 <exercisegroup>

Sometimes you have several exercises that should all have a common set of instructions, which is when you will use the <exercisegroup> tag. An <exercisegroup> can only be used as part of an <exercises> element or a <subexercises> element, however! The portion of this section headed as “16.4 Exercises” is produced using the code in Listing 16.3.1.
<exercises xml:id="basics-s-sample-exercises">
  <exercisegroup>

    <introduction>
      <p>
        Here's where you put the common instructions.
      </p>
    </introduction>

    <exercise>
      <statement>
        <p>
          First exercise.
          <idx><h sortby="statement"><tag>statement</tag></h><h sortby="of an exercise">of an <tag>exercise</tag></h></idx>
          <idx><h sortby="exercise"><tag>exercise</tag></h><h sortby="statement"><tag>statement</tag></h></idx>
          You can add all the usual bells and whistles after,
          but we'll keep it short here.
          (The <tag>statement</tag> may be omitted if none of
          <tag>hint</tag>, <tag>answer</tag>, or <tag>solution</tag>
          are present as a child of the <tag>exercise</tag>.)
        </p>
      </statement>
    </exercise>

    <exercise>
      <statement>
        <p>
          Second exercise.
        </p>
      </statement>
      <hint>
        <p>
          The <tag>statement</tag> for this exercise is necessary because we
          have included at least one of
          <tag>hint</tag>, <tag>answer</tag>, or <tag>solution</tag>
          (namely, <tag>hint</tag>).
        </p>
      </hint>
    </exercise>

    <exercise>
      <p>
        Third exercise.
        (No <tag>statement</tag> necessary here because no
        <tag>hint</tag>, <tag>answer</tag>, or <tag>solution</tag>.)
      </p>
    </exercise>

  </exercisegroup>

  <exercise>
    <p>
      This <tag>exercise</tag> is not inside the <tag>exercisegroup</tag>.
    </p>
  </exercise>

</exercises>
Listing 16.3.1. Using an <exercisegroup>.
If you want the contents of an <exercisegroup> to be put in multiple columns, you can add a @cols attribute to the <exercisegroup> with value (for example) 3. The integer value of @cols must be between 2 and 6 (inclusive).
The code in Listing 16.3.1 produces the output seen in Exercises 16.4.

Subsection 16.3.2 Reading questions

Another specialized division, <reading-questions>, can be used to house <exercise>s designed to test or guide a reader’s comprehension of the material in that division. The structure of a <reading-questions> element is similar to an <exercises> element, but without the grouping options of <subexercises> and <exercisegroup>. The portion of this section headed as “16.3.3 Check your understanding!” is produced using the code in Listing 16.3.2.
<reading-questions xml:id="basics-reading-questions">
  <title>Check your understanding!</title>
  <introduction>
    <p>
      Here is a spot to explain the purpose of these questions. It's
      optional, like most introductions.
    </p>
  </introduction>

  <exercise>
    <statement>
      <p>
	Here is a question.
      </p>
    </statement>
    <hint>
      <p>
        A little hint.
      </p>
    </hint>
    <answer>
      <p>
        Just the answer.
      </p>
    </answer>
    <solution>
      <p>
        All the glorious details about an answer.
      </p>
    </solution>
  </exercise>

  <exercise>
    <statement>
      <p>
	A second comprehension question. We don't bother with answers
	or solutions.
      </p>
    </statement>
  </exercise>

  <conclusion>
    <p>
      A little wrap up, perhaps giving guidance or encouragement if
      the student struggled with the questions. Optional like most
      conclusions. 
    </p>
  </conclusion>

</reading-questions>
Listing 16.3.2. Structure of <reading-questions>.

Reading Questions 16.3.3 Check your understanding!

Here is a spot to explain the purpose of these questions. It’s optional, like most introductions.

1.

Here is a question.
Hint.
A little hint.
Answer.
Just the answer.
Solution.
All the glorious details about an answer.

2.

A second comprehension question. We don’t bother with answers or solutions.
A little wrap up, perhaps giving guidance or encouragement if the student struggled with the questions. Optional like most conclusions.
You have attempted of activities on this page.