Skip to main content
Chemistry LibreTexts

7.1: Simple Syntax Checking (Linting) in WeBWork

  • Page ID
    557407
  • ​

    ​

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

    Use this section when you want to catch mistakes before students see them. Linting means checking your problem file for common errors, either by reading through it yourself (static checks) or by running it through the renderer and inspecting the output. Both approaches catch different kinds of issues, so use them together.

    Think of linting like proofreading a lab protocol. Some errors you can catch by reading the text carefully. Others only show up when you actually run the protocol and watch what happens. A good QA pass uses both strategies: read the code for known pitfalls, then render the problem and inspect the result in a browser.

    What linting catches that reading misses

    • Variables that look correct in source but render wrong because of escaping or parsing rules (see Introduction to PGML for PGML syntax basics)
    • HTML that gets escaped when you wanted it to render as formatted content
    • PGML syntax that parses differently than you expected (list markers, bold, eval blocks)
    • Missing macros that only fail at render time, not while reading the code (see Common Mistakes and How to Fix Them for common macro mistakes)
    • Layout issues that only appear in a browser (spacing, alignment, missing blanks)

    Static checks you can do by eye

    These are patterns you can search for in your source file before rendering. Each one causes a specific failure that is easy to miss in the code but obvious in the rendered output.

    Static checks you can do by eye reference.
    What to look for Why it matters What to do
    PGML tag wrappers inside Perl variables ("[<" or "]{[" in string assignments) PGML parses once. Tags in variables are not re-parsed. Move PGML syntax out of variables and into the PGML block directly.
    HTML in variables without * (variable contains <span, <div, etc. but is output as [$var] without trailing *) PGML escapes the HTML. You see literal tags instead of formatted text. Add * after the bracket: [$var]*
    MODES( inside [@ ... @] eval blocks MODES returns 1 in eval context, not the HTML string. Use [@ ... @]* with MODES only for wrapper divs. For simple HTML, use [$var]* instead.
    TeX color macros (\color{ or \textcolor{) in PGML MathJax does not render these in this install. Use HTML <span> styles for color instead.
    Blocked HTML tags: <table, <tr, <td, <th These tags are stripped by the HTML whitelist. Use niceTables.pl (DataTable or LayoutTable) for any tables.
    Ordered list label patterns: A. or B. at the start of a line in PGML PGML may parse these as list markup instead of plain text. Use *A.* (bold) or escape the dot: A\.

    Structural checks

    These checks confirm that the required scaffolding of a PG file is in place. Missing any of these causes the renderer to fail or produce partial output.

    Structural checks: check, what to look for, and symptom if missing.
    Check What to look for Symptom if missing
    Missing DOCUMENT(); File does not start with DOCUMENT() after loadMacros Render fails with a cryptic error
    Missing ENDDOCUMENT(); File does not end with ENDDOCUMENT() Render fails or produces partial output
    Unmatched BEGIN_PGML / END_PGML One is present without the other Parse error, content not rendered
    Nested BEGIN_PGML without closing Two BEGIN_PGML in a row without an END_PGML between them Parse error
    Unbalanced [@ ... @] eval blocks Opening [@ without closing @] or vice versa PGML parse failure

    Renderer-based lint

    Static checks catch many issues, but some problems only surface when the renderer actually processes the file. Renderer-based lint sends your file through the same pipeline students will use and reports errors, warnings, and the final HTML output.

    HTML render is the primary test

    WeBWorK questions are designed for browsers, so the rendered HTML is the most important check. Render your problem, save the output as an HTML file, and open it in a browser. Check: Does the question text read clearly? Are all blanks visible? Does the layout look right? Are interactive widgets (radio buttons, dropdowns) displaying correctly instead of plain text boxes?

    Using the lint script

    The helper script lint_pg_via_renderer_api.py wraps the renderer API for a local file. It sends your PG source to the renderer, collects any lint messages, and optionally saves the rendered HTML.

    To get lint messages only (no HTML output), omit the -r flag:

    python3 lint_pg_via_renderer_api.py -i private/myproblem.pg
    

    To generate full HTML output for visual inspection, include the -r flag and redirect the output to a file:

    python3 lint_pg_via_renderer_api.py -i private/myproblem.pg -r > /tmp/pg_render.html
    

    The script prints the seed it uses. You can set a specific seed with -s:

    python3 lint_pg_via_renderer_api.py -i private/myproblem.pg -s 1234 -r > /tmp/pg_render.html
    

    What to check in the output

    • Render errors: The renderer reports line numbers and error messages. Fix these first, since they usually mean the problem will not display at all.
    • Warnings: Check for PGML parse warnings. These may not prevent rendering but can cause unexpected behavior for some students or certain seeds.
    • Visual inspection: Open the HTML in a browser and read it like a student. Check that text is formatted correctly, blanks appear where expected, and no raw markup is visible.
    • Widget behavior: Confirm that interactive widgets (radio buttons, dropdowns, checkboxes) display as the correct widget type, not as a plain text input box.

    A simple lint workflow

    Follow these steps in order each time you finish editing a problem. The whole process takes less than a minute once you are familiar with it.

    1. Save your .pg file.
    2. Run the lint script without -r to check for errors.
    3. Fix any reported issues.
    4. Run the lint script with -r to generate HTML.
    5. Open the HTML file in your browser.
    6. Read the question as a student would.
    7. Check that every answer blank appears and is in the right place.

    Apply it today

    Run a lint check on one problem file today. Fix any issues it reports, then open the HTML in your browser and read the question as if you were a student seeing it for the first time. If the text is clear, the blanks are visible, and the layout looks right, your problem is ready for further testing.


    This page titled 7.1: Simple Syntax Checking (Linting) in WeBWork was last modified on Fri, 27 Feb 2026 15:41:32 GMT and is shared under a CC BY 4.0 license and was authored, remixed, and/or curated by Neil R. Voss.