Difference between revisions of "IntroToWeBWorKProblems"
(Created page with '==What a WeBWorK Problem Is== A WeBWorK problem consists of two related things: '''database metadata''', that indicate the characteristics of the problem in the WeBWorK problem …') |
|||
Line 11: | Line 11: | ||
The source file for a WeBWorK problem is written using the '''PG''' (''Problem Generation'') language, which is based in the scripting language ''Perl'' and allows use of ''TeX'' to typeset mathematics in the text that the student sees. A very simple example of the text of a source file for a problem is the following |
The source file for a WeBWorK problem is written using the '''PG''' (''Problem Generation'') language, which is based in the scripting language ''Perl'' and allows use of ''TeX'' to typeset mathematics in the text that the student sees. A very simple example of the text of a source file for a problem is the following |
||
+ | ############################################################ |
||
# DESCRIPTION |
# DESCRIPTION |
||
# Very simple sample problem for WeBWorK PREP workshop |
# Very simple sample problem for WeBWorK PREP workshop |
||
Line 17: | Line 18: | ||
DOCUMENT(); |
DOCUMENT(); |
||
− | |||
loadMacros( "PGstandard.pl", "MathObjects.pl" ); |
loadMacros( "PGstandard.pl", "MathObjects.pl" ); |
||
############################################################ |
############################################################ |
||
# problem set-up |
# problem set-up |
||
+ | # |
||
Context("Numeric"); |
Context("Numeric"); |
||
− | |||
$a = random(2,8,1); |
$a = random(2,8,1); |
||
$f = Compute( "x^$a" ); |
$f = Compute( "x^$a" ); |
||
− | |||
+ | |||
############################################################ |
############################################################ |
||
# text |
# text |
||
− | + | # |
|
TEXT(beginproblem()); |
TEXT(beginproblem()); |
||
Context()->texStrings; |
Context()->texStrings; |
||
BEGIN_TEXT |
BEGIN_TEXT |
||
− | |||
Find the derivative of \(f(x) = $f\): |
Find the derivative of \(f(x) = $f\): |
||
$BR |
$BR |
||
\( f'(x) = \) \{ $f->ans_rule(10) \} |
\( f'(x) = \) \{ $f->ans_rule(10) \} |
||
− | |||
END_TEXT |
END_TEXT |
||
Context()->normalStrings; |
Context()->normalStrings; |
||
− | |||
+ | |||
############################################################ |
############################################################ |
||
# answer and solution |
# answer and solution |
||
− | + | # |
|
$fp = $f->D() |
$fp = $f->D() |
||
ANS( $fp->cmp() ); |
ANS( $fp->cmp() ); |
||
Line 55: | Line 53: | ||
ENDDOCUMENT(); |
ENDDOCUMENT(); |
||
− | |||
+ | |||
− | # end of problem |
||
+ | We will learn what the parts of the problem are through [[ProblemAuthoring|another set of documentation]]. |
||
− | ############################################################ |
||
+ | |||
+ | ==Creating Problem Files== |
||
+ | |||
+ | From the preceding, we note that to write our own problems we have to ''create the problem source text files''. |
Revision as of 20:35, 25 May 2011
What a WeBWorK Problem Is
A WeBWorK problem consists of two related things: database metadata, that indicate the characteristics of the problem in the WeBWorK problem set (things like the number of attempts, problem weight, etc.), which exist in the WeBWorK database, and a source file which is a text file that defines what text students see, the solution text for the problem, and the algorithmic definition of the mathematics in the problem.
Database Metadata
Database metadata are defined within WeBWorK, usually through the Set Detail editing page in the Instructor Tools in the WeBWorK interface. These data may also be imported from a set definition file to create the parameters of the set and problems in it en masse.
Source File
The source file for a WeBWorK problem is written using the PG (Problem Generation) language, which is based in the scripting language Perl and allows use of TeX to typeset mathematics in the text that the student sees. A very simple example of the text of a source file for a problem is the following
############################################################ # DESCRIPTION # Very simple sample problem for WeBWorK PREP workshop # WeBWorK problem written by Gavin LaRose, <glarose@umich.edu> # ENDDESCRIPTION DOCUMENT(); loadMacros( "PGstandard.pl", "MathObjects.pl" ); ############################################################ # problem set-up # Context("Numeric"); $a = random(2,8,1); $f = Compute( "x^$a" ); ############################################################ # text # TEXT(beginproblem()); Context()->texStrings; BEGIN_TEXT Find the derivative of \(f(x) = $f\): $BR \( f'(x) = \) \{ $f->ans_rule(10) \} END_TEXT Context()->normalStrings; ############################################################ # answer and solution # $fp = $f->D() ANS( $fp->cmp() ); Context()->texStrings; SOLUTION(EV3(<<'END_SOLUTION')); $PAR SOLUTION $PAR \( f'(x) = $fp \), by the power rule. END_SOLUTION Context()->normalStrings; ENDDOCUMENT();
We will learn what the parts of the problem are through another set of documentation.
Creating Problem Files
From the preceding, we note that to write our own problems we have to create the problem source text files.