I am writing a question where I want to display the values \( \sin(\theta) \) and \( \cos(\theta) \) as fractions, so students are able to identify the representative angle that they are coming from.

I am using the Fractions Context, but I do not succeed after evaluating the functions. A sample code can be found below. As you notice, I tried several formats but I get displayed either "0.5" or " \( \sin(\pi/6) \)" for example. Is there a way to achieve this without using arrays to have the fractions stored? I want to avoid this approach as I would like to randomize the angle to either \( \pm k \frac{\pi}{6} \) or \( \pm k \frac{\pi}{4} \).

Thanks in advance!

DOCUMENT();

loadMacros(

"PGstandard.pl",

"MathObjects.pl",

"PGcourse.pl",

"PGML.pl",

"parserPopUp.pl",

"PGchoicemacros.pl",

"contextFraction.pl",

);

TEXT(beginproblem());

$showPartialCorrectAnswers = 1;

Context("Fraction-NoDecimals");

$theta = list_random(Formula("0"),Formula("pi/6"), Formula("pi/4"), Formula("pi/3"), Formula("pi/2"));

$a11 = Compute(cos($theta));

$a12 = -sin($theta);

$a21 = Formula(sin($theta));

$a22 = Formula(cos($theta));

Context()->texStrings;

BEGIN_PGML

The following matrix is the rotation matrix with angle [`\theta = [$theta] `].

[` \begin{bmatrix}

[$a11] & [$a12] \\

[$a21] & [$a22]

\end{bmatrix}

`]

END_PGML

ENDDOCUMENT();