# Revision history [back]

Hello, @StevenClontz! I don't know if this solves the general case of your question, but it does solve the particular example your present. Write the following:

def latex_frac(frac):
if frac == 0:    return '0'
num = frac.numerator()
den = frac.denominator()
if den == 1:    return str(num)
return r'\frac{' + str(num) + '}{' + str(den) + '}'


You can then call this functions like this:

latex_frac((2*x+4)/(x^2+1)^2)


which will give the result you want.

I hope this helps!