# In Sage Math, which command do I use to get the LaTeX of my input?

For example, if my input equation is latex(integrate(z^4, z)) the result is \frac{1}{5} \, z^{5}. Not what I want. I want the result to be \int z^4 \, dz, which is the LaTeX of the Input, not calculated.

Same thing for latex(diff(x^4, x)) ....

edit retag close merge delete

( 2023-05-04 14:10:05 +0200 )edit

Sort by ยป oldest newest most voted

Symbolic expressions in Sage tend to be computed to some extent.

Sometimes we can hold off this computation with a "hold" keyword.

The integrate function, in particular, does support that keyword.

Example.

Sage and Python versions used for this example:

sage: print("{}, Python {}.{}.{}".format(version(), *sys.version_info[:3]))
SageMath version 9.8, Release Date: 2023-02-11, Python 3.10.8


Define a symbolic variable:

sage: z = SR.var('z')


The integral is computed before being latexed...

sage: latex(integrate(z^4, z))
\frac{1}{5} \, z^{5}


... unless we hold off the computation:

sage: latex(integrate(z^4, z, hold=True))
\int z^{4}\,{d z}


We can use an equation with both forms:

sage: latex(integrate(z^4, z, hold=True) == integrate(z^4, z))
\int z^{4}\,{d z} = \frac{1}{5} \, z^{5}


Or, giving the held integral a name:

sage: a = integrate(z^4, z, hold=True)

sage: a
integrate(z^4, z)
sage: a.unhold()
1/5*z^5

sage: latex(a == a.unhold())
\int z^{4}\,{d z} = \frac{1}{5} \, z^{5}

more