## WeBWorK Problems

### Answer preview format string for MathObjects.

by Jaimos Skriletz -
Number of replies: 1

Using parserMultiAnswer.pl, I can set both format and tex_format strings to display the answers in the answer preview.

Is a similar thing possible with a MathObject? I can wrap the answer through a MultiAnswer grader with one item to get the result I want, but would prefer a way that didn't need to use MultiAnswer.

### Re: Answer preview format string for MathObjects.

by Davide Cervone -

No, there are no options to control this directly, but you can use a post-filter for the answer checker to adjust the values that are displayed.

For example:

$a = Compute(12.34)->with( correct_ans_latex_string => "\text{The number } 12.34", # The "Correct Answer" column correct_ans => "The number 12.34", # The "Correct Answer" popup ); TEXT($a->ans_rule(5));

ANS($a->cmp->withPostFilter(sub { my$ans = shift;
if (!$ans->{error_message} &&$ans->{preview_text_string}) {
$ans->{student_ans} = "The number$ans->{student_ans}";                           # The "Entered" colomn
$ans->{preview_latex_string} = "\text{The number }$ans->{preview_latex_string}";  # The "Answer Preview" column
$ans->{preview_text_string} = "The number$ans->{preview_text_string}";           # "Answer Preview" Popup
}
return \$ans;
}));

You can, of course, adjust the values to be whatever you want. The test for existence of error_message is so that if there is a syntax error, for example, you won't overwrite the syntax highlighting.