In an earlier post sagetex was used to create a problem that said, "Use reference triangles to find the sine/cosine/tangent/etc of the angle x (in degrees)". As I mentioned there, Sage prints out radian angles such as $latex \frac{3\pi}{4}$ so that $latex \pi$ is multiplied by $latex \frac{3}{4}$. You can't just code in $latex \LaTeX$ and insert the numerator or denominator via a Sage command because $latex 0$ and $latex \pi$ aren't fractions. I opted to crunch things out case by case; simple and quick to implement. It gets the job done by referring to the numerators and denominators:

anglesR = [0, pi/6, pi/4, pi/3, pi/2, 2*pi/3, 3*pi/4, 5*pi/6, pi, 7*pi/6, 5*pi/4, 4*pi/3, 3*pi/2,5*pi/3,7*pi/8,11*pi/6]

#Numerators and Denominators of the radian angles

anglesRnum = [0,1, 1, 1, 1, 2, 3, 5, 1, 7, 5, 4, 3,5,7,11]

anglesRden = [1, 6, 4, 3, 2, 3, 4, 6, 1, 6, 4, 3, 2,3,8,6]

Regardless of the angle, it's passed to a function GetTheta that will take the index and return the $latex \LaTeX$ string formatted as a single ratio: $\sin\left(\sage{theta1}\right)$. Here's the GetTheta function; note that the code isn't formatted properly:

def GetTheta(Index):

if Index == 0:

theta = '0'

elif Index == 8:

theta = '\\pi'

elif (Index == 1) or (Index == 2) or (Index == 3) or (Index == 3) or (Index == 8):

theta = '\\frac{\\pi}{'+ str(anglesRden[Index])+'}'

elif (Index == 5):

theta = '\\frac{2\\pi}{'+ str(anglesRden[Index])+'}'

elif (Index == 6) or (Index == 12):

theta = '\\frac{3\\pi}{'+ str(anglesRden[Index])+'}'

elif (Index == 7) or (Index == 10):

theta = '\\frac{5\\pi}{'+ str(anglesRden[Index])+'}'

elif (Index == 9) or (Index == 14):

theta = '\\frac{7\\pi}{'+ str(anglesRden[Index])+'}'

elif (Index == 11):

theta = '\\frac{4\\pi}{'+ str(anglesRden[Index])+'}'

elif (Index == 15):

theta = '\\frac{11\\pi}{'+ str(anglesRden[Index])+'}'

return theta

That's some long, ugly code but as you can see from the screenshot, it works. Note that backslash has to be typed twice to be picked recognized in a regular string (but not a raw string). The full code is posted on the SageTeX: Trigonometry page.