WeBWorK Problems

Questions about correct_ans_latex_string

Questions about correct_ans_latex_string

by Alex Jordan -
Number of replies: 5
In the answer hash, correct_ans_latex_string does not seem to respect the flag showExtraParens. I frequently see correct answers displayed with extra parens, especially answers like "x=(-7)" and "-(sqrt(5))". If I set showExtraParens=>0, then this affects correct_ans, but not correct_ans_latex_string. I've been wondering if this is intentional or if this was an oversight when correct_ans_latex_string was introduced. The only way I can find to remove extra parens from correct_ans_latex_string is to manually change it - which goes against my code-writing instincts (address the problem, not the symptom). If this is the intended behavior, is there a nonmanual way to remove extra parens from correct_ans_latex_string?

Another question I have is why we sometimes see correct_ans and other times correct_ans_latex_string displayed as the correct answer. The behavior I typically see is that if I check "show correct answers" without having entered any answer, I see correct_ans. But if I have entered an answer into the corresponding answer blank, then I see correct_ans_latex_string. Am I understanding the behavior right, and is this the intended behavior?
In reply to Alex Jordan

Re: Questions about correct_ans_latex_string

by Alex Jordan -
Another thing about correct_ans_latex_string: when correct answers actually are strings, they should be encased in \text{} or something similar. Right now if the answer is say "no solutions" it is seemingly put into correct_ans_latex_string as is, and the result looks sort of like "n o s o l u t i o n s".
In reply to Alex Jordan

Re: Questions about correct_ans_latex_string

by Davide Cervone -
The String object's TeX output needs to be overhauled to handle more situations. It was originally intended only for single words (like "none" and "DNE"), but it is being used for more complicated things (like phrases, or special symbols), and the TeX output doesn't handle that well.

You can always override the TeX output using something like

    Context()->strings->add("no solutions" => {TeX=>"\text{no solutions}"});
if you prefer.

Davide

In reply to Alex Jordan

Re: Questions about correct_ans_latex_string

by Davide Cervone -
The correct_ans_latex_string is a relatively recent addition to WeBWorK, and it was not there when MathObjects were written. When it was added, someone patched the MathObject answer checker code to create it, but the place that that is done is not really the right place.

One consequence of this is that the correct_ans_latex_string is only set when the answer checker actually runs, and that only happens when the answer blank is not empty. If correct_ans_latex_string is not set, then correct_ans is used instead, and that is why you see the latter when there is no answer, and the former when there is.

I have recently submitted a patch that corrects this, but I don't think it is in v2.7, so it should be in 2.8.

The TeX output should not include extra parentheses (that is only for string output), and so it does not use the showExtraParens value. It turns out, however, that the parserAssignment code contained a typo so that the TeX output was using the string output for the value rather than the TeX output, so you wold get extra parentheses in that case. I recently submitted a patch for that as well. You can get the current version and put it in your course's macros directory if you want. See if that doesn't resolve the issue.

Davide
In reply to Davide Cervone

Re: Questions about correct_ans_latex_string

by Alex Jordan -
Makes a lot of sense. And as I now understand, the patch is for one or more .pm files, so it isn't something that we could grab by updating our libraries.
In reply to Alex Jordan

Re: Questions about correct_ans_latex_string

by Davide Cervone -
Yes, the fix for the corrections_latex_string is in the ,pm files, so not something you can override without system access, and not something that can be changed on a course-by-course basis.