WeBWorK Problems

How to get showExtraParens to make the string method show them.

How to get showExtraParens to make the string method show them.

by Jaimos Skriletz -
Number of replies: 1

I want to make the string output of a MathObject "painfully unambiguous". Goal is to have formulas like "-x^2" produce "-(x^2)" instead. This seems it can be done by setting showExtraParens => 2 in the context. I've tried two approaches:

$MO->context->flags->(showExtraParens => 2);
$MO->string;

And I've tried:

$MO->context->flags->(showExtraParens => 2);
$newMO = Value->Package('Formula')->new($MO->context, $MO->string);
$newMO->string;

In both cases I was hoping for more parenthesis in the string output, but for simple functions like "-x^2", but I have noticed no difference.

In reply to Jaimos Skriletz

Re: How to get showExtraParens to make the string method show them.

by Jaimos Skriletz -
Never mind, I just had a typo, but this was nested in other code that I didn't notice any warning from it (unsure why). But the first option does work if I type it correctly.

$MO->context->flags->set(showExtraParens => 2);
$MO->string;