Skip to main content
Chemistry LibreTexts

3.1: Introduction to PGML

  • Page ID
    555703
  • ​

    ​

    \( \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}\)

    PGML is a markup language for writing the student-facing text of a WeBWorK problem. It is designed to replace older authoring styles that required long blocks of text and careful escaping.

    In this book, PG is treated as minimal setup code, and PGML is where you spend most of your authoring time.

    Use this when: you want the prompt to read like a worksheet while keeping the grading logic close to the text students see.

    Copy and edit (minimum viable PGML)

    This template shows a minimal PGML block with inline math, variable substitution, and one answer blank.

    $km = Real(2.5);
    $substrate = Real(12);
    $rate = Real(0.48);
    
    BEGIN_PGML
    For this enzyme, [`K_m = [$km]`] μM and [`[S] = [$substrate]`] μM.
    Report the rate [`v`] in μM/s:
    
    [`v = `] [____]{$rate}
    END_PGML
    

    Customize the variable names, the prompt text, and the answer expression in braces.

    Common failure and fix

    Without backtick delimiters, subscripts and Greek letters render as plain text instead of formatted math.

    Broken: Km = 2.5 μM
    Fix: [`K_m`] = 2.5 μM
    

    What PGML is good at

    • Readable prompts that look similar to the rendered output.
    • Math written in TeX or calculator notation with consistent delimiters.
    • Answer blanks tied directly to answer checkers.
    • Structured formatting for science prompts (lists, tables, and short sections).

    Most instructors do not need to learn PGML exhaustively. In practice, a small set of patterns covers the majority of biology and life science questions: inline math, answer blanks, short lists, and simple tables. This chapter focuses on those patterns so you can write readable prompts without treating PGML as another programming language.

    Math notation (TeX and calculator notation)

    PGML supports two styles for writing mathematics: TeX and calculator notation. Both styles support inline math and displayed math, and you should pick the one that matches the situation.

    Use TeX when you care about typesetting (for example, [`K_m`] or [`V_{max}`]). Use calculator notation when you care about readability and copy-paste (for example, [: Ct :] or [: C1*V1/V2 :] for a dilution).

    TeX math delimiters

    • Inline: [` ... `]
    • Display-style inline: [`` ... ``]
    • Display (own line): [``` ... ```]

    Calculator notation delimiters

    • Inline: [: ... :]
    • Display-style inline: [:: ... ::]
    • Display (own line): [::: ... :::]
    Calculator notation delimiters: task, delimiter, and example.
    Task Delimiter Example
    Variable name TeX inline [`K_m`]
    Short equation Calculator inline [: C1*V1/V2 :]
    Long equation TeX display [``` V = V_{max} * S/(K_m + S) ```]

    Science-friendly practice

    • Use inline math for variable names and short expressions.
    • Use display math for longer equations or multi-step expressions.
    • Keep units outside the math expression unless you are explicitly typesetting them.

    Math formatting vs variable substitution

    PGML uses square brackets for two different purposes. Confusing them is a common mistake.

    Math formatting vs variable substitution: purpose, syntax, example, and more.
    Purpose Syntax Example Result
    Math formatting [` ... `] [`K_m`] Renders K with subscript m
    Variable substitution [$variable] [$km] Displays value: 2.5
    Combined [`K_m = [$km]`] [`K_m = [$km]`] Math with value inserted

    Key rule: Use backticks when you want LaTeX math rendering. Use plain brackets (no backticks) when you want to display a variable's value as text.

    Common mistake

    Wrong: The answer is [`$radio->correct_ans`]
    Right: The answer is [$radio->correct_ans]
    

    The wrong version tries to render "Blue" as LaTeX math. The right version displays the text value.

    PGML is single-pass

    PGML parses your text exactly once. This means that if you build PGML tag-wrapper syntax inside a Perl variable, PGML will not re-parse it. The variable's contents are inserted as literal text, so patterns like [<...>]{[...]} stored in a string will not produce the expected formatting.

    A related pitfall involves the [< character sequence. If a Perl string assigned earlier in your code contains [<, it can collide with PGML's own bracket-angle syntax and produce parser errors or garbled output. Watch for this when building HTML snippets or conditional text in Perl and then inserting them with [$var].

    The single-pass rule also means that [$...] PGML interpolation inside a [@ ... @] eval block will not work. The eval block runs Perl; it does not re-enter the PGML parser. If you need formatted output from an eval block, return a string and let PGML display it.

    If you are writing your first problem, go to Answer blanks and answers now.

    Next, depending on what you are doing:


    This page titled 3.1: Introduction to PGML was last modified on Fri, 27 Feb 2026 15:30:22 GMT and is shared under a CC BY 4.0 license and was authored, remixed, and/or curated by Neil R. Voss.