## WeBWorK Problems

### Presenting fractions nicely

by Gregory Varner -
Number of replies: 2

While I have had some workarounds where you define the fraction and then pass it into a formula as a real, I am wondering if there is an easier to to get a fraction to display correctly in a problem.

The text that I have is

TEXT(beginproblem());

Context("Fraction");

$a = Compute("-5/2");$b = 1;
$c = 4;$d = 2;
$e = 1;$f = 13;

$lhs1=nicestring([$a,$b],['x','y']);$lhs2=nicestring([$d,$e],['x','y']);
BEGIN_TEXT

Graph the region of feasibility. List each corner/vertex point (answers should be given exactly, but order does not matter).

$lhs1 \leq 4 \quad \text{or} \quad lhs2 >f$

However, the fraction appears as (-5/2) instead of as a displayed fraction.

Thank you

(This is probably a stupid question, but I am still working through how to combine contexts to get things to display correctly.)

Tags:

### Re: Presenting fractions nicely

by Alex Jordan -

Hi Gregory,

What you are seeing is the Fraction math object's string representation, not it's TeX representation. Before you enter the TEXT area, you could set:

Context()->texStrings;

So that math objects will be represented by their TeX representation.

I might also suggest moving away from TEXT and using PGML. If you use PGML, there is no need to set the TeX string representation because PGML is aware of when a math object is inside math content. So you TEXT block would be:

BEGIN_PGML

Graph the region of feasibility. List each corner/vertex point (answers should be given exactly, but order does not matter).

[[$lhs1]\leq4\quad\text{or}\quad[$lhs2]\leq[\$f]]

END_PGML

You need to load the PGML.pl macro library for this. The [...] is creating centered display mode math. Then each variable is wrapped in [...] for substitution. More about PGML is here: https://webwork.maa.org/wiki/Introduction_to_PGML