Course-Wide Customizations

From WeBWorK_wiki
Revision as of 10:54, 7 June 2013 by Dpvc (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

It is often the case that different courses use different notation for the same concept. For example, some use angle brackets for matrix delimiters, as in <4,0,-1>, while others use parentheses. Some use [math]{\bf i}[/math], [math]{\bf j}[/math], and [math]{\bf k}[/math] for the coordinate unit vectors, while others use [math]\hat\imath[/math], [math]\hat\jmath[/math], and [math]\hat k[/math], or [math]\vec\imath[/math], [math]\vec\jmath[/math], and [math]\vec k[/math], or some other notation. Some prefer the [math]ijk[/math]-notation and others the delimited coordinate form.

It would be nice if you could set your preferences for this globally within your course and have it affect all the problems you use, rather than having to edit them all to use the notation that you would like. Although you don't have perfect control over this, there are some things you can do to move in that direction. The mechanism for doing this is to use the parserCustomization.pl file to make customized versions of the Contexts from the problems you are using so that the Context settings match your preferences.

First, make a copy of pg/macros/parserCustomization.pl and put it in your course's templates/macros folder (using the File Manager). Then edit it to include Context changes that you desire. If you want to make changes to the Vector Context, for example, you will need to make a copy of that in the %context hash, and then make your modifications, as in the example below. The Context() command knows to look in the %context hash first, and then to look in the default Context list, so when you put a new Context here, that makes it available via Context(). In particular, if you give the new Context the same name as the original one, then Context() will find your modified one first rather than the original one. In this way, you are overriding the settings in the original.

   $context{Vector} = Parser::Context->getCopy("Vector");
   $context{Vector}->flags->set(ijk=>1);         # force output in ijk-notation
   $context{Vector}->parens->remove('<');        # force entry of vectors in ijk-notation

Note that the last command will cause questions that use Compute("<...>") to produce error messages, since you have disabled the angle brackets as a means of creating vectors.

To allow students to enter vectors using parentheses rather than angle brackets, use

   $context{Vector} = Parser::Context->getCopy("Vector");
   $context{Vector}->{cmpDefaults}{Vector} = {promotePoints => 1};
   $context{Vector}->lists->set(Vector=>{open=>'(', close=>')'});

This actually just turns Points into Vectors in the answer checker for Vectors, and displays Vectors using parens rather than angle brackets. The student is really still entering what MathObjects thinks is a Point, but since Points get promoted automatically, that should work. If a problem checks if a student's value is actually a Vector, however, that will not be true.

An alternative would be to use

   $context{Vector} = Parser::Context->getCopy("Vector");
   $context{Vector}->lists->set(Vector=>{open=>'(', close=>')'});
   $context{Vector}->parens->set('('=>{type=>'Vector'});

which actually does force the student's answer to be a Vector object. The problem here is that there is now no way to enter an actual Point, since parentheses now produce Vectors.

Other similar changes can be made, but such changes may cause some problems to fail, since the defaults are no longer what they expect them to be. So if you take this route, be sure to check the problems you use very carefully before assigning them to students.