WeBWorK Problems

Is there a way to make a string answer display as a symbol in Preview?

Is there a way to make a string answer display as a symbol in Preview?

by Paul Seeburger -
Number of replies: 4
I am trying to allow the students to enter 'null set' as their answer, but have it display as a true null set using '\varnothing' in the Preview window.  Is this possible?

I could not find documentation on the options for a string being added to a context.  Maybe there's a way to make this substitution in a meaningful way.  I was able to do it with an alias, but it showed that the student had entered '\varnothing' instead of 'null set', but in the Preview window it did display the real null set character.  So I was close.  =)

Ideally, it would be great to be able to display a small template with characters like infinity, the null set, etc. on it for students to click on to include in their answers.  Of course we have the option of turning MathView on for the whole course, but I am interested in having something simpler available.  Perhaps it can be done with JavaScript.  Has anyone tried this?

Thanks!

Paul
In reply to Paul Seeburger

Re: Is there a way to make a string answer display as a symbol in Preview?

by Davide Cervone -
Use
Context()->strings->add(
  "null set" => {TeX => "\varnothing"}
);
to set the TeX version of the string to \varnothing.

If you use this for student answers, you may run into some troubles.

For example, you should be sure to add the typeMatch option when you use this as a correct answer so that you can get correct error messages:

ANS(Compute("null set")->cmp(typeMatch=>Value::Set));
(otherwise the error messages will say they are looking for a number not a set).

Also, if a student answers {} or some set expression that leads to an empty set, e.g., [1,2]-(0,3), then their answer will be marked wrong.

In reply to Paul Seeburger

Re: Is there a way to make a string answer display as a symbol in Preview?

by Davide Cervone -
On the other hand, you might be better off with a constant rather than a string object for this (since the null set is already something that has a MathObject that can represent it). The only problem is that constants normally aren't allowed to have spaces in their names, so you have to fix the allowed name pattern as well:
Context("Interval");
Context()->{_constants}{namePattern} = qr/[a-zA-Z][a-zA-Z0-9_ ]*/;  # allow space in constant names
Context()->update;

Context()->constants->add(
  "null set" => Set(),     # the empty set
);
or
Context("Interval");
Context()->{_constants}{namePattern} = qr/[a-zA-Z][a-zA-Z0-9_ ]*/;  # allow space in constant names
Context()->update;

Context()->constants->add(
  "null set" => {value => Set(), TeX => "\varnothing"}
);
if you really want this to show up as the symbol. I'm not sure I'd do that, however. If you use "null set" as the correct answer, then the correct answer column will show the symbol, and it will not be clear to the students how to enter the answer (unless they use the hover tooltip to see what to type). Also, if they enter null sets in other ways, like as {}, which is the default means of doing it, then it will not show up as the empty-set symbol.
In reply to Davide Cervone

Re: Is there a way to make a string answer display as a symbol in Preview?

by Paul Seeburger -
This makes sense, Davide!

I think I plan to leave it as null set for now, although I may fix the error message given when a set answer is attempted.  Currently it says the answer does not look like a number (which of course it really should not be).

But I appreciate learning how to change the TeX for the answer if I need to do this in the future, and the other tips you've given here are good information too.

As I mentioned before, someday it will ideally be possible to insert a small template (JavaScript?) that includes a few useful symbols like infinity, is an element of, the null set, the set of Real numbers, etc.

Thanks!

Paul
In reply to Paul Seeburger

Re: Is there a way to make a string answer display as a symbol in Preview?

by Davide Cervone -
Currently it says the answer does not look like a number (which of course it really should not be).

Right, that is why I suggested this was not the best approach. Adding the typeMatch option will take care of that.