$a = Fraction(5,2);
$b = Fraction(-6,3);
$f = Compute("$a*x+$b");
Then in output such as \( f(x)=$f \), there are extra set of parentheses around the $b term (as the fraction is reduced).
If I use nicestring to perform output, such as
$g = nicestring([$a,$b]);
The output such as \( f(x)= $g\), has the fraction written in a linear form as 5/2x-2, which students will see as the x in the denominator.
I can live with the first output (with the extra parentheses), however, I prefer to have output in standard form as I would write it down.
Peter
This is usually the correct thing to do when converting a MathObject to a string, but there is an important case where that is the wrong thing to do. It is when the MathObject is used in math mode within a BEGIN_TEXT/END_TEXT block, as in your case above. In that case, you would want the MathObject to produce its TeX version instead. That could be done using the rather verbose \( f(x) = \{$f->TeX\} \) construct, but there is an easier way.
If you use the command
Context()->texStrings;before the BEGIN_TEXT and
Context()->normalStrings;after the END_TEXT that will cause the \( f(x) = $f \) to work as you probably intend.
Hope that helps.
Davide
Context()->texStrings; Context()->normalStrings;in the appropriate places. After some additional playing I understand this a bit better, but can't get precisely what I'd like. For example if I use "contextFraction.pl" and have:
$c=Fraction(1,3);
$d=Fraction(-2,3);
$g=Compute("$c*x+$d");
Then \( y=$g\)produces nice output as intended, however if the Fraction reduces to an integer (and negative) such as:
$c=Fraction(1,3);
$d=Fraction(-6,3);
$g=Compute("$c*x+$d");
(which sometimes occurs with random numerators), then the output \( y=$g \) looks like y=(1/3)x+(-2) [except that the 1/3 is like \frac{1}{3}. ] And I would like to see it as y=(1/3)x-2.
If instead, I replace $d with -2, such as:
$c=Fraction(1,3);
$d=-2;
$g=Compute("$c*x+$d");
Then the result is the same as the 2nd case, so it appears that Fraction(-6,3) reduces to the integer -2, however, the TeX output with the integer (-2) is not formatted nicely.
To improve the formatting for linear functions (and polynomial), I generally use the nicestring function, however this strips TeX formatting out of fractions it appears. I've tried various combinations with nicestring, but to no avail.
Peter
$g = Compute("$c*x+$d")->reduce;in order to turn the x+-2 into x-2.
At least that is what is supposed to happen. It turns out that there were problems with reduce() in the Fraction contexts, but I have fixed them. You will need to get the lasted version of contextFraction.pl in order to have reduce() work as expected.
Let me know if that doesn't work for you.
Davide
I just upgraded Webwork via CVS (from the server at rochester), although I don't think that gave me a new version. The date-stamp seems to be 2009-06-25. Did you just change something in the past few days? Do you add a date-change or a version inside the file? I couldn't find anything.
Also, when I run the version I have there seems to be a problem when I change the line:
$g=Compute("$c*x+$d");
to
$g=Compute("$c*x+$d")->reduce;
in that the webserver just stalls out. (Once I think I got an error about an infinite loop, but I can't seem to replicate it.)
Peter
You need to get the latest HEAD version, but you probably just got the rel-2-4-7 version. Try
cvs update -A contextFraction.pland see if that doesn't do it for you.
Davide
I have a new version now. At least, I think so, the time-stamp is 8/04 (today, when I updated). The previous version I had was in June.
It still seems to in a infinite loop. Again the lines of code that are doing it are:
$c = Fraction(1,3)
$d = -2;
$g = Compute("$c*x+$d")->reduce;
If I don't apply "reduce", then there are no problems.
Peter
cvs status contextFractions.pland see what version you have. It should be 1.7, but I suspect you have an earlier one. If you do, try
cvs update -r HEAD contextFraction.plto get the latest version.
Davide
It looks like I have the current version (1.7). I actually updated to the current version of everything in pg directory (I don't know if this could be an issue--If you think so I could revert back to the 2.4.7 release).
Are there other packages that contextFraction.pl depends on? I'm guessing mathObjects.pl, which is version 1.10.
Peter
It still sounds to me like the old version is in place.
If you are sure it's not, then can you send the pg file and the seed that you are using and I'll test with that.
Davide