## WeBWorK Main Forum

by Sean Fitzpatrick -
Number of replies: 3

This seems really basic, but I haven't found a good solution.

Let's say I have a calculus problem where the answer is 2*sqrt(2). (I do, and it's an arc length problem, but I digress.)

I would like the answer reported by WeBWorK to display as $$2\sqrt{2}$$, and not as a decimal. The problem is part of a PreTeXt book, and the answers reported by WeBWorK become the answers in the back. I can manually override the answer from WeBWorK, but only if I don't randomize the question.

I know that I can get the answer display I want using the limited radical context. But I also want students to be able to answer sqrt(8) and have it marked correct.

So maybe this is unusual in that I don't care how the answer is entered by students; what matters to me is how the answer is displayed when WeBWorK reports back the correct answer. Is there a way to accomplish this?

by Sean Fitzpatrick -
Update: I found code that works in an old problem. The code itself is apparently 13 year old code from Davide Cervonne.
The OPL problem at Library/NewHampshire/unh_schoolib/Square_Root/sqrnne401.pg contains a subroutine for square roots that seems to do the job.

But I remain open to simpler solutions!
If you use Compute() to create your answer object (e.g. $correct = Compute("2sqrt(2)");) then the correct answer latex string (which is displayed when using "Show Correct Answers") will be set to display the answer as provided. However, keep in mind that using the MathObject "$correct" in a string (or in PGML) will still most likely display as a decimal value (this can be worked around by defining $correct to be a Formula object specifically while the context is set to reduceConstantFunctions => 0). In reply to Andrew Parker ### Re: Display radical in answer without contextLimitedRadical? by Danny Glin - You can also manually set the correct answer latex string for a MathObject. For example:$ans->{correct_ans_latex_string} = "2\sqrt{2}";
1. Variables will be interpolated (so you could do $ans->{correct_ans_latex_string} = "2\sqrt{$a}";), but no further processing will be done on the string.