ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Mon, 28 Nov 2016 20:00:55 +0100'object is not callable' error in sagetex (that doesn't occur in a worksheet)https://ask.sagemath.org/question/35766/object-is-not-callable-error-in-sagetex-that-doesnt-occur-in-a-worksheet/I'm generating random numbers to be presented in scientific notation for a quiz I'm typing. In testing this code works fine in a worksheet, but gives an error in a sagesilent block of my .tex document. Here's the code:
sci = {}
for index in range(1, 14): # Picks random coeffs for sci not.
places = ZZ.random_element(0, 4)
sci["co{0}".format(index)] = round(10*random(), places)
powe = {}
for index in range(1, 14): # Picks random powers for use.
powe["r{0}".format(index)] = ZZ.random_element(5, 10)
sci['co1']
sci['co2']
powe['r1']
powe['r2']
In the worksheet, those last four lines generate output like
3.0
5.566
7
8
But when I use that same code in the .tex document (without the last four lines), Sage returns this error before I can even call my numbers:
'module' object is not callable
My best guess is that rounding needs some package that the worksheet imports automatically but sagetex does not, but I'm afraid I don't know enough about what's really going on. Thank you for any help!mathochistMon, 28 Nov 2016 20:00:55 +0100https://ask.sagemath.org/question/35766/Converting sage output into static latex functionhttps://ask.sagemath.org/question/31414/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?Jason021Tue, 08 Dec 2015 17:05:53 +0100https://ask.sagemath.org/question/31414/