WeBWorK Problems

Entering subscripts in student answers

Re: Entering subscripts in student answers

by Davide Cervone -
Number of replies: 0
Perhaps I could have them enter xi for xi, but then it would be nice to have a way for this to be redefined as x_i for the Preview.

This can be achieved fairly easily as in the following:

    Context()->variables->add(xi => ['Real',TeX=>"x_i"]);

It would seem to me that they should be allowed to enter x_i

I understand your desire for this, but I'm not sure the students will find it as natural as you do (as a TeX user). In any case, it can be done, but takes a bit more work. You need to change the allowed format for a variable name:

    Context()->variables->{namePattern} = qr/[a-z][a-z0-9]*(:?_(:?[a-z]|\d+))?/;
    Context()->variables->update;
    
    Context()->variables->add("x_i"=>"Real");
The TeX formatting will work out automatically for this. Note that you will need to add all the subscripted variables that you need, so with the example above, students could enter x_i but not x_k or y_i. Anything better than that would require some substantial additions to the MathObject Formula code.

Hope one of those works for you.

Davide