WeBWorK Problems

Asterisk appears in Compute( "$a x " )->reduce; HOW TO GET RID OF IT?

Asterisk appears in Compute( "$a x " )->reduce; HOW TO GET RID OF IT?

by Aba Mbirika -
Number of replies: 3
When I create a quadratic function like:
$f = Compute( "x^2 + $a x + b" )->reduce;

Then if $a is randomly chosen to be 3, for instance, the quadratic appears on the screen as:
x2+3 * x+b

Instead, I would like it to appear as:
x2+3x+b

Is it possible to remove the asterisk?

Thanks much,
aBa
In reply to Aba Mbirika

Re: Asterisk appears in Compute( "$a x " )->reduce; HOW TO GET RID OF IT?

by Alex Jordan -
If you are using the BEGIN_TEXT...END_TEXT environment to display the problem and the Math Objects, then you need to precede it all with Context()->texStrings; and end it with Context()->normalStrings; My first guess would be that this is the issue.
Context()->texStrings;
BEGIN_TEXT
...
END_TEXT
Context()->normalStrings;

See if this fixes things for you.

In reply to Alex Jordan

Re: Asterisk appears in Compute( "$a x " )->reduce; HOW TO GET RID OF IT?

by Aba Mbirika -
Thanks Alex. That absolutely fixed the problem. I am new-ish at authoring problems, so I take much content from the NPL. The one I "lifted" has

TEXT(EV3(<<'EOT'));

EOT

So indeed this is old code. Thanks for the tip. And have a nice day!

Shalom,
aBa
In reply to Aba Mbirika

Re: Asterisk appears in Compute( "$a x " )->reduce; HOW TO GET RID OF IT?

by Alex Jordan -
I believe that BEGIN_TEXT and END_TEXT are just easier-to-read replacements for TEXT(EV3(<<'EOT')); and EOT. You should also be able to put Context()->texStrings and Context()->normalStrings before and after these commands.

To explain a little what is happening here, suppose $f=Formula("x/3"). Then $f is a complex hash of information, including how to represent $f as a string for say other math objects, as well as how to represent it as a string to be processed with tex.

By default, Context()->normalStrings is in place, and if you had $g=Formula("$f+1");, then $f is replaced with x/3, and you have something equivalent to $g=Formula("x/3+1");. But for display to students, you want $f to come out as \frac{x}{3}. Setting Context()->texStrings makes this happen.

Lastly you go back to Context()->normalStrings, because if you now used $g=Formula("$f+1");, you'd get an error from $g=Formula("\frac{x}{3}+1").

I've used this example with division to reveal a big difference between the two modes. But in general, "normal" strings and "tex" strings are just different.