ASKSAGE: Sage Q&A Forum - Latest question feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Tue, 13 Oct 2020 12:37:51 -0500Can attributes of sage classes be changed?https://ask.sagemath.org/question/53892/can-attributes-of-sage-classes-be-changed/ I want to change the way vectors are rendered in sagetex. For example, consider `v = vector([1, 2, 3])`. In sagetex, the command `$v=\sage{v}$` renders as
$$
v=(1, 2, 3)
$$
Instead, I want my vectors to take the form
$$
v=\left[\begin{array}{rrr}1&2&3\end{array}\right]^\intercal
$$
I thought I could do this by resetting the `_latex_` method of the `sage.modules.free_module_element.FreeModuleElement` class as follows.
def my_vector_latex(self):
return matrix(v)._latex_() + r'^\intercal'
setattr(sage.modules.free_module_element.FreeModuleElement, '_latex_', my_vector_latex)
However, this code throws the following error:
TypeError: can't set attributes of built-in/extension type 'sage.modules.free_module_element.FreeModuleElement'
So, it looks like I can't modify the methods of `FreeModuleElement` in this way. Is there anything else I could do?more_weightTue, 13 Oct 2020 12:37:51 -0500https://ask.sagemath.org/question/53892/Problems with SageTex on MacOShttps://ask.sagemath.org/question/52612/problems-with-sagetex-on-macos/I have follow the instructions according with the sage tutorial guide for install SageTex and for "LaTex to know Sage", to being able to use SageTex on MacOS, but although it's recognize the sage.sty file when I compile a document on each part of sage it displays "??", I have no more ideas what to do, I have use a lot of differents versions of Sage but no one works.emaspWed, 22 Jul 2020 02:01:02 -0500https://ask.sagemath.org/question/52612/SageTeX-Output: Possible simplification soughthttps://ask.sagemath.org/question/49374/sagetex-output-possible-simplification-sought/I created a minimal example for SageTeX:
x = 420 # Denominator
MyRange = 222
M = []
for n in range (1,MyRange):
if x == denominator(n/x):
M.append('$' + latex(n/x).replace(' ','') + '$')
else:
M.append('$' + '\\frac{' + "{}".format(n) + '}{' + "{}".format(x) + '}=' + latex(n/x).replace(' ','') + '$')
MyOut = ', '.join(M)
print(MyOut)
This gives:
![image description](https://matheplanet.de/matheplanet/nuke/html/uploads/b/50970_7_56555555.png)
It works! Just for interest, I wonder: does the 2nd else-output <br>
`M.append('$' + '\\frac{' + "{}".format(n) + '}{' + "{}".format(x) + '}=' + latex(n/x).replace(' ','') + '$')` <br>
really have to be so complicated or is there an easier way?
â‚¬dit: My SageTeX-MWE is:
\documentclass{article}
\usepackage{amsmath, amssymb, amsfonts}
\usepackage{sagetex}
\begin{document}
\section{In}
\begin{sageblock}
x = 420 # Denominator
MyRange = 222
M = []
for n in range (1,MyRange):
if x == denominator(n/x):
M.append('$' + latex(n/x).replace(' ','') + '$')
else:
M.append('$' + '\\frac{' + "{}".format(n) + '}{' + "{}".format(x) + '}=' + latex(n/x).replace(' ','') + '$')
MyOut = ', '.join(M)
#print MyOut
\end{sageblock}
\section{Out}
\baselineskip16pt \sagestr{MyOut}
\end{document}geroyxSun, 05 Jan 2020 09:32:29 -0600https://ask.sagemath.org/question/49374/Sagetex : how to capture sageblock output for future use.https://ask.sagemath.org/question/36422/sagetex-how-to-capture-sageblock-output-for-future-use/[ This is more, I think, a \LaTeX question than a Sagemath question. But since it's centered on the use of Sagetex, it is probably the right place to ask... ]
I'd like to be able to do some (boring but necessary) computation without printing it, use its results, *then*, in an appendix, show the computation (without re-running it).
The obvious solution would be to run the computation in a `sagesilent` block, use its results, then later insert a `sageverbatim` environment with the same code :
\begin{sagesilent}
## Boring computation
\end{sagesilent}
%% Lotsa discussion
\appendix
\begin{sageverbatim}
## Boring computation again
\end{sageverbatim}
The problem is that now, I have two copies of the same code, with no consistency guarantee (as illustrated in the example, BTW).
I tried :
\let\foo={\begin{sageblock}
## boring computation
\end{sageblock}}
% Lotsadiscussion
\appendix
\foo
But that doesn't work : The boring computation is still printed before the discussion and nothing is printed in the appendix.
I'm not really surprised : the \LaTeX `verbatim` environments are full of such traps. And, no, using `\protect` is not enough.
Any idea ?Emmanuel CharpentierWed, 01 Feb 2017 09:41:51 -0600https://ask.sagemath.org/question/36422/LatexMk and sagetex not workinghttps://ask.sagemath.org/question/39455/latexmk-and-sagetex-not-working/ According to the Sagetex github page (https://github.com/sagemath/sagetex/wiki) the following snippet code put into a .latexmkrc dotfile should make latexmk run sagetex.sage files if necessary:
add_cus_dep('sagetex.sage', 'sagetex.sout', 0, 'makesout');
$hash_calc_ignore_pattern{'sage'} = '^( _st_.goboom| ?_st_.current_tex_line|print .SageT)';
sub makesout {
system("sage '$_[0].sagetex.sage'");
}
But nothing seems to happen, when I run latexmk on the tex file, it gives no errors and does not run the sagetex.sage file, but compiles the pdf nontheless. If I run latexmk and sage manually I have no problems compiling the document with the sage math. Is the code outdated/can it be fixed to work properly?PoetastropheWed, 08 Nov 2017 13:48:45 -0600https://ask.sagemath.org/question/39455/Does sagetex require math environment around \sage{}?https://ask.sagemath.org/question/34713/does-sagetex-require-math-environment-around-sage/I have problems in typesetting the sagetex example file example.tex with the sage engine in TeXShop 3.71. Namely, the output of the command \sage{pascals_triangle(n)} near the end is a string containing LaTeX code, which should then be processed as LaTeX input by LaTeX. However, the typesetter complains that the $$ around the sage output are missing. Putting them results in the string be reproduced verbatim in the output, which is not the expected behavior. I checked that at least in my current version of sagetex.sty ALL output of \sage{} is expected to be placed in a math environment, otherwise a LaTeX error is raised. In the documentation, it is mentioned that it is useful, but not generally required, to put \sage{} commands in a math environment. I remember that the file was smoothly typeset a year or two ago. Has anything changed in the meantime?qwfwqSun, 04 Sep 2016 06:53:11 -0500https://ask.sagemath.org/question/34713/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 10:05:53 -0600https://ask.sagemath.org/question/31414/Sagetex on Windows: Using miktex and sage on virtualbox. How to make it work?https://ask.sagemath.org/question/27264/sagetex-on-windows-using-miktex-and-sage-on-virtualbox-how-to-make-it-work/ Hello!
I've installed sagetex (2009-06-26) using the miktex package manager. I use Sage 6.7 on Oracle's Virtual Box, as recommended for windows users.
For me, the following code:
> \documentclass{article}
> \usepackage{sagetex}
>
> \begin{document}
>
> For example, there are
> $\sage{number_of_partitions(1269)}$
> integer partitions of $1269$.
>
> \end{document}
Gives this output:
> For example, there are ?? integer partitions of 1269.
All the sage commands just give "??" in the latex document. I've been looking at the documentation, but it doesn't seem to be for windows.
- Is sagetex supposed to work out of the box, just installing it on miktex and having sage installed on virtualbox?
- If not, is there an official procedure to make it work? e.g. documentation about sagetex on windows?
Thanks! eodMon, 06 Jul 2015 09:41:20 -0500https://ask.sagemath.org/question/27264/How to join function to grid scale?https://ask.sagemath.org/question/25639/how-to-join-function-to-grid-scale/ Dear friends, I'm trying to use latex+sagetex+tikz and it's really powerfull combination. But I don't understand how to join axes grid to function. If you see attached example you see first original plotting then another two with different axes grids. But function plot in 2,3 graphs the same as in first function plot! It should to stretch/collapse in accord with scale x/y axes. How to do it right way?
Update: I don't know why I can't to add .tex file so you can get this example from http://www.highschoolmathandchess.com/latex/plotting-with-sagetex/ (section "Sagetex and the tkz-fct package"). Changing axes doesn't affect to function plot. y023rusThu, 29 Jan 2015 13:48:04 -0600https://ask.sagemath.org/question/25639/tex distribution doesn't see sagetexhttps://ask.sagemath.org/question/10716/tex-distribution-doesnt-see-sagetex/Hi all,
So I've spent some time installing sage 5.12 on my machine (Ubuntu 12.04.3) and been trying to edit a latex document using sagetex that worked fine on another computer. I've found that despite copying
> SAGE_ROOT/sage/local/share/texmf/tex/
to
> /usr/local/share/texmf/
and running
> sudo texhash
I get a compile error. To be clear, I have a single sagesilent block and a single sagestr{} block, and the document compiles on my other machine. I have found that simply copying 'sagetex.sty' into the document directory will work, but this is not the permanent solution I was hoping for. I'm really confused because both my machines are running the same linux OS, so there should really be no difference between them. Any thoughts?
ThanksunderchemistSat, 09 Nov 2013 02:36:58 -0600https://ask.sagemath.org/question/10716/LaTeX, sagetex, Sagehttps://ask.sagemath.org/question/10649/latex-sagetex-sage/Hi there,
I'm new to Sage and new to the forum. I'm using MiKTex 29, the editor is Texmaker on a Win7 PC, Sage as 5.11 in VirtualBox. The .latexmkrc has been changed as advised here:
[Changing .latexmkrc when using Texmaker](https://bitbucket.org/ddrake/sagetex/wiki/UsingSageTeX)
The sagetex which is used by Sage and pdflatex are of the same version. Everything should do just fine, except it doesn't.
Using the example.tex given in the sagetex directory, I compile it with TeX and get example.sagetex.sage. Everything fine there.
Running it in Sage works quite well, too. Sage says, it's plotting and doing and so on. Then it comes to a point, where Sage says:
"[Errno 2] No sich file or directory: 'example.sagetex.sage'".
And the process breaks.
Here my question: Sage processes the example.sagetex.sage file in the given directory. Then it says "file not found / file not there". Both of the prompts seem to exclude eachother fairly well. But I get them anyway.
What am I doing wrong?
Regards.
H.HoedTue, 22 Oct 2013 23:11:58 -0500https://ask.sagemath.org/question/10649/implementing sagetex in latexhttps://ask.sagemath.org/question/8098/implementing-sagetex-in-latex/For calling SAGE from within LATEX-file there must be following
entry in line 1:
% !TEX TS-program = sage // (this creates undersome conditions I dont know a syntax error)
...
and
\usepackage{sagetex}
But I get in one tex-file a syntax error in Line 1.
Does anyone know a work around or how it really works?
Many thanks in advance for your hints.
GeraldpechocSun, 01 May 2011 06:22:00 -0500https://ask.sagemath.org/question/8098/SageTeX doesn't workhttps://ask.sagemath.org/question/9669/sagetex-doesnt-work/I'm using AUCTeX as my TeX editor. I created a TeX file loaded with SageTeX. When I run LaTeX on it I get the message that there are unresolved references. The output has question marks on the places I have put \sage. However, it seems to understand without any trouble the sageblock environment.
When I load the corresponding .sage file on Sage, I get at the following message:
VersionError: versions of .sty and .py files do not match.
stexample.sagetex.sage was generated by sagetex.sty version "None", but
is being processed by sagetex.py version "2012/01/16 v2.3.3-69dcb0eb93de".
Please make sure that TeX is using the sagetex.sty
from your current version of Sage; see
http://www.sagemath.org/doc/installation/sagetex.html.
I thought I had followed the instructions on the "Make SageTeX Known to TeX" section of the Sage installation guide but it's not working.
jdiosesMon, 31 Dec 2012 12:42:41 -0600https://ask.sagemath.org/question/9669/Sagetex from the notebook - feedback on how I automate thingshttps://ask.sagemath.org/question/8928/sagetex-from-the-notebook-feedback-on-how-i-automate-things/This isn't really a question, so please accept my apologies if non-questions are unwelcome here.
I am using sage with latex, but I am the kind of person who doesn't like leaving the notebook, so I tried to automate the process. You can see my code below. Any comments and suggestions are appreciated.
Also, if you think you will find this or a similar setup useful, please say so, because people who like staying within the notebook are probably underrepresented among the developers.
def load_cache(f): # so that we don't recompute for every latex change
try:f.cache=load(DATA+"/cache/"+f.f.func_name)
except IOError:pass
def export_code (list_of_functions, folder): # copy code to our latex folder
for func in list_of_functions:
try:
save(func.cache,DATA+"/cache/"+func.f.func_name)
func=func.f
except AttributeError:pass # in case the function isn't cached
sh.eval("cp " + func.func_code.co_filename + " " + folder + "/" + func.func_name + ".py")
def runsagelatex(latexfile):
def evalindir(cmd,path): # otherwise the output appears in the current directory
sh.eval("( cd "+os.path.dirname(path)+" ; "+cmd+" )")
evalindir("pdflatex --file-line-error "+latexfile,latexfile)
evalindir("sage "+os.path.splitext(latexfile)[0]+".sagetex.sage",latexfile)
evalindir("pdflatex --file-line-error "+latexfile,latexfile)
def sagelatex(name="project",export=[],cmd=""):
html(r'<div class="notruncate">') # for the output of pdflatex
try:os.mkdir(DATA+"/cache/")
except OSError:pass
try:os.mkdir(DATA+"/sagelatex/")
except OSError:pass
try:os.mkdir(DATA+"/sagelatex/sagenb-export/")
except OSError:pass
export_code(export,DATA+"/sagelatex/sagenb-export/")
f=open(DATA+"/sagelatex/"+name+".tex","wb")
f.write(cmd)
f.close()
runsagelatex(DATA+"/sagelatex/"+name+".tex")
html(r'</div>')
Example usage:
def f1(a,b):
return a+b
@cached_function
def f2(a):
return a^2
load_cache(f2)
And in a new cell (and change DATA below):
sagelatex(name="myproject",export=[f1,f2,load_cache],cmd=\
r"""
\documentclass{article}
\usepackage{sagetex}
\begin{document}
\begin{sagesilent}
DATA="/.../.sage/sage_notebook.sagenb/home/user/123/data/" # make it match the worksheet's DATA constant
execfile("sagenb-export/load_cache.py")
execfile("sagenb-export/f1.py")
execfile("sagenb-export/f2.py")
\end{sagesilent}
$\sage{f1(1,2)+f2(10)}$
\end{document}
""")
This should produce a pdf file in your DATA/sagelatex folder. That folder is accessible through your web browser.Tom DorrisWed, 25 Apr 2012 09:20:52 -0500https://ask.sagemath.org/question/8928/How do I change the default latex output of a vector?https://ask.sagemath.org/question/8107/how-do-i-change-the-default-latex-output-of-a-vector/I want a vector v=vector([1,2,3]) to be diplayed in sagetex as (1|2|3) an not as (1,2,3).
v=var('v',latex_name=latex(v).replace(',', '|')) does not work.Georg DammSun, 08 May 2011 02:21:01 -0500https://ask.sagemath.org/question/8107/