Ask Your Question

Revision history [back]

Since you can do x.mul(1/x, hold=True), you can also do latex(x.mul(1/x, hold=True)).

I suppose you could also write the expression using LaTeX:

sage: LatexExpr(r"\frac{%s}{%s}" % (latex(x), latex(x)))
\frac{x}{x}
sage: LatexExpr(r"\frac{%s}{%s}" % (latex(factor(x^2+3*x + 2)), latex(x)))
\frac{{\left(x + 1\right)} {\left(x + 2\right)}}{x}

But in general, latex(foo) first computes foo, which means that typically it will get simplified, and then it computes its LaTeX representation. So I don't think there is a simple way to do what you want.