WeBWorK Problems

options for display of vectors (and answers)

Re: options for display of vectors (and answers)

by Michael Gage -
Number of replies: 0
As a last resort -- here is a method to directly modify what you want displayed as the correct answer:

ANS( $ev -> cmp()->withPostFilter( 
 sub { my $ans_hash=shift; 
 "\left<\frac{$a}{$norm}, \frac{$b}{\sqrt{$a^2+$b^2}}\right>";

The post filter explicitly changes the TeX for the correct answer, after it
has been computed during the comparing operation. (If you change the
{correct_ans_latex_string} before the comparison it just gets overwritten when the comparison occurs.)

One more gotcha -- no comparison occurs if the answer blank is empty -- so in that case no latex string is calculated and only the raw correct answer occurs. In other words to review your correct answer you must enter SOMETHING into the answer blank or you will never see the lovely tex message you have created!

This bug (which I helped create :-) ) kept me busy for several hours today. :-(.

A change to MathObjects which creates the {correct_ans_latex_string} when the object is created would, I think, fix this. It would also simplify
the evaluation of answers in Problem.pm (This is a technical note -- so we
can remember what could be improved.)
If you do this often you could write the following subroutine in your problem
or in PGcourse.pl

sub fixCorrectAnswer {
 my $latex_string = shift;
 sub {
  my $ans_hash = shift;

and call it with

ANS( $ev -> cmp()->withPostFilter(