Skip to main content

Section 16.5 WeBWorK Exercises

It is possible to embed WeBWorK exercises into a PreTeXt document. It is possible to build an HTML version in which readers can answer these exercises and find out if their answer is correct or incorrect. However, results of WeBWorK exercises cannot yet be recorded to your gradebook. Because WeBWorK content belongs inside an <exercise>, you can include WeBWorK exercises in any of the elements that can contain an <exercise> such as a <worksheet> and <reading-questions>. There's some configuration required use WeBWorK. Please see Chapter 7 and Chapter 35 for more details. As soon as you add WeBWorK exercises, compiling to produce any output format becomes a multistep process.

When a WeBWorK exercise lives on the server, the code takes one simple form.

<exercise>

  <introduction>
    <p>
      Optional introduction
    </p>
  </introduction>

  <webwork source="Library/ma122DB/set12/s5_4_26.pg" />

  <conclusion>
    <p>
      Optional conclusion
    </p>
  </conclusion>

</exercise>
Listing 16.5.1. A WeBWorK exercise living on the server

The code in Listing 16.5.1 produces the following output:

Optional introduction

\(\displaystyle \int_0^{1} (4 e^x+5 \sin x)\, dx\) =

Answer.

\(9.17161578449548\)

Solution.

SOLUTION

\begin{equation*} \begin{array}{rcl} \displaystyle \int_0^{1} (4 e^x+5 \sin x)\, dx \amp =\amp \displaystyle 4 e^x-5 \cos x \Big]_0^{1} \\ \amp =\amp (4 e^{1} - 5 \cos 1) - (4 e^0 - 5 \cos0 ) \\ \amp =\amp 4 e^{1} - 5 \cos 1 + 1 \end{array} \end{equation*}

Optional conclusion

It is also possible to code WeBWorK exercises directly in your PreTeXt source. This shows the most primitive sort of such exercise. Chapter 7 goes into greater detail.

<exercise>
  <webwork>
      <statement>
        <p>
          <m>1+2=</m><var name="3" width="5" />
        </p>
      </statement>
  </webwork>
</exercise>
Listing 16.5.3. A simple WeBWorK exercise coded in PreTeXt source

The code in Listing 16.5.3 produces the following output:

\(1+2=\)

Answer.

\(3\)