Skip to main content

The PreTeXt Guide

Section 38.2 Configuring a WeBWorK Course for PreTeXt

To make use of WeBWorK in your PreTeXt project, you need a host WeBWorK course. If someone is providing a WeBWorK server for you, like the AIM server at webwork-ptx.aimath.org, then we assume they have already configured a course for use with PreTeXt, and you may skip this section and move on to Section 38.4.
If you are configuring your own WeBWorK server to use with PreTeXt, we assume a mild familiarity with administrating a WeBWorK server. The version of WeBWorK needs to be 2.14 or later for use with PreTeXt.
Using the admin course, create a course named anonymous. (You could name it something else, but we assume the name is anonymous in this guide.) In the course’s Course Configuration menu, set all permissions to admin (or perhaps set some to the even more restrictive nobody). Except set “Allowed to login to the course” to login_proctor. Also if your server is new enough, it has “Allowed to view course home page” which should also be set to login_proctor.
In the Classlist Editor, add a user named anonymous (again, you could use some other name), and set that user’s permission level to login_proctor, the permission level one higher than student. Set that user’s password to anonymous (again, you could use some other password). Note that because this is public information, anyone will be able to log into this course as this user. This is why restricting permissions in the previous paragraph is very important.
Add the following lines to the course.conf file (which lives in the parent folder of the templates/ folder.)
# Hide message about previewing hints and solutions for instructors
$pg{specialPGEnvironmentVars}{ALWAYS_SHOW_HINT_PERMISSION_LEVEL} = 100;
$pg{specialPGEnvironmentVars}{ALWAYS_SHOW_SOLUTION_PERMISSION_LEVEL} = 100;
In the templates/macros/ folder, edit PGcourse.pl (or create it if need be) and add the following lines.
#### Replace essay boxes with a message
my $essay_message = 'If you were logged into a WeBWorK course '
    . 'and this problem were assigned to you, '
    . 'you would be able to submit an essay answer '
    . 'that would be graded later by a human being.';

sub essay_box {
  my $out = MODES(
    TeX => '',
    Latex2HTML => '',
    HTML => qq!<p>$essay_message</p>!,
    PTX => '',
  );
  $out;
};

sub explanation_box {
  return if ($envir{waiveExplanations});
  my $out = MODES(
    TeX => '',
    Latex2HTML => '',
    HTML => qq!<p>$essay_message</p>!,
    PTX => '',
  );
  $out;
};

#### Suppress essay help link
sub essay_help {};

#### How many attempts until hint is available
$showHint = -1;
# May be a bug that WeBWorK requires -1 instead of 0
# for immediate access to hints

1;
Now PreTeXt will be able to communicate with this course to retrieve what is needed.