Skip to main content

Chapter 23 WeBWorK Exercises

It is possible to embed WeBWorK exercises into a PreTeXt document. In the HTML version, readers can answer these exercises and find out if their answer is correct or incorrect. However, results of WeBWorK exercises cannot be recorded to your gradebook. There's some configuration required use WeBWorK. Please see Chapter 8 and Chapter 40 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 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 23.0.1. A WeBWorK exercise living on the server

The code in Listing 23.0.1 produces the following output:

Optional introduction

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

Answer.

\(9.97050222469081\)

Solution.

SOLUTION

\begin{equation*} \begin{array}{rcl} \displaystyle \int_0^{1} (5 e^x+3 \sin x)\, dx \amp =\amp \displaystyle 5 e^x-3 \cos x \Big]_0^{1} \\ \amp =\amp (5 e^{1} - 3 \cos 1) - (5 e^0 - 3 \cos0 ) \\ \amp =\amp 5 e^{1} - 3 \cos 1 - 2 \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. The section of the Author's Guide referenced above goes into greater detail (Chapter 8).

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

The code in Listing 23.0.3 produces the following output:

\(1+2=\)

Answer.

\(3\)