SYNOPSIS

$pg = WeBWorK::PG->new(
    displayMode        => 'MathJax',            # (images|MathJax)
    showHints          => 1,
    showSolutions      => 0,
    processAnswers     => 1,
    isInstructor       => 1,
    useMathQuill       => 1,
    templateDirectory  => '/opt/webwork/pg/',
    problemSeed        => 1234,
    inputs_ref         => $formFields,
    sourceFilePath     =>
        '/opt/webwork/libraries/webwork-open-problem-library/OpenProblemLibrary/Michigan/Chap8Sec4/Q21.pg'

);

$translator       = $pg->{translator};          # WeBWorK::PG::Translator
$body             = $pg->{body_text};           # text string
$header           = $pg->{head_text};           # text string
$post_header_text = $pg->{post_header_text};    # text string
$answerHash       = $pg->{answers};             # WeBWorK::PG::AnswerHash
$result           = $pg->{result};              # hash reference
$state            = $pg->{state};               # hash reference
$errors           = $pg->{errors};              # text string
$warnings         = $pg->{warnings};            # text string
$flags            = $pg->{flags};               # hash reference
$pgcore           = $pg->{pgcore}               # PGcore

DESCRIPTION

WeBWorK::PG is a module that provides a convenient API for rendering a PG problem.

OPTIONS

The constructor can be passed the following options. One of the r_source or sourceFilePath options described below must be provided. In addition, any of the translator environment variables may be passed as options in this argument. Furthermore, any keys in the passed hash not documented below will be copied into the translator environment.

r_source (reference to string)

The source of the pg problem to render provided as a reference to a string. If this is given it will be used for the problem source instead of the sourceFilePath

sourceFilePath (string)

Location of the pg problem file to render. It must either be provided with an absoute path, or a path relative to the given templateDirectory.

templateDirectory (string, default: '')

Either a readable location containing the problem file and all static assets for the problem, or the empty string. WARNING: If this is the empty string then any static assets for the problem may not be found.

problemSeed (number, default: 1234)

Seed to use for the problem.

displayMode (string, default: 'MathJax')

The PG display mode to use, e.g., 'tex', 'plainText', 'images', 'MathJax', or 'PTX'.

showHints (boolean, default: 1)

This determines if hints that may be encoded in the problem will be rendered.

showSolutions (boolean, default: 0)

This determines if solutionas that may be encoded in the problem will be rendered.

forceScaffoldsOpen (boolean, default: 0)

If set to 1, then all scaffolds will be allowed to be opened.

setOpen (boolean, default: 1)

Determines if the set containing the problem is open for the user to work. (This is only used by problemPanic.pl)

pastDue (boolean, default: 0)

Determines if the problem is past due. (This is only used by answerDiscussion.pl, problemPanic.pl, and problemRandomize.pl)

answersAvailable (boolean, default: 0)

Determines if the problem answers are available. (This is only used by scaffold.pl)

problemUUID (scalar, default: 0)

This is used to generate unique identifiers for resources. The caller should ensure that this is sufficiently unique for the purposes of the system. Generally that means it should be unique for each course, user, set, and problem number.

psvn (number, default: 1)

Problem set version number. This is also incorporated into the unique identifiers used for resources.

probNum (number, default: 1, deprecated)

Problem number. This will eventually be removed from pg.

refreshMath2img (boolean, default: 0)

If 1, force images created by math2img (in "images" mode) to be recreated.

processAnswers (boolean, default: 0)

If 1, call answer evaluators and graders.

isInstructor (boolean, default: 0)

Determines if the user is an instructor (certain restrictions are removed for these users).

inputs_ref (hash, default: {})

Hash containing all input values in the form containing the problem. Most importantly this contains answers.

ansEvalDefaults (hash, default: taken from WeBWorK::PG::Environment)

This may contain the following keys (example values are shown)

functAbsTolDefault: 0.001
functLLimitDefault: 0.0000001
functMaxConstantOfIntegration: 1E8
functNumOfPoints: 3
functRelPercentTolDefault: 0.1
functULimitDefault: 0.9999999
functVarDefault: x
functZeroLevelDefault: 1E-14
functZeroLevelTolDefault: 1E-12
numAbsTolDefault: 0.001
numFormatDefault: ''
numRelPercentTolDefault: 0.1
numZeroLevelDefault: 1E-14
numZeroLevelTolDefault: 1E-12
useBaseTenLog: 0
defaultDisplayMatrixStyle: '[s]' # left delimiter, middle line delimiters, right delimiter
answerPrefix (string, default: '')

A prefix to prepend to all answer labels. Note that other prefixes may be prepended in front of this one, so it is not safe to assume that it is at the beginning of all answer labels. For example, the parserMultiAnswer.pl macro does this. Also note that in the actual PGcore environment this is QUIZ_PREFIX.

grader (string or CODE, default taken from WeBWorK::PG::Environment)

The default grader to use. This can be overridden by the problem.

useMathQuill, useMathView (boolean, defaults taken from WeBWorK::PG::Environment)

Determines which entry assist method to use. If useMathQuill is 1, then MathQuill will be used. Otherwise, if useMathView is 1, then MathView will be used. If both are 0, then basic html inputs will be used.

language (string, default: 'en')

The language for the problem.

language_subroutine (CODE, default: sub (@args) { return $args[0]; })

Language subroutine that will be used for translations (the maketext method).

macrosPath (array, default taken from WeBWorK::PG::Environment)

An array of paths to search for macros that may be loaded by the problem.

htmlPath (array, default taken from WeBWorK::PG::Environment)

Paths to search for auxiliary html files. Note that this array may contain the special value of '.' which means the directory the problem file is contained in.

imagesPath (array, default taken from WeBWorK::PG::Environment)

Paths to search for auxiliarly image files. Note that this array may contain the special value of '.' which means the directory the problem file is contained in.

htmlDirectory (string, default taken from WeBWorK::PG::Environment)

Html directory that may contain additional static resources that may be used in problems. Usually the course's html directory.

htmlURL (string, default taken from WeBWorK::PG::Environment)

Public html address of the htmlDirectory above.

tempDirectory (string, default taken from WeBWorK::PG::Environment)

Location to place generated resources. This directory must be writable.

tempURL (string, default taken from WeBWorK::PG::Environment)

Public html address of the tempDirectory above.

localHelpURL (string, default taken from WeBWorK::PG::Environment)

Public html address for the PG help files.

use_site_prefix (string, default: '')

Site prefix prepended to image and video url's inserted into problems by the PGbasicmacros.pl methods "image" and "video".

use_opaque_prefix (boolean, default: 0)

If set to 1, then "%%IDPREFIX%%" will be prepended to answer labels.

__files__ (hash default: default taken from WeBWorK::PG::Environment)

A hash that should contain key value pairs for the keys 'root', 'pg', and 'tmpl'. These are used to shorten filenames in error messages.

specialPGEnvironmentVars (hash, default taken from WeBWorK::PG::Environment)

A hash that can contain any of the keys described int conf/pg_config.dist.yml.

debuggingOptions (hash, default: {})

A hash that may contain key value pairs for the keys show_resource_info, view_problem_debugging_info, show_pg_info, show_answer_hash_info, show_answer_group_info. The keys enable the things describe in the key name.

courseName (string, default: 'pg_local', deprecated)
setNumber (number, default: 1, deprecated)
studentLogin (string, default: 'pg_local', deprecated)
studentName (string, default: 'pg_local', deprecated)
studentID (string, default: 'pg_local', deprecated)

These options are still used in some places in PG (mostly by macros that will eventually be deprecated and removed), but eventually that will all be fixed and these will no longer be needed. Note that webwork2 still needs to pass the courseName so the relevant course values (course html directories and urls) can be optained from the WeBWorK::CourseEnvironment.

RETURN VALUE

The new method returns a blessed hash reference containing the following fields. More information can be found in the documentation for WeBWorK::PG::Translator.

translator

The WeBWorK::PG::Translator object used to render the problem.

head_text

HTML code to be injected into the <head> tag of the web page containing the problem.

post_header_text

HTML code to be injected into the <body> tag before the form containing the problem.

body_text

HTML code to be inserted into the <body> tag of the web page to show the problem.

answers

An AnswerHash object containing submitted answers, and results of answer evaluation.

result

A hash containing the results of grading the problem.

state

A hash containing the problem state.

errors

A string containing any errors encountered while rendering the problem.

warnings

A string containing any warnings encountered while rendering the problem.

flags

A hash containing PG_flags (see the Translator docs).

pgcore

The PGcore object for the problem.