Skip to main content
Chemistry LibreTexts

2.5: Common PG Macros

  • Page ID
    488659
  • ​

    ​

    \( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \)

    \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)

    \( \newcommand{\dsum}{\displaystyle\sum\limits} \)

    \( \newcommand{\dint}{\displaystyle\int\limits} \)

    \( \newcommand{\dlim}{\displaystyle\lim\limits} \)

    \( \newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\)

    ( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\)

    \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\)

    \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\)

    \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\)

    \( \newcommand{\Span}{\mathrm{span}}\)

    \( \newcommand{\id}{\mathrm{id}}\)

    \( \newcommand{\Span}{\mathrm{span}}\)

    \( \newcommand{\kernel}{\mathrm{null}\,}\)

    \( \newcommand{\range}{\mathrm{range}\,}\)

    \( \newcommand{\RealPart}{\mathrm{Re}}\)

    \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\)

    \( \newcommand{\Argument}{\mathrm{Arg}}\)

    \( \newcommand{\norm}[1]{\| #1 \|}\)

    \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\)

    \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\AA}{\unicode[.8,0]{x212B}}\)

    \( \newcommand{\vectorA}[1]{\vec{#1}}      % arrow\)

    \( \newcommand{\vectorAt}[1]{\vec{\text{#1}}}      % arrow\)

    \( \newcommand{\vectorB}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \)

    \( \newcommand{\vectorC}[1]{\textbf{#1}} \)

    \( \newcommand{\vectorD}[1]{\overrightarrow{#1}} \)

    \( \newcommand{\vectorDt}[1]{\overrightarrow{\text{#1}}} \)

    \( \newcommand{\vectE}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash{\mathbf {#1}}}} \)

    \( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \)

    \(\newcommand{\longvect}{\overrightarrow}\)

    \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)

    \(\newcommand{\ket}[1]{\left| #1 \right>}\)
    \(\newcommand{\bra}[1]{\left< #1 \right|}\)
    \(\newcommand{\braket}[2]{\left< #1 \vphantom{#2} \right| \left. #2 \vphantom{#1} \right>}\)
    \(\newcommand{\braopket}[3]{\left< #1 \vphantom{#2}\vphantom{#3} \right| #2 \vphantom{#1}\vphantom{#3} \left| #3 \vphantom{#1}\vphantom{#2} \right>}\)
    \(\newcommand{\qmvec}[1]{\mathbf{\vec{#1}}}\)
    \(\newcommand{\op}[1]{\hat{\mathbf{#1}}}\)
    \(\newcommand{\expect}[1]{\langle #1 \rangle}\)
    \(\newcommand{\dfn}[1]{\emph{\textbf{#1}}}\)

    \(\newcommand{\avec}{\mathbf a}\) \(\newcommand{\bvec}{\mathbf b}\) \(\newcommand{\cvec}{\mathbf c}\) \(\newcommand{\dvec}{\mathbf d}\) \(\newcommand{\dtil}{\widetilde{\mathbf d}}\) \(\newcommand{\evec}{\mathbf e}\) \(\newcommand{\fvec}{\mathbf f}\) \(\newcommand{\nvec}{\mathbf n}\) \(\newcommand{\pvec}{\mathbf p}\) \(\newcommand{\qvec}{\mathbf q}\) \(\newcommand{\svec}{\mathbf s}\) \(\newcommand{\tvec}{\mathbf t}\) \(\newcommand{\uvec}{\mathbf u}\) \(\newcommand{\vvec}{\mathbf v}\) \(\newcommand{\wvec}{\mathbf w}\) \(\newcommand{\xvec}{\mathbf x}\) \(\newcommand{\yvec}{\mathbf y}\) \(\newcommand{\zvec}{\mathbf z}\) \(\newcommand{\rvec}{\mathbf r}\) \(\newcommand{\mvec}{\mathbf m}\) \(\newcommand{\zerovec}{\mathbf 0}\) \(\newcommand{\onevec}{\mathbf 1}\) \(\newcommand{\real}{\mathbb R}\) \(\newcommand{\twovec}[2]{\left[\begin{array}{r}#1 \\ #2 \end{array}\right]}\) \(\newcommand{\ctwovec}[2]{\left[\begin{array}{c}#1 \\ #2 \end{array}\right]}\) \(\newcommand{\threevec}[3]{\left[\begin{array}{r}#1 \\ #2 \\ #3 \end{array}\right]}\) \(\newcommand{\cthreevec}[3]{\left[\begin{array}{c}#1 \\ #2 \\ #3 \end{array}\right]}\) \(\newcommand{\fourvec}[4]{\left[\begin{array}{r}#1 \\ #2 \\ #3 \\ #4 \end{array}\right]}\) \(\newcommand{\cfourvec}[4]{\left[\begin{array}{c}#1 \\ #2 \\ #3 \\ #4 \end{array}\right]}\) \(\newcommand{\fivevec}[5]{\left[\begin{array}{r}#1 \\ #2 \\ #3 \\ #4 \\ #5 \\ \end{array}\right]}\) \(\newcommand{\cfivevec}[5]{\left[\begin{array}{c}#1 \\ #2 \\ #3 \\ #4 \\ #5 \\ \end{array}\right]}\) \(\newcommand{\mattwo}[4]{\left[\begin{array}{rr}#1 \amp #2 \\ #3 \amp #4 \\ \end{array}\right]}\) \(\newcommand{\laspan}[1]{\text{Span}\{#1\}}\) \(\newcommand{\bcal}{\cal B}\) \(\newcommand{\ccal}{\cal C}\) \(\newcommand{\scal}{\cal S}\) \(\newcommand{\wcal}{\cal W}\) \(\newcommand{\ecal}{\cal E}\) \(\newcommand{\coords}[2]{\left\{#1\right\}_{#2}}\) \(\newcommand{\gray}[1]{\color{gray}{#1}}\) \(\newcommand{\lgray}[1]{\color{lightgray}{#1}}\) \(\newcommand{\rank}{\operatorname{rank}}\) \(\newcommand{\row}{\text{Row}}\) \(\newcommand{\col}{\text{Col}}\) \(\renewcommand{\row}{\text{Row}}\) \(\newcommand{\nul}{\text{Nul}}\) \(\newcommand{\var}{\text{Var}}\) \(\newcommand{\corr}{\text{corr}}\) \(\newcommand{\len}[1]{\left|#1\right|}\) \(\newcommand{\bbar}{\overline{\bvec}}\) \(\newcommand{\bhat}{\widehat{\bvec}}\) \(\newcommand{\bperp}{\bvec^\perp}\) \(\newcommand{\xhat}{\widehat{\xvec}}\) \(\newcommand{\vhat}{\widehat{\vvec}}\) \(\newcommand{\uhat}{\widehat{\uvec}}\) \(\newcommand{\what}{\widehat{\wvec}}\) \(\newcommand{\Sighat}{\widehat{\Sigma}}\) \(\newcommand{\lt}{<}\) \(\newcommand{\gt}{>}\) \(\newcommand{\amp}{&}\) \(\definecolor{fillinmathshade}{gray}{0.9}\)

    This page is not a catalog of everything PG can do. It is a short list of macros you will actually see and use when writing PGML-first science problems.

    Use this page when: a problem will not render, a widget is missing, or you are adding a new interaction type.

    This guide reflects the PG 2.17 subset used in ADAPT and webwork-pg-renderer. Some macros used in online examples are missing in this subset, so check the allowlist before you add a new file to loadMacros().

    For the full comparison table, see docs/PG_MACRO_VERSION_COMPARISON.md.

    If you are writing your first problem, start with the four core macros (PGstandard.pl, MathObjects.pl, PGML.pl, PGcourse.pl). Add interaction macros only when you need a specific widget like radio buttons or dropdowns.

    Copy and edit (minimal macro set)

    DOCUMENT();
    
    loadMacros(
    	"PGstandard.pl",
    	"MathObjects.pl",
    	"PGML.pl",
    	"PGcourse.pl",
    );
    

    This is the most common macro error: calling a function that requires a macro you forgot to load. PG reports the function name as "Undefined subroutine" because the macro file that defines it was never loaded.

    Common failure and fix

    Broken: RadioButtons(...) without parserRadioButtons.pl
    What you will see: Undefined subroutine &main::RadioButtons called
    Fix: add "parserRadioButtons.pl" to loadMacros()
    

    Core macros for PGML-first problems

    These four macros form the foundation of every PGML problem. Load all four unless you have a specific reason to omit one. The table below shows what each macro enables and what breaks if you leave it out.

    Core macros for PGML-first problems reference.
    Macro What it enables What breaks if it is missing
    PGstandard.pl Core PG helpers and defaults. Basic PG functions are undefined.
    PGML.pl PGML blocks, formatting, and answer blanks. PGML blocks fail or render as raw text.
    PGcourse.pl Course-level helpers and defaults. Course-specific helpers are undefined.
    MathObjects.pl MathObjects: Real, Formula, Compute, Context. Needed when using Real(), Compute(), Formula(), or Context(). Not required for RadioButtons or CheckboxList.

    Note: MathObjects.pl is included in most science problems because they use numeric answers with Real() or Compute(). For pure multiple-choice or matching problems that do not compute numeric values, it can be omitted.

    Add-ons by interaction type

    Beyond the core four, you add macros based on the interaction type your problem needs. Each row below corresponds to a student-facing widget. Load the macro only when you use that widget -- extra macros add no value and slow down debugging.

    Add-ons by interaction type: what students see, macro to load, and notes.
    What students see Macro to load Notes
    Single-choice questions (radio buttons) parserRadioButtons.pl Visible options, one correct choice (see Multiple Choice).
    Matching or shuffled lists PGchoicemacros.pl Matching and choice helpers (see Matching and Randomized Matching Problems).
    Targeted feedback for common errors answerHints.pl Instructor-style feedback without extra widgets.
    Dropdown menus (select one from a list) parserPopUp.pl Use PopUp() for inline dropdown selection. Available in ADAPT (see Randomized Matching Problems).
    Drag-and-drop proof ordering draggableProof.pl Students arrange steps into the correct order.
    Drag-and-drop grouping into subsets draggableSubsets.pl Students sort items into labeled bins.
    Free-response essay box PGessaymacros.pl Open-ended text entry; requires manual grading.
    Fill-in-the-blank word completion parserWordCompletion.pl Accepts specific string answers from a word bank.

    Macro availability (subset vs full PG)

    Not every PG macro is available in the ADAPT/renderer subset. The table below shows which macros work in your environment. If a macro shows "No" in the ADAPT column, you need a workaround.

    Macro availability (subset vs full PG) reference.
    Macro file ADAPT/renderer subset Full PG 2.17+ PG 2.20
    PGML.pl Yes Yes Yes
    MathObjects.pl Yes Yes Yes
    parserRadioButtons.pl Yes Yes Yes
    parserCheckboxList.pl No Yes Yes
    VectorListCheckers.pl No Yes Yes

    What macro availability means for you

    The ADAPT/renderer subset is based on PG 2.17 but uses a flattened macro tree with some files removed. This affects what widgets and helpers you can use in problems.

    Parser widgets: Key differences

    Parser widgets: Key differences reference.
    Widget ADAPT/renderer Full PG 2.17+ Notes
    PopUp Yes Yes Use for matching dropdowns (see Randomized Matching Problems)
    RadioButtons Yes Yes Use for single-choice questions and per-statement True/False
    CheckboxList No Yes Not available. Use RadioButtons per statement instead (Randomized MC True and False Statements)
    DropDown No No PG 2.18+ only. Use PopUp in ADAPT/renderer

    Core macros: All available

    Core macros: All available: macro, adapt/renderer, full pg 2.17+, and more.
    Macro ADAPT/renderer Full PG 2.17+ Notes
    PGML.pl Yes Yes Always load this for PGML blocks
    PGstandard.pl Yes Yes Core PG functions
    MathObjects.pl Yes Yes Required for Real(), Compute(), Formula()
    niceTables.pl Yes Yes The only supported way to create tables (see Making Tables with niceTables)

    Context macros: Most available, some missing

    Context macros: Most available, some missing reference.
    Macro ADAPT/renderer Full PG 2.17+ Notes
    contextUnits.pl Yes Yes Unit-aware parsing for science problems
    contextReaction.pl Yes Yes Chemical reaction input validation
    VectorListCheckers.pl No Yes Vector list validation not available in subset

    What this means for problem authors

    • Use PopUp and RadioButtons: These work reliably across all PG versions and are available in the ADAPT/renderer subset.
    • Avoid CheckboxList: It's not in the PG 2.17 subset. Use RadioButtons per statement instead (see Randomized MC True and False Statements for the pattern).
    • Check the allowlist before copying: Online examples may use macros that aren't in the subset. Always verify against the allowlist in docs/PG_2_17_RENDERER_MACROS.md.
    • Use niceTables.pl for all tables: HTML table tags (<table>, <tr>, <td>) are blocked. niceTables.pl is the only supported way to create tables.
    • Test locally: Use the local renderer (Testing and Debugging) to catch missing macros before deploying to ADAPT.

    When a macro is missing

    If you try to load a macro that's not in the ADAPT/renderer subset, you'll see an error. Here's how to diagnose and fix it.

    Symptoms of a missing macro

    • "Can't locate [MacroFile].pl" error: The macro file doesn't exist in the renderer's macro search path.
    • "Undefined subroutine" error: A function from a missing macro was called (e.g., CheckboxList() without parserCheckboxList.pl).
    • Widget doesn't appear: The problem renders but the expected checkbox list, dropdown, or other widget is missing.

    How to diagnose

    1. Check the allowlist: Open docs/PG_2_17_RENDERER_MACROS.md and search for the macro file name. If it's not listed, it's not available.
    2. Test locally with renderer: Run the problem through the local renderer (Setting Up the PG Renderer). The error message will tell you which macro failed to load and where it was called.
    3. Search for alternatives: Look for similar functionality in macros that ARE in the allowlist. For example, use PopUp instead of DropDown.

    Common workarounds

    Common workarounds: missing macro, what it provided, and workaround.
    Missing macro What it provided Workaround
    parserCheckboxList.pl Checkbox lists for multiple correct answers Use RadioButtons per statement (True/False), see Randomized MC True and False Statements
    DropDown (PG 2.18+) Modern dropdown widget Use PopUp from parserPopUp.pl (same functionality)
    VectorListCheckers.pl Vector list validation helpers Use MathObjects Vector context directly or simplify to scalar answers

    Prevention

    • Before copying code from online examples, check the macro list against the allowlist.
    • Use templates from Minimal Templates, which are verified to work with the PG 2.17 subset.
    • Test problems locally (Setting Up the PG Renderer) before deploying to ADAPT.

    Science-native contexts and grading helpers

    These macros extend PG's answer checking to handle science-specific input formats like units, chemical reactions, and scientific notation. Use them when the standard Numeric or String contexts are too restrictive for what you want students to enter.

    Science-native contexts and grading helpers reference.
    Use it when Macro to load Why it matters
    Units are part of correctness contextUnits.pl Supports unit-aware parsing and validation.
    You need chemical reaction input contextReaction.pl Validates reactants/products and reaction structure.
    Multiple blanks depend on each other parserMultiAnswer.pl Ties related blanks to one checker.
    Parts should contribute different weights weightedGrader.pl Supports weighted scoring across parts.
    Order should not matter in a list unorderedAnswer.pl Grades set-style answers without order.
    Answer must include physical units (e.g., "9.8 m/s^2") parserNumberWithUnits.pl Parses and validates a number paired with a unit string.
    Answer is a formula with units (e.g., "2*pi*r m") parserFormulaWithUnits.pl Extends FormulaWithUnits to accept symbolic expressions with units.
    Answer should be in scientific notation contextScientificNotation.pl Requires answers like 6.02E23 or 6.02 x 10^23. Useful for biology measurements.
    Answer must be a fraction, not a decimal contextFraction.pl Requires fractional form; rejects decimal equivalents.
    Answer is a percentage contextPercent.pl Parses answers like "45%" and validates the percent sign.
    You need a custom answer checker answerCustom.pl Build a fully custom grading subroutine when standard checkers are insufficient.
    Partial credit for multi-part problems PGgraders.pl Provides full_partial_grader and other grading strategies.

    Tables, layouts, and visual tools

    These macros control how content is displayed, from data tables to scaffolded multi-part prompts to generated graphs. Most biology problems need at most niceTables.pl for data presentation.

    Tables, layouts, and visual tools reference.
    Use it when Macro to load Why it matters
    You need structured tables or aligned blanks niceTables.pl / unionTables.pl Keeps data displays clean and readable.
    You want scaffolded, multi-part prompts scaffold.pl Supports structured sections without custom logic.
    An interactive graph tool is required parserGraphTool.pl Provides interactive graph widgets.
    You need a TikZ-generated image in the problem PGtikz.pl Renders TikZ code to an image at display time.
    You need a LaTeX-generated diagram or figure PGlateximage.pl Renders arbitrary LaTeX snippets to images.

    Symptoms when missing

    Symptoms when missing: symptom, likely missing, and fix.
    Symptom Likely missing Fix
    PGML renders as raw text PGML.pl Load PGML.pl before BEGIN_PGML.
    Radio buttons do not appear parserRadioButtons.pl Add parserRadioButtons.pl to loadMacros().
    Checkbox list does not appear parserCheckboxList.pl (not available) Use per-statement RadioButtons or matching instead.
    MathObjects are undefined MathObjects.pl Load MathObjects.pl before using Real/Compute.

    Local render shows the line and missing macro when ADAPT only reports a generic error (Testing and Debugging).

    Graph, plotting, and image macros

    The renderer includes several macros for generating figures and plots. Most biology problems do not need dynamic graphs, but these are available when a problem requires a visual.

    Graph, plotting, and image macros: macro, what it does, and when to use it.
    Macro What it does When to use it
    PGgraphmacros.pl Creates 2D function plots using the WWPlot/Fun system. Simple function graphs (growth curves, dose-response). See Making Graphs.
    PGtikz.pl Renders TikZ code to an image. Custom diagrams, flowcharts, or annotated figures.
    PGlateximage.pl Renders arbitrary LaTeX to an image. Complex LaTeX-only figures or chemical structures.
    parserGraphTool.pl Interactive graph widget where students plot points or draw lines. Problems that ask students to construct a graph.
    LiveGraphics3D.pl Embeds interactive 3D graphics. Rarely needed for life-science problems. Available but niche.
    PGstatisticsGraphMacros.pl Pre-built statistical graph types (histograms, scatter plots). Statistics-oriented problems with data visualization.

    Statistics and numerical macros

    These macros are available in the renderer and are useful for quantitative biology, biostatistics, or ecology problems that involve data analysis.

    Statistics and numerical macros: macro, what it provides, and notes.
    Macro What it provides Notes
    PGstatisticsmacros.pl Statistical functions: mean, standard deviation, normal and t-distribution values. Useful for biostatistics problems involving hypothesis testing or confidence intervals.
    PGnumericalmacros.pl Numerical methods: interpolation, numerical integration, Newton's method. Rarely needed for biology. More common in engineering or physics.
    RserveClient.pl Connects to an R statistical computing server from within PG. Requires a running Rserve instance. Not available in most ADAPT deployments.

    Matrix and linear algebra macros

    Matrix macros are available in the renderer but are rarely needed for biology or life-science problems. They appear frequently in math and engineering problem libraries.

    Matrix and linear algebra macros: macro, what it provides, and notes.
    Macro What it provides Notes
    PGmatrixmacros.pl Basic matrix display and input helpers. Use for problems involving transition matrices (population genetics, Markov chains).
    MatrixCheckers.pl Answer checkers for matrix-valued answers. Validates student matrix input against correct answer.
    MatrixReduce.pl Row reduction and RREF utilities. Rarely needed for biology.
    contextMatrixExtras.pl Extra MathObject operations for matrices. Extends the Matrix context with additional operations.

    Complex number and specialized math macros

    These macros exist in the renderer for completeness but are almost never needed in biology or life-science problems. They are listed here so you recognize them if encountered in borrowed code.

    Complex number and specialized math macros reference.
    Macro What it provides Relevance to biology
    PGcomplexmacros.pl Complex number arithmetic and display. None. Remove if found in copied code.
    contextComplexExtras.pl / contextComplexJ.pl Extended complex number contexts (j instead of i). None. Engineering-oriented.
    PGdiffeqmacros.pl Differential equation display and solution helpers. Rare. Could appear in population dynamics or pharmacokinetics problems.
    PGpolynomialmacros.pl Polynomial manipulation utilities. None for typical biology problems.
    LinearProgramming.pl Simplex method and LP helpers. None. Operations research only.

    Quick reference: which macro for which task

    Use this table when you know what you want the problem to do but are not sure which macro provides it.

    Quick reference: which macro for which task: i want to... and load this macro.
    I want to... Load this macro
    Ask a multiple-choice question parserRadioButtons.pl
    Ask a dropdown selection question parserPopUp.pl
    Ask for a numeric answer with units parserNumberWithUnits.pl
    Require scientific notation in the answer contextScientificNotation.pl
    Accept a chemical reaction as input contextReaction.pl
    Require a fraction (no decimals) contextFraction.pl
    Accept a percentage answer like "45%" contextPercent.pl
    Display a data table in the problem niceTables.pl
    Create a multi-part scaffolded problem scaffold.pl
    Show a dynamically generated graph or plot PGgraphmacros.pl (or PGtikz.pl for custom diagrams)
    Let students arrange steps in order draggableProof.pl
    Give partial credit by part PGgraders.pl (or weightedGrader.pl for weighted scoring)
    Grade related answer blanks together parserMultiAnswer.pl
    Write a custom answer checker from scratch answerCustom.pl
    Provide targeted feedback for common mistakes answerHints.pl
    Ask for a free-response essay PGessaymacros.pl

    Do not cargo-cult

    • Remove macros you do not use and re-render.
    • Load macros only once per file.
    • Let dependencies load themselves; do not list everything "just in case."

    Next, depending on what you are doing:


    This page titled 2.5: Common PG Macros was last modified on Fri, 27 Feb 2026 15:15:26 GMT and is shared under a CC BY 4.0 license and was authored, remixed, and/or curated by Neil R. Voss.