Skip to main content

Section 15.2 Example-Like Elements

PreTeXt provides three closely-related tags for things that are examples or similar. They are <example>, <problem>, and <question>. They all have the same syntax. The <title> element is optional, but encouraged as discussed in Best Practice 4.8.1. You may either use a freeform example, as shown in Listing 15.2.1, or an example structured with a <statement> and zero or more <hint>s, <answer>s, and <solution>s (in that order). This is illustrated in Listing 15.2.3. Note that for HTML output, if your <example> has a <solution>, the solution will be hidden in a knowl by default. See Section 29.2 for information on changing this behavior.

Aside: Author vs. publisher.

Listing 15.2.1. A simple example
<!--********************************************************************
Copyright (C) 2019-2026  Robert A. Beezer

This file is part of PreTeXt.

PreTeXt is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 or version 3 of the
License (at your option).

PreTeXt is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with PreTeXt.  If not, see <http://www.gnu.org/licenses/>.
*****************************************************************-->

<example>
  <title>Differentiating a polynomial</title>
  <p>
    The derivative of the function
    <m>f(x) = 3x^5-7x+5</m> is <m>f'(x) = 15x^4-7</m>.
  </p>
</example>
The code in Listing 15.2.1 produces the following output:

Example 15.2.2. Differentiating a polynomial.

The derivative of the function \(f(x) = 3x^5-7x+5\) is \(f'(x) = 15x^4-7\text{.}\)
If you are reading this in HTML with the default processing options applied, the example above will be knowled. This is the PreTeXt default only so that authors know that knowls exist. See Section 29.2 for information on changing this behavior.
Listing 15.2.3. A structured example
<!--********************************************************************
Copyright (C) 2019-2026  Robert A. Beezer

This file is part of PreTeXt.

PreTeXt is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 or version 3 of the
License (at your option).

PreTeXt is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with PreTeXt.  If not, see <http://www.gnu.org/licenses/>.
*****************************************************************-->

<example>
  <title>Differentiating a polynomial</title>
  <statement>
    <p>
      Differentiate the function <m>f(x) = 3x^5-7x+5</m>.
    </p>
  </statement>
  <answer>
    <p>
      <m>f'(x) = 15x^4-7</m>
    </p>
  </answer>
  <solution>
    <p>
      We use the power, sum,
      and constant multiple rules and find that the derivative is <m>f'(x) = 15x^4-7</m>.
    </p>
  </solution>
</example>
The code in Listing 15.2.3 produces the following output:

Example 15.2.4. Differentiating a polynomial.

Differentiate the function \(f(x) = 3x^5-7x+5\text{.}\)
Answer.
\(f'(x) = 15x^4-7\)
Solution.
We use the power, sum, and constant multiple rules and find that the derivative is \(f'(x) = 15x^4-7\text{.}\)