Skip to main content

Section 36.4 Processing WeBWorK Exercises

Subsection 36.4.1 Extraction and Processing

Before anything else can be done, a PreTeXt project with WeBWorK problems must first have its WeBWorK content extracted and processed into multiple representations, which are then collected into an auxiliary XML file. We do this with the pretext/pretext script which uses Python and the Python requests module. It is not uncommon for your computer to not have requests installed, so you should check if it is there and install it if need be. You can check if it is installed from the command line with:

          python -c "import requests"
        

And if it isn't, you can install it with pip, specifically with:

          sudo pip install requests
        

(If you don't have pip installed, you could use:

          sudo easy_install pip
        

to install it.)

Processing WeBWorK problems is best accomplished if you are using directory management. With a publication file, declare the external and generated directories as describe in Section 5.6. Then use the pretext script to extract PreTeXt content from the WeBWorK server. It will be placed in a webwork subfolder of your generated folder. For example:

$ pretext -c webwork -p <publisher> aota.ptx

aota.ptx in the example is the root file for your PreTeXt project.

Warning 36.4.1. File Paths.

In the previous example and those that follow, you should specify paths as needed. For example, the pretext script is typically at ~/mathbook/pretext/pretext. And the -p option is specifying a publication file.

-c webwork means you are processing the WeBWorK components.

-p specifies the publication file, as described in Chapter 42. In the publication file, the element <webwork> may have attributes @server, @course, @coursepassword, @user, and @userpassword. If absent, these default to https://webwork-ptx.aimath.org, anonymous, anonymous, anonymous, and anonymous respectively. If you specify a server, you must correctly specify the protocol (http versus https). And it must be version 2.14 or later. Do not include a trailing slash.

Subsection 36.4.2 HTML output

We assume you are using managed directories, and have WeBWorK representations file as above. Now you may use pretext/pretext to build HTML. For example:

$ pretext -c all -f html -p <publisher> -d <destination> aota.ptx

-p specifies the publication file, as described in Chapter 42.

-d specifies a folder to place all of the HTML output. If unspecified, this will be the current working directory.

There are several string parameters you may pass to pretext using -x stringparam option stringparam option .... If you use -x with pretext, make sure at least one other switch (-p for example) follows the use of -x.

stringparam options
webwork.inline.static

'no' (default) means inline exercises render as interactive.

'yes' means inline exercises render as static.

'preview' (planned) means inline exercises render as static until you click to activate them.

webwork.divisional.static

'no' means divisional exercises render as interactive.

'yes' (default) means divisional exercises render as static.

'preview' (planned) means divisional exercises render as static until you click to activate them.

html.knowl.exercise.inline

'no' means inline exercises appear on page load.

'yes' (default) means inline exercises are hidden in knowls.

html.knowl.exercise.sectional

'no' (default) means divisional exercises appear on page load.

'yes' means divisional exercises are hidden in knowls.

Subsection 36.4.3 output

We assume you are using managed directories, and have WeBWorK representations file as above. Now you may use pretext/pretext to build a PDF. For example:

$ pretext -c all -f pdf -p <publisher> -d <destination> aota.ptx

-p specifies the publication file, as described in Chapter 42.

-d specifies a folder to place the PDF output. If unspecified, this will be the current working directory.

There is one string parameter you may pass to pretext using -x. If you use -x with pretext, make sure at least one other switch (-p for example) follows the use of -x.

stringparam options
latex.fillin.style

'underline' (default) means that where there would be an answer blank, it is rendered as an underline.

'box' means that where there would be an answer blank, it is rendered as a box outline.

Subsection 36.4.4 Creating Files for Uploading to WeBWorK

All of the <webwork> that you have written into your project can be “harvested” and put into their own .pg files by the pretext script. These files are created with a folder structure that follows the chunking scheme you specify. This process also creates set definition files (.def) for each chunk (say, for each section): one for inline exercises (checkpoints) and one for divisional exercises. For <webwork> problems that come from the WeBWorK server, the .def file will include them as well. This archiving process creates set header .pg files for each set definition.

For example:

$ xsltproc -stringparam publisher <publisher> pretext-ww-problem-sets.xsl aota.ptx

You may need to specify paths to these files.

With a book, you can break up your problem set into multiple files according to a chosen depth of the hierarchy. See Subsection 42.1.1 for details on how to specify this.

This creates a folder named after your book title, which has a folder tree with all of the .pg and .def files laid out according to your chunk level. You can compress this folder and upload it into an active WeBWorK course where you may then assign the sets to your students (and modify, as you like).