## WeBWorK Problems

### MathObject List answers are displaying the value, not the name, of items in the list ### MathObject List answers are displaying the value, not the name, of items in the list

by Paul Pearson -
Number of replies: 4
Hi everyone,

When an answer is a MathObject List and the items in the list are named constants, is there a way to get the correct answer displayed in terms of the names for the constants, rather than the values of the constants?

Related question: If I create a MathObject List $G, is there a way for me to get the input string for that list? None of these four methods seems to return the input string from the list$G (see attached file for more context)

$G->value; # this has the matrices pretty_print($G->data); # a reference to a perl array of the matrices that gets displayed using pretty_print()

$G->TeX; # this has a TeX version of the matrices$G->string; # this has the matrices

I'm thinking that for my purposes (using Lists to do answer checking for a table) I will need to write some custom answer checkers with pre- and post-filters that control how the entered answer, answer preview, answer, and correct answer are displayed to the student.  Because the correct answer is getting displayed by value rather than by name, I was looking for some way to display the input string to the List (which is by name, not value).

Thanks!

Paul Pearson ### Re: MathObject List answers are displaying the value, not the name, of items in the list

by Davide Cervone -

Use

$G = Compute("e, a, a^2");  rather than $G = List("e, a, a^2");


The Compute() function arranges for the correct answer to be the parsed version of the answer. ### Re: MathObject List answers are displaying the value, not the name, of items in the list

by Paul Pearson -
Thanks, Davide. I should've realized that on my own. If $G = Compute("e,a,a^2") then is there any method$G->some_method() that will return the parsed version of the answer (i.e., the input string)? ### Re: MathObject List answers are displaying the value, not the name, of items in the list

by Paul Pearson -
You can disregard my last question. I can probably get the string I want from the answer hash.

Thanks!
Paul You can use $G->{correct_ans} for the string, $G->{correct_ans_latex_string} for the TeX version, or \$G->{original_formula} for the Formula() object for the expression.