Skip to main content

Section 21.2 <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 placed inside an <exercises> element, however! The portion of this section headed as “21.3 Exercises” is produced using the code in Listing 21.2.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.
          The <c>statement</c> is mandatory.
          <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.
        </p>
      </statement>
    </exercise>

    <exercise>
      <statement>
        <p>
          Second exercise.
        </p>
      </statement>
    </exercise>

    <exercise>
      <statement>
        <p>
          Third exercise.
        </p>
      </statement>
    </exercise>

  </exercisegroup>

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

</exercises>
Listing 21.2.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> of the form @cols="3". The integer value of @cols must be between 2 and 6 (inclusive).

An <exercisegroup> generates exercises in a separate section or subsection. The code in Listing 21.2.1 produces the output seen in Exercises 21.3.