Ask Your Question
1

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

asked 2 years ago

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

Preview: (hide)

Comments

Welcome to Ask Sage! Thank you for your question!

slelievre gravatar imageslelievre ( 2 years ago )

1 Answer

Sort by » oldest newest most voted
2

answered 2 years ago

slelievre gravatar image

updated 2 years ago

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}
Preview: (hide)
link

Your Answer

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

Add Answer

Question Tools

Stats

Asked: 2 years ago

Seen: 562 times

Last updated: May 04 '23