## WeBWorK Main Forum

### TeX in graphs

by joel robbin -
Number of replies: 4
The code

$graph_object->lb( new Label($xmin+0.1,0.05,'x','black','left','center'));

inserts the label x at the indicated point on the graph.
Can I insert a TeX label (like $$\frac{\pi}{2}$$ in place of 'x'?

### Re: TeX in graphs

by Michael Gage -
Not directly but something like

$pi_label = EV3("$$\frac{\pi}{2}$$");$graph_object->lb( new Label($xmin+0.1,0.05,$pi_label,'black','left','center'));

might work (I haven't had a chance to test it.)

The EV3() subroutine is the one that translates Tex and other things in
the BEGIN_TEXT/END_TEXT blocks.

(see the problem text for details)

### Re: TeX in graphs

by joel robbin -
I tried your suggestion and am getting wierd behavior.
The graph image isn't changing. Even when I remove
the label command or change the label to something like
'*', the old label is drawn. It is as if the image is stored
permanantly somewhere on the disk and is oblivious to
changes in my code.

Here is my code:

$graph_object = init_graph(-2, -6, 2, 6, 'axes' => [0,0], 'grid' => [4,12], 'pixels' => [400,600]);$g= sub{my $x=shift(); return$x**3;};
$fn=new Fun($g,$graph_object);$p=1.570795;
$graph_object->moveTo(-$p,0);
$graph_object->lineTo(-$p,-$p**3);$graph_object->stamps( closed_circle(-$p,-$p**3,'blue') );
$graph_object->lb( new Label(-$p+0.15,-$p**3,'P', 'black','left','center'));$pi_label = EV3("$$-\pi/2$$");
$graph_object->lb( new Label($p,0.05,$pi_label,'black','left','center')); ############################ TEXT(beginproblem()); BEGIN_TEXT Here is the graph of the function $$g(x)=x^3$$ problem 3.2.2 in your textbook (p180).$BR
\{ image( insertGraph($graph_object) ) \} (Click on the image to enlarge it.)$BR
Specify
the $$y$$-coordinate of the point $$P$$ on the given function. Give
an exact expression and also a calculator approximation rounded to three
decimal places. In the graph I put -pi/2 instead of $$-\frac{\pi}{2}$$;
Remember that $$\pi=3.14159\ldots$$.

$PAR $$\hspace{.25in} \mbox{Exact value } =$$ \{ ans_rule{20} \}$PAR

$$\hspace{.25in} \mbox{Value to 3dp } =$$ \{ ans_rule{20} \}

$BR$BR

END_TEXT

############################

Context("LimitedNumeric");
loadMacros("fixedPrecision.pl"); # must come after Context is set.

$y = "-pi**3/8";$n = FixedPrecision(3.876);

ANS(num_cmp($y)); ANS(num_cmp(-3.876)); ############################ if ($showHints) {
}

if ($showSols) {$twoinc = 2 * $inc;$incsquared = $inc**2; SOLUTION(EV3(<<'EOT'));$BR <B>Solution</B>:
The $$x$$ coordinate of $$P$$ is $$-\pi/2$$ and $$P$$ lies
on the graph of $$g(x) = x^3$$, so the $$y$$ coordinate of
$$P$$ must be $$y = (-\pi/2)^3 = -\pi^3/8 \simeq -3.876$$.
EOT
}

ENDDOCUMENT();

### Re: TeX in graphs

by joel robbin -
Disregard my last response. This is apparently
a bug in the browser. When I sign off and on, normal
behavior resumes. However, the code didn't work. y

### Re: TeX in graphs

by Michael Gage -
Hi Joel,

Make sure that you use "shift reload" on your browser to make sure that the image is not being cached by
your browser. Having said that -- yes the image is also likely
cached on the machine as well. There is some effort made to insure that this image
is "current" but since you are doing something a bit outside the standard box
it's possible that in this case the refresh isn't behaving properly. It would take some experimenting
to figure out exactly what the problem is.

Take care,

Mike