WeBWorK Problems

Entering subscripts in student answers

Entering subscripts in student answers

by Paul Seeburger -
Number of replies: 1

Is there a way to allow students to enter subscripts in their answers?

For example, for Calc 2 volume problems, I would like my students to enter the formula for area of the ith rectangle using subscripts on x or y.

Ex. Ai = (xi2 - xi)*delta xi.

I suppose this also requires them to enter delta x.

It would seem to me that they should be allowed to enter x_i, but I cannot seem to get the context to recognize this as a legal variable.

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.

Anyone have suggestions for me?

Thanks!

Paul

In reply to Paul Seeburger

Re: Entering subscripts in student answers

by Davide Cervone -
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