Difference between revisions of "IntroToWeBWorKProblems"

From WeBWorK_wiki
Jump to navigation Jump to search
Line 9: Line 9:
 
===Source File===
 
===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
+
The source file for a WeBWorK problem is a text file 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
   
 
############################################################
 
############################################################
Line 56: Line 56:
 
We will learn what the parts of the problem are through [[ProblemAuthoring|another set of documentation]].
 
We will learn what the parts of the problem are through [[ProblemAuthoring|another set of documentation]].
   
==Creating Problem Files==
+
==Creating Problem Source Files==
   
From the preceding, we note that to write our own problems we have to ''create the problem source text files''.
 
  +
From the preceding, we note that to write our own problems we have to ''create the problem source text files''. This is no different than editing a web page or an e-mail message: in either case there may be ''mark-up'' that determines the formatting on the page, which is equivalent to the ''PG code and mark-up'' that determine the problem and how it apears to the student. We can edit the source file for a problem by editing it with our favorite editor (e.g., ''emacs'', ''vi'', ''Word'', ''OpenOffice'', etc.--being sure to save it as a text file with a <code>.pg</code> extension) on our computer, or by editing it through WeBWorK with WeBWorK's problem editor. You can get to the ''WeBWorK problem editor'' by looking at an existing problem in the Library Browser or in an existing problem set, and then clicking the "Edit" link that appears by the problem. You can also use this editor to create new problems: edit a problem, and create a copy of it to use for your new problem.
  +
  +
==Where to Put Problem Source Files==
  +
  +
To have a problem that you've created available for your course, it has to be in the '''templates''' directory of your course. If you create a copy of a WeBWorK problem using the problem editor, this is the location that it will be created (the <code>[TMPL]/</code> prefix in the "save as" option indicates the templates directory.
  +
  +
If you edit a problem with an editor on your computer, the '''WeBWorK File Manager''' will allow you to add it to the templates directory of your course.

Revision as of 21:52, 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 a text file 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 Source Files

From the preceding, we note that to write our own problems we have to create the problem source text files. This is no different than editing a web page or an e-mail message: in either case there may be mark-up that determines the formatting on the page, which is equivalent to the PG code and mark-up that determine the problem and how it apears to the student. We can edit the source file for a problem by editing it with our favorite editor (e.g., emacs, vi, Word, OpenOffice, etc.--being sure to save it as a text file with a .pg extension) on our computer, or by editing it through WeBWorK with WeBWorK's problem editor. You can get to the WeBWorK problem editor by looking at an existing problem in the Library Browser or in an existing problem set, and then clicking the "Edit" link that appears by the problem. You can also use this editor to create new problems: edit a problem, and create a copy of it to use for your new problem.

Where to Put Problem Source Files

To have a problem that you've created available for your course, it has to be in the templates directory of your course. If you create a copy of a WeBWorK problem using the problem editor, this is the location that it will be created (the [TMPL]/ prefix in the "save as" option indicates the templates directory.

If you edit a problem with an editor on your computer, the WeBWorK File Manager will allow you to add it to the templates directory of your course.