Command substitution - PGML
Command Substitution
You can perform a perl command by surrounding it with [@ ... @]
and its output will be placed into the problem at that point.
The sum of 1 and 2 is [@ 1+2 @].
You can use this inside math mode as well, which can help make it easier to produce solutions (without having to have lots of variables that contain intermediate results).
To solve for [: x + [$a] = [$b]x :], subtract the [:x:] from both sides to get [: [$a] = [$b]x - x = ([$b] - 1) x = [@ $b-1 @] x:], and then divide by [: [@ $b-1 @] :] to get [: x = [$a]/[@ $b-1 @] = [@ Fraction($a,$b - 1)->reduce @] :].
If the command produces output that is already formatted, follow it by a star.
Enter your response: [@ ANS(String("none")->cmp); ans_box(3,40) @]*
Since PGML doesn't include a means of producing an answer box, the example above shows how you can do so using the PG commands directly.
Similarly, PGML doesn't yet include any direct support for images, but you can get them as in the following example
[@ image(insertGraph($graph), width=>300, height=>300) @]*
which inserts a graph created dynamically earlier in the problem.
See the section on Escaping Substitutions for more details about how the result will be interpreted when it is inserted into the output by PGML.