Ask Your Question

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

asked 2023-04-20 04:04:25 +0200

Hellwood gravatar image

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 flag offensive close merge delete


Welcome to Ask Sage! Thank you for your question!

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

1 Answer

Sort by ยป oldest newest most voted

answered 2023-05-04 14:06:46 +0200

slelievre gravatar image

updated 2023-05-04 22:27:16 +0200

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.


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()

sage: latex(a == a.unhold())
\int z^{4}\,{d z} = \frac{1}{5} \, z^{5}
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools


Asked: 2023-04-20 02:07:16 +0200

Seen: 459 times

Last updated: May 04 '23