Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Converting sage output into static latex function

Hello!

I want to be able to use sagetex to do some work in sage, and then create a latex function with the result of that sage work, but without calling sage every time the function is called.

Here is an example of the current pseudo-code

\begin{sagesilent}
func1 = x - 3
func2 = x + 1
f = expand(func1*func2)
\end{sagesilent}

\newcommand{\foo}{\sage{f}}

Here, what would normally happen is sage silent runs sage, and creates the correct f = x^2 - 2x - 3. Then every time \foo is called, it reruns an instance of sage to go locate the definition of f in the sage file, and then sage will spit out the definition in text to \foo which then will display f. This is taking a lot of compute time unnecessarily, and when things get randomized it all goes to hell.

Is there any way to force a command to take in the (sage) definition when it's defined, and then save that definition as straight up text so that I don't have to rerun sage to go find the definition of f every time I want to call \foo?

Converting sage output into static latex function

Hello!

I want to be able to use sagetex to do some work in sage, and then create a latex function with the result of that sage work, but without calling sage every time the function is called.

Here is an example of the current pseudo-code

\begin{sagesilent}
func1 = x - 3
func2 = x + 1
f = expand(func1*func2)
\end{sagesilent}

\newcommand{\foo}{\sage{f}}

Here, what would normally happen is sage silent runs sage, and creates the correct f = x^2 - 2x - 3. Then every time \foo is called, it reruns an instance of sage to go locate the definition of f in the sage file, and then sage will spit out the definition in text to \foo which then will display f. This is taking a lot of compute time unnecessarily, and when things get randomized it all goes to hell.

Is there any way to force a command to take in the (sage) definition when it's defined, and then save that definition as straight up text so that I don't have to rerun sage to go find the definition of f every time I want to call \foo?

Edit: It seems this could be accomplished if there is a way to define a latex command inside the sagesilent environment? From reading the sage doc it seems that this should be possible (there are examples doing it from a sage prompt) but I can't seem to figure out the correct syntax. Suggestions?