Difference between revisions of "PGLabs"

From WeBWorK_wiki
Jump to navigation Jump to search
(Update some formatting, and link to PGML sample)
Line 9: Line 9:
 
For example you could enter the code fragment below into the calculator:
 
For example you could enter the code fragment below into the calculator:
   
Context("Numeric");
+
Context("Numeric");
$f = Compute("x^2-3x+5");
+
$f = Compute("x^2-3x+5");
$fp = $f->D; # calculate the derivative
+
$fp = $f->D; # calculate the derivative
checkAnswer($fp, "2x-3"); # the first argument is a MathObject, the second the student's answer string
+
checkAnswer($fp, "2x-3"); # the first argument is a MathObject, the second the student's answer string
 
   
 
* On the last line <code>TEXT</code> prints the results of (reading from left to right)
 
* On the last line <code>TEXT</code> prints the results of (reading from left to right)
** Constructing the AnswerEvaluator for the contents of the Formula $fp
+
** Constructing the AnswerEvaluator for the contents of the Formula <code>$fp</code>
** Evaluating the string "2x-3" using this AnswerEvaluator to produce an AnswerHash
+
** Evaluating the string <code>"2x-3"</code> using this AnswerEvaluator to produce an AnswerHash
** Recursively representing the contents of the AnswerHash in a nice table
+
** Recursively representing the contents of the AnswerHash in a nice table.
checkAnswer() inserts its arguments into a more complicated command. e.g. last line above becomes:
+
TEXT($fp->cmp->evaluate("2x-3")->pretty_print );
+
<code>checkAnswer()</code> inserts its arguments into a more complicated command. e.g. last line above becomes:
  +
  +
TEXT($fp->cmp->evaluate("2x-3")->pretty_print);
   
 
=== PGML markup lab ===
 
=== PGML markup lab ===
Line 30: Line 30:
 
https://courses.webwork.maa.org/webwork2/cervone_course/PGML-examples/?login_practice_user=true
 
https://courses.webwork.maa.org/webwork2/cervone_course/PGML-examples/?login_practice_user=true
   
To use these commands in your own courses you will need a recent version of PG. (You can update by changing
+
To use these commands in your own courses you will need a recent version of PG. (You can update by changing to the <code>/opt/pg</code> directory and typing
to the /opt/pg directory and typing
+
cvs update -A
+
cvs update -A
which will get you the latest version of all of the PG code
+
You can move back to the more stable code base by typing
+
which will get you the latest version of all of the PG code. You can move back to the more stable code base by typing
cvs update -r rel-2-4-patches
+
  +
cvs update -r rel-2-4-patches
  +
  +
Include <code>PGML.pl</code> in your <code>loadMacros()</code> segment. Start the display of your problem text with <code>BEGIN_PGML</code> which expands to
  +
  +
TEXT(PGML::Format2(<<'END_PGML'));
   
Include PGML.pm in your loadMacros() segment.
 
  +
and end with <code>END_PGML</code>. These are used instead of the usual <code>BEGIN_TEXT/END_TEXT</code> construct. You can use both <code>BEGIN_TEXT/END_TEXT<code> and <code>BEGIN_PGML/END_PGML</code> in the same problem, if you wish. See [[SampleProblem4]] for an example (with explanation) that uses PGML.
Start the display of your problem text with BEGIN_PGML which expands to
 
TEXT(PGML::Format2(<<'END_PGML'));
 
and end with END_PGML
 
These are used instead of the usual BEGIN_TEXT/END_TEXT construct. You can use both BEGIN_TEXT/END_TEXT and BEGIN_PGML/END_PGML in the same question.
 
   
 
[[Category:Authors]]
 
[[Category:Authors]]

Revision as of 14:43, 20 July 2012

On-line labs for rendering of PG code. These two labs allow you to experiment with PG syntax.

Test your PG code fragments

Click on this link to go to PG calculator:

http://hosted2.webwork.rochester.edu/webwork2/wikiExamples/MathObjectsLabs2/2/?login_practice_user=true

For example you could enter the code fragment below into the calculator:

   Context("Numeric");
   $f = Compute("x^2-3x+5");
   $fp = $f->D; # calculate the derivative
   checkAnswer($fp, "2x-3");      # the first argument is a MathObject, the second the student's answer string
  • On the last line TEXT prints the results of (reading from left to right)
    • Constructing the AnswerEvaluator for the contents of the Formula $fp
    • Evaluating the string "2x-3" using this AnswerEvaluator to produce an AnswerHash
    • Recursively representing the contents of the AnswerHash in a nice table.

checkAnswer() inserts its arguments into a more complicated command. e.g. last line above becomes:

   TEXT($fp->cmp->evaluate("2x-3")->pretty_print);

PGML markup lab

  • Experiment with the new PG markup language syntax (PGML) which simplifies the graphical layout of the mathematics question. This is not yet available in the rel-2-4-patches release of WeBWorK but can be used if you update the pg code to HEAD. This is fairly safe since no modifications of configuration files are needed and existing problems are not likely to be affected. (The code base on hosted2.webwork.rochester.edu/webwork2 where many WeBWorK courses are hosted has been updated to HEAD and will run PGML.)

https://courses.webwork.maa.org/webwork2/cervone_course/PGML?login_practice_user=true

Several dozen questions illustrating the use of PGML:

https://courses.webwork.maa.org/webwork2/cervone_course/PGML-examples/?login_practice_user=true

To use these commands in your own courses you will need a recent version of PG. (You can update by changing to the /opt/pg directory and typing

   cvs update -A   
which will get you the latest version of all of the PG code.  You can move back to the more stable code base by typing
   cvs update -r rel-2-4-patches

Include PGML.pl in your loadMacros() segment. Start the display of your problem text with BEGIN_PGML which expands to

   TEXT(PGML::Format2(<<'END_PGML'));

and end with END_PGML. These are used instead of the usual BEGIN_TEXT/END_TEXT construct. You can use both BEGIN_TEXT/END_TEXT and BEGIN_PGML/END_PGML in the same problem, if you wish. See SampleProblem4 for an example (with explanation) that uses PGML.