WeBWorK Problems

Error using PGML macro

Error using PGML macro

by Jennifer Thorenson -
Number of replies: 10

We recently completed a new installation of WeBWorK version 2.17 and have discovered that some of the problems in the OPL do not render.  The issue that we have involves the problems that use the PGML macro to display an image within the BEGIN_PGML/END_PGML environment.

For example, the library problem Library/Valdosta/APEX_Calculus/1.4/APEX_1.4_12.pg does not render

Within the PGML environment, the problem has the line of code

>> [![$alttext]!]{$graph1}{400} <<

which produces warning messages when the problem is compiled.  The warning messages are

PG warning messages


------
---- PGML (eval 1709) 1504 ------
==================
Errors parsing PGML:
Error: extra option '400'
Warning: unknown block type 'image' in PGML::Format::html::format

Warning messages

  • Use of uninitialized value $string in string eq at line 928 of [PG]/macros/PGML.pl
Similar error messages are produced by other OPL problems that use the PGML macro to display images. 

Do you have a recommendation for how to fix this issue?

In reply to Jennifer Thorenson

Re: Error using PGML macro

by Alex Jordan -
The current version of WeBWorK is 2.18, since summer of 2023. (And this coming summer, 2.19 will be released.) The current version of the OPL has problems that use features that were only developed for 2.18 (and beyond, of course). For example the PGML that you cited here was only added in version 2.18.

If you are not able to upgrade WeBWorK to 2.18, you could consider downgrading your OPL. There is a "v2023-04-30" tag that you could check out. Or you you could rewind commits in the OPL back to a bit later, sometime in summer 2023. Then there should be no 2.18 features in the OPL.
In reply to Alex Jordan

Re: Error using PGML macro

by Glenn Rice -

As Alex stated, the "v2023-04-30" tag will work.  Note that if you run the webwork2 "OPL-update" script, that will take care of checking out that branch and setting up the database.

In reply to Glenn Rice

Re: Error using PGML macro

by Larry Riddle -
We are having the same issue as described above with the PGML.pl macro and PGML code like [![$alttext]!]{$graph1}{400} that is found in the Valdosta APEX_Calculus files in the OPL. But we ARE on version 2.18 of WebWork. I just tried running OPL-update and it shows

Downloading the latest OPL release.
Found OPL METADATA release v2024-08-14.
Downloaded release archive, now extracting.
Restoring OPL tables from release database dump.
OPL path seems to be /opt/webwork/libraries/webwork-open-problem-library/
Removing temporary files.
Done!
Using WeBWorK root: /opt/webwork/webwork2
Using library root: /opt/webwork/libraries/webwork-open-problem-library/OpenProblemLibrary
Using contrib root: /opt/webwork/libraries/webwork-open-problem-library/Contrib
Saved OPL set definition list to /opt/webwork/webwork2/htdocs/DATA/library-set-defs.json.
Saved Contrib set definition list to /opt/webwork/webwork2/htdocs/DATA/contrib-set-defs.json.

I have checked that the content of the local OPL pg files having issues is the same as that for the github version of the OPL. They are using PGtikz.pl to draw the graphs, but we still getting the same warning messages as shown in the original message.

Here is one example of a problem that is failing.
OpenProblemLibrary/Valdosta/APEX_Calculus/2.2/APEX_2.2_18.pg

DOCUMENT();

# Load whatever macros you need for the problem
loadMacros(
'PGstandard.pl', 'PGML.pl', 'PGtikz.pl', 'parserPopUp.pl',
'PGcourse.pl'
);

$a = random(1, 4, 0.2) * random(-1, 1, 2);

$graph = createTikZImage();
$graph->tikzLibraries('arrows.meta');
$graph->BEGIN_TIKZ
\tikzset{>={Stealth[scale=1.5]}}
\filldraw[
draw=LightBlue,
fill=white,
rounded corners=10pt,
thick,use as bounding box
] (-7,-7) rectangle (7,7);
\draw[->,thick] (-6.5,0) -- (6.5,0) node[above left,outer sep=3pt] {\(x\)};
\foreach \x in {-6,...,-1,1,2,...,6}
\draw(\x,5pt) -- (\x,-5pt) node [below] {\(\x\)};
\draw[->,thick] (0,-6.5) -- (0,6.5) node[below right,outer sep=3pt] {\(y\)};
\foreach \y in {-6,...,-1,1,2,...,6}
\draw (5pt,\y) -- (-5pt,\y) node[left] {\(\y\)};
\draw[blue,ultra thick, dashed] plot[domain=-6:6,samples=100, smooth]
(\x,{$a*cos(pi*\x/2 r)});
\draw[ForestGreen,ultra thick] plot[domain=-6:6,samples=100, smooth]
(\x,{$a*sin(pi*\x/2 r)});
END_TIKZ

$negA = -$a;

$altText =
$a > 0
? "A graph with two plots. The green one is oscillates starting at "
. "(-6,0) falls to (-5, $negA), rises through (-4,0) to a maximum at (-3, $a) "
. "to (-2,0). This repeats through the rest of the plot. The blue one (dashed) "
. "starts at (-6,$negA), rises through (-5,0) to a maximum at (-4, $a) "
. "falls through (-3,0) to a minimum at (-2, $negA). This repeats through the "
. "rest of the plot."
: "A graph with two plots. The green one is oscillates starting at "
. "(-6,0) rises to (-5, $negA), falls through (-4,0) to a minium at (-3, $a) "
. "to (-2,0). This repeats through the rest of the plot. The blue one (dashed) "
. "starts at (-6,$negA), falls through (-5,0) to a minimum at (-4, $a) "
. "rises through (-3,0) to a maximum at (-2, $negA). This repeats through the "
. "rest of the plot.";

$ans_a = "f is green and its derivative is dashed blue";
$ans_b = "f is dashed blue and its derivative is green";
$ans = DropDown([ [ $ans_a, $ans_b ] ], $ans_a);

BEGIN_PGML
The graphs of two functions are shown below. One is the graph
of [`f(x)`] and the other is the graph of its derivative,
[`f'(x)`]. Identify which graph is which.
>> [![$altText]!]{$graph}{300} <<

[_]{$ans}

END_PGML

ENDDOCUMENT();

which produces the messages

PG warning messages

------
---- PGML (eval 3876) 1503 ------
==================
Errors parsing PGML:
Error: extra option '300'
Warning: unknown block type 'image' in PGML::Format::html::format
==================
__________________________
WeBWorK Warnings

WeBWorK has encountered warnings while processing your request. If this occured when viewing a problem, it was likely caused by an error or ambiguity in that problem. Otherwise, it may indicate a problem with the WeBWorK system itself. If you are a student, report these warnings to your professor to have them corrected. If you are a professor, please consult the warning output below for more information.

Warning messages

Use of uninitialized value $string in string eq at line 927 of [TMPL]/macros/PGML.pl.
In reply to Larry Riddle

Re: Error using PGML macro

by Danny Glin -
This file loads fine for me in 2.19 (I don't have a 2.18 install to test against).

Did you update PG to 2.18 when you updated WeBWorK?
In reply to Larry Riddle

Re: Error using PGML macro

by Glenn Rice -
Are you also on PG 2.18 (or 2.19)? The warning that you are getting suggests that you might not have updated /opt/webwork/pg.
In reply to Glenn Rice

Re: Error using PGML macro

by Larry Riddle -
In reply to Larry Riddle

Re: Error using PGML macro

by Sean Fitzpatrick -

This won't be any help to Larry, but I checked this problem from Valdosta on a WeBWorK 2.18 server, and it works for me. So I am not sure what is different for Larry.

In reply to Sean Fitzpatrick

Re: Error using PGML macro

by Larry Riddle -

If it is of any help, if I remove the line

>> [![$altText]!]{$graph}{300} <<

then no error warnings are given (and, of course, no graph is displayed).

In reply to Larry Riddle

Re: Error using PGML macro

by Alex Jordan -

Does this happen in all courses? What I am wondering is if you have a course with some local copy of an old PGML.pl file in its macros folder.

In reply to Alex Jordan

Re: Error using PGML macro

by Larry Riddle -
Bingo!! Yes, the course in which the error was occurring had a copy of PGML.pl in its macros folder. I renamed it to PGML.pl.old and the pg file then ran successfully with no warnings. There was one other course I checked in which the error occurred, and that course also had a PGML.pl file in its macros folder. I have no recollection of why these two courses had this local copy, but at least none of our other courses had one. So thanks, Alex, for providing the solution. Much appreciated. And thank you Danny, Glen, and Sean for also taking a look at this for me. This forum has come to my rescue many times.