WeBWorK Main Forum

Forcing the limited fraction context in matrices

Forcing the limited fraction context in matrices

by Rick Lynch -
Number of replies: 1

I am in need of enforcing reduced fractions with limited use of operators inside matrices. I have tried to follow Davide's advice by adding 

Context()->parens->set("[" => {formMatrix => 1});

to the "LimitedFraction" context. The full code is attached.

It seems to force the entries to be reduced fractions and disallow operators to be used, but only when all answer blanks are not filled. However, it doesn't actually work when checking the entire matrix. That is, when a student enters all entries, it gives a weird 'Can't locate object method "weaken" via package "main"' error:

Another issue seems to be location of the errors. For unreduced fractions, it will actually say the entry that the fraction isn't reduced, but if it's an operator error, it doesn't (and in fact doesn't even give an error message):

Lastly, assuming I can get all of that above working somehow, is there a way to change all error messages for "Can't use 'op' in this context" to something more understandable by the students? I am aware I can change individual error message by doing something like:

@badops = ('+','-','*',' *','* ','^','**');
foreach $bad (@badops) {
    Context()->{error}{msg}{"Can't use '$bad' in this context"} = "Each entry must be a fully computed and reduced number";

but is there a way to cover all operators other than just adding everything to the @badops array? 

Thanks so much in advance!