web analytics
Skip to main content

The PreTeXt Guide

Section 39.4 Processing WeBWorK Exercises

Subsection 39.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. Using the CLI, this is done with pretext generate webwork (if you want to reference a particular target, add -t [targetname]).
If instead you want to use the pretext/pretext script, you might need to install the Python requests module. It is not uncommon for your computer to not have requests installed (although it comes with the CLI), 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 6.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 39.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 ~/pretext/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 45. 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 39.4.2 HTML output

We assume you are using managed directories, and have WeBWorK representations file as above. Build the HTML with pretext build web. You can also 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 45.
-d specifies a folder to place all of the HTML output. If unspecified, this will be the current working directory.
There are five publisher file entries which control how a WeBWorK problem is realized within HTML output. These are divided based on where the exercise (or project-like) resides: inline, within a division of exercises, within a reading questions division, within a worksheet, or if it is a project or similar. If the class of problems is declared dynamic, then each problem has a button that readers can click to make the problem interactive. Conversely, if the class of problems is declared static, then the problems render with a static preview.
By default, inline exercises and project-like will be dynamic, under the assumption that these are meant to be worked as a reader works through the material. The others will be static, under the assumption that they will be placed on a WeBWorK server where they will be worked for scores and grades. See Subsection 45.4.4 for the precise syntax for these switches.
If an exercise is subdivided into tasks, then by default they will only be revealed incrementally as the reader answers each one correctly. If you would like to have all tasks revealed from the start, then this option may be elected in the publication file (see Subsection 45.8.6).

Subsection 39.4.3 output

We assume you are using managed directories, and have WeBWorK representations file as above. Then build as normal with the CLI. Or 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 45.
-d specifies a folder to place the PDF output. If unspecified, this will be the current working directory.

Subsection 39.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 45.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).