## WeBWorK Problems

### getting a numerical MathObject to display its formula in text ### Re: getting a numerical MathObject to display its formula in text

by Dick Lane -
Number of replies: 0
I want to recant about half-way for the first paragraph (and a bit more for the last).

One list/array of MathObjects can be used, an item selected, and then it alone is put thru the ->{original_formula} filter to get the typeset-able version.  The benefit to programming effort can vary with the structure of the problem.

In a problem about converting rectangular coordinates to spherical, I began with an array of [x,y,z,rho,theta,phi] 6-tuples which were chosen to be "nice", selected one 6-tuple, used its values for answer-checking and put just its items thru the ->{original_formula} filter for use in the problem statement and in a solution.  To offer a bit more variety to students, I used a scale factor for [x,y,z,rho] and discovered that "original formula" is not inherited.  This was easy to fix: just put the scale factor into the computations which produce the array of 6-tuples, e.g., rather than having [sqrt(3),0,1,2,0,pi/4] be extracted from the array and then scale [x,y,z,rho], have [a sqrt(3),0,a,2 a, 0, pi/4] be in the original array (Perl note: of array references).

I would still prefer to have TexString be the default behavior for a Computed object in a texString context, but ->{original_formula} did simplify my example greatly.

technical note about data structure for my example:
@DTA = ( [6-tuple of Computed items] , [another 6-tuple] , ... ) ;
$pick = random( 0 , scalar(@DTA) , 1 ) ; ($x, $y,$z, $rho,$theta, $phi) = @{$DTA[ \$pick ] } ;