Skip to main content

The PreTeXt Guide

Section 38.1 Using a Local Copy of PG

WeBWorK problems can be processed using a local copy of the pg repository. This can siginificanlty speed up processing time, compared with the other options that use a network connection.
To use this processing method, clone the pg repository. The code below places it in a default location, but you could place it somewhere else.
cd /opt
mkdir webwork
cd webwork
git clone https://github.com/openwebwork/pg
Note that you should end up with a verion of pg that is 2.19 or later. To check, examine the VERSION file in the root of the repository.
Set the PG_ROOT environment variable to be the path to your copy of pg. If it is at the default location, you could run:
export PG_ROOT=/opt/webwork/pg
This will only define $PG_ROOT for your current terminal session, so you might also do whatever is appropriate on your system to set PG_ROOT each time a terminal session begins.
In pg/conf/, make a copy of pg_config.dist.yml called pg_config.yml. In general you should read through all the settings and set them appropriately. At a minimum, set directories: root: to the absolute path to your clone of pg. You may need to set paths in externalPrograms: as well. And maybe more...
For PreTeXt in general you should already have ImageMagick installed. Somewhere in your file system is an XML file that ImageMagick uses to control permissions. The file is named policy.xml and might be located in a place like /etc/imagemagick/policy.xml or /etc/ImageMagick-6/policy.xml. (If your version of ImageMagick is not 6, it’s possible none of this is necessary. But also it should be harmless to continue.) In this file, within the <policymap> element, add the element:
<policy domain="coder" rights="read" pattern="PDF" />
Depending on your file, you may need to replace a similar line that is assigning rights="none". Make sure that this is not within a commented out portion of the file.
You need to have a recent enough perl version. Version 5.32 is known to work, and versions as early as 5.26 may work, but have not been thoroughly tested.
PG also uses perl packages that you may not yet have and need to install. These may be available from Linux package distributions, and the details differ from one flavor of Linux to the next. Alternatively there is a utility called cpanm (cpanminus) that is supposed to let you manage perl module installation across Linux flavors. One important difference is that cpanm only mangages perl modules. And sometimes a perl module is actually an interface between perl and some other system utility. cpanm will not actually install that system utility that it depends on and will just quit. Whereas Linux package distributions will have a more sophisticated dependency understanding, and try to install non-perl tools when needed. So you want to try to use Linux package distributions where you can. Or else use cpanm and perhaps be prepared to read the log if it fails and attempt to install some non-perl tool that a particular module depends on.
Here is a list of all the perl modules you might need. Some are essential, and some are only needed for tools that many exercises will not use. Carp Class::Accessor Class::Tiny Data::Dumper DBI Digest::MD5 File::Copy File::Find File::Path File::Spec GD Getopt::Long HTML::Entities Locale::Maketext::Lexicon MIME::Base64 Mojo::Base Mojo::IOLoop Mojo::DOM Mojo::JSON Opcode Pandoc Perl::Tidy Pod::Simple::Search Scalar::Util Socket Tie::IxHash UUID::Tiny YAML::XS. If you don’t have one of these that is needed, and you attempt to process WeBWorK problems using local PG processing, you will get a clear message about which module is missing that you must pursue installing it.
Here are some Linux package collections that we think are sufficient (but please report if you find them to be insufficient).
Debian/Ubuntu
liblocale-maketext-lexicon-perl, libyaml-libyaml-perl, libuuid-tiny-perl, libclass-tiny-perl, libdbi-perl, libgd-perl, libgd-text-perl
RedHat
List not yet gathered. Please report if you put together a good list.
To try to install using cpanm, of course first you must have cpanm. Try cpanm --version to see if you have it. If not, follow installation instructions for Ubuntu
 1 
manpages.ubuntu.com/manpages/trusty/man3/App::cpanminus.3pm.html
, Debian
 2 
packages.debian.org/search?keywords=cpanminus
(sudo apt install cpanminus), RedHat (sudo dnf install perl-CPAN), or MacOS (brew install cpanminus, requiring you first install Homebrew
 3 
https://brew.sh/
). Or you could install cpanm directly following these instruction
 4 
metacpan.org/pod/App::cpanminus
.
Once you have cpanm, you can opt to install the above modules one at a time, or all at once. Either way, it is probably adequate to install the modules as your own user. And yet we will recommend that you install the modules as root to avoid certain installation headaches and so that your system is set up to use webwork2 if that is ever desired. To install one at time, run commands like: sudo cpanm Carp. But proceed through each module listed above. This will help you clearly see if there was an issue during installation. To install all at once: sudo cpanm Carp Class::Accessor ... YAML::XS, replacing the dots with the full list of modules above.
One known bump in the road may come with the GD module. You may need to actually install gd first, which is not a perl module. The perl GD module is the perl bridge to gd. For Ubuntu/Debian, install these packages: pkgconf, gdlib libgd-dev.
Now in a publisher file, you can set the <webwork> element to have @static-processing with value local. If you put the pg repository in the default location, this is all you need to do. Otherwise, you also need to add the attribute @pg-location with the absolute path, for example /opt/webwork/pg. And when you process WeBWorK exercises for static representations (following Subsection 38.5.1) your local copy of PG will be used instead of some remote server.
Note that you will still need a network connection for problems in your HTML output to render as live interactive exercises.