HomeCurrent UR
|
This page is no longer being maintained.
The new URL for this content is
http://webwork.maa.org/wiki/SampleProblem1
| |
1 DOCUMENT();
2 loadMacros(
3 PGbasicmacros.pl,
4 PGanswermacros.pl,
5 PGchoicemacros.pl
6 );
7
8 TEXT(beginproblem());
9
10 BEGIN_TEXT
11 Complete the sentence: $PAR
12 \{ ans_rule(20) \} world!
13 END_TEXT
14 ANS( str_cmp( "Hello" ) );
15
16 ENDDOCUMENT();
1 DOCUMENT();The subroutine
DOCUMENT() must the first line of any pg problem. It does setup procedures and initializes much of the information that will be used later on by WeBWorK to create the problem.
3 loadMacros( 4 PGbasicmacros.pl, 5 PGanswermacros.pl, 6 );The
loadMacros() call loads the specified macro files so that any macros that have been defined within them will be readily available to the professor.
Mandatory modules:
$DOLLAR returns a $) and basic html tags (such as $PAR for <P>).
Optional modules:
8 TEXT(beginproblem());The
TEXT command is essentially the print command of the pg language. Everything that is passed to it, concatenated, evaluated, and then printed out.
10 BEGIN_TEXT
11 Complete the sentence: $PAR
12 \{ ans_rule(20) \} world!
13 END_TEXT
The BEGIN_TEXT/END_TEXT pair is a replacement for the older EV2 and EV3 tags.
BEGIN_TEXT and END_TEXT tags must be alone on a line, but everything between them is printed exactly AS IS.
\( ... \) tags.
$PAR)
\{ ... \} tags (such as the ans_rule(20) call which is a macro from PGbasicmacros.pl that creates an answer blank.)
14 ANS( str_cmp( "Hello" ) );The
ANS subroutine stores the answer evaluators used to evaluate the students answer by comparing the submitted answer to the one given by the instructor. How the answers are compared is determined by which answer evaluator is used (str_cmp("Hello") is one example) all of which are listed in PGanswermacros.pl.
16 ENDDOCUMENT();The
ENDDOCUMENT() finishes up the pg problem and makes sure everything closes out correctly. This must be the last line in your problem (at best anything after this will be ignored, at worst it will cause an error).
Final Notes:
Because we are writing a perl script, each statement must end in a semi-colon. Note however that many statements can be several lines long (such as loadMacros(), lines 2-5), these only require one semi-colon.
All of the extra exterior links, buttons, forms, pictures, etc that are common to all problems are generated by the WeBWorK scripts and do not (and cannot) be created within the pg problem itself.
| Prev | Next | tutorial |