Perhaps a simple revision of line 817 in .../pg/macros/contextFraction.pl would be sufficient to change this.
I think producing merely "\frac..." would suffice because I could still choose between using \( $ratio \) for small format or \(\displaystyle $ratio \) or \[ $ratio \] to get large fractions.
Note: this is separate from (and probably independent of) choosing whether to show negative two divided by three as "\frac{-2}{3}" or "- \, \frac{2}{3}".
$f
is a Fraction object, you can use
$f->with(isHorizontal=>true);to produce a Fraction object that display as
a/b
rather than \frac{a}{b}
in TeX output. It will handle the denominator 1 case properly.
If you want to get the numerator and denominator separately, use
($a,$b) = $f->value;
I think the reason for the \textstyle
is because the fractions produce mixed numbers like 4 1/2 for "four and a half" and 4\frac{1}{2}
in display mode is not correct for that. If you only used text mode for mixed numbers, then 9/2 would display differently from 1/2, which would be inconsistent.
While it is true that as an author, you could choose how you insert the fraction into the problem, you need to remember that the TeX output is used not only for the problem text, but also for the student answers, which (if I remember correctly) are done in display mode. If the default were to be plain \frac{a}{b}
, then all mixed-number student answers would be wrongly formatted. The original motivation for the Fraction context was elementary education problems, where consistency of the format is more critical.
But you are right, there should be more control over the TeX output. There should probably be a parameter to determine the format to use.
Of course, you could subclass the Fraction class and replace its TeX output function. :-)
Davide
Is there something similar to handle exponents in horizontal format but with coefficients in stacked format? E.g., I would like antiderivative of sqrt(x) to have TeX form \frac{2}{3} x^{3/2} rather than \frac{2}{3} x^{\frac{3}{2}}. If the exponent is stacked, then baseline of its denominator is very close to the baseline of x.