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/Can sagetex generate tex files?https://ask.sagemath.org/question/53227/can-sagetex-generate-tex-files/I'm writing a latex document that will eventually need to be compiled on a machine that does not have sage on it. However, right now I'm using sagetex to write this document. I'm curious if it is somehow possible to generate a latex document with all of the \sage invocations replaced with the corresponding latex code. done_with_fishMon, 31 Aug 2020 01:58:58 -0500https://ask.sagemath.org/question/53227/sagetex linebreakhttps://ask.sagemath.org/question/53064/sagetex-linebreak/When using the environment sagecommandline of sagetex with long number output, how can I get automatic line breaks? I already tried to change sagetex.sty (putting breaklines=true at several places), but nothing changed. Here is my minimal example: (p.s. I asked the same question also on tex.stackexchange)
\documentclass[
a6paper, 11pt, oneside,
english,ngerman]{scrartcl}
% !TEX TS-program = sage
% !TEX encoding = UTF-8 Unicode
\usepackage[headsep=0cm,footskip=1.5em,includeheadfoot=true,
top=0cm,bottom=0cm,left=.5cm,right=.5cm,]{geometry}
\usepackage{sagetex}
\lstdefinestyle{SageOutput}{style=DefaultSageOutput,breaklines=true}
\begin{document}
\begin{sagecommandline}
sage: factorial(100)+1
sage: factorial(50)+1
sage: factorial(10)
\end{sagecommandline}
\end{document}
dantetanteSun, 16 Aug 2020 07:11:31 -0500https://ask.sagemath.org/question/53064/Configuring an arara rule of sagetex on Windows 10https://ask.sagemath.org/question/52840/configuring-an-arara-rule-of-sagetex-on-windows-10/ This question has been cross-posted on tex.sx here https://tex[dot]stackexchange[dot]com/q/557131/2288.
----------
When using the following `sagetex.yaml` arara rule
!config
# SageTeX-Rule for arara.
identifier: sagetex
name: SageTeX
authors:
- TeXnician (Author)
- cis (Idea)
arguments: []
commands:
- name: A SageTeX Rule for arara
command: >
@{
pathToBashExecutive = "C:\\Program Files\\SageMath 9.1\\runtime\\bin\\bash";
pathToSageStartfile = "C:/Program Files/SageMath 9.1/runtime/opt/sagemath-9.1/sage";
pathOfCurrentWorkingFolder = currentFile().getParent();
theWindowsCommand = getCommand(pathToBashExecutive, "-l", pathToSageStartfile, "-c", "os.chdir('" + pathOfCurrentWorkingFolder + "'); load('" + getBasename(currentFile()) + ".sagetex.sage')");
return isWindows(theWindowsCommand, getCommand("sage", getBasename(reference) + ".sagetex.sage"));
}
to compile the following document
% arara: lualatex
% arara: sagetex
% arara: lualatex
\documentclass{article}
\usepackage{sagetex}
\begin{document}
Using Sage\TeX, one can use Sage to compute things and put them into your \LaTeX{} document. For example, there are
$\sage{number_of_partitions(1269)}$ integer partitions of $1269$.
You don't need to compute the number yourself, or even cut and paste it from somewhere.
Here's some Sage code:
\begin{sageblock}
f(x) = exp(x) * sin(2*x)
\end{sageblock}
The second derivative of $f$ is
\[
\frac{\mathrm{d}^{2}}{\mathrm{d}x^{2}} \sage{f(x)} =
\sage{diff(f, x, 2)(x)}.
\]
Here's a plot of $f$ from $-1$ to $1$:
\sageplot{plot(f, -1, 1)}
\end{document}
I get this error
> SyntaxError: (unicode error)
> 'unicodeescape' codec can't decode
> bytes in position 2-3: truncated
> \UXXXXXXXX escape
So, what should be changed in both the arara rule and, consequently, the following command to make everything work?
"C:\Program Files\SageMath 9.1\runtime\bin\bash" -l "C:/Program Files/SageMath 9.1/runtime/opt/sagemath-9.1/sage" -c "os.chdir('C:\Users\Diaa\Desktop\Test'); load('testsagetex.sagetex.sage')"DiaaMon, 03 Aug 2020 16:10:57 -0500https://ask.sagemath.org/question/52840/SageMath on macOS: app, components, packages, SageTeXhttps://ask.sagemath.org/question/52776/sagemath-on-macos-app-components-packages-sagetex/I'm brand new to SageMath and having trouble getting my bearings.
Can you help with these things:
- On macOS 10.14.6, I downloaded and installed
`sage-9.1-OSX_10.11.6-X86_64.app.dmg` from the
[SageMath download mirror at MIT](https://mirrors.mit.edu/sage/osx/intel/index.html).
But although the app starts the way the page says, "like most other
Mac applications," the interface is quite different from most other
Mac applications. Instead of the usual sequence,
"**AppName**, **File**, **Edit**, **View**, ... **Window**, **Help**,"
Sage has "**Sage**, **File**, **Server**, **Terminal Session**, **Development**, **Help**."
I recognize "**Sage**," "**File**," and "**Help**," but not the rest.
Is there introductory documentation or a tutorial somewhere
that explains how to use Sage from this interface?
- Regarding the installation itself, the
[SageMath components documentation](https://www.sagemath.org/links-components.html)
lists 84 separate components. Some of these, like R and Python,
I already have installed and use regularly in different contexts.
Does SageMath install duplicates, or does it use the already installed
versions? And in either case, how does SageMath handle component
updates and possible incompatibilities associated with them?
- I want to use SageMath with [LyX](https://www.lyx.org/)
and therefore need SageTeX. In the SageMath documentation, the
[SageTeX tutorial](https://doc.sagemath.org/html/en/tutorial/sagetex.html#sec-sagetex-install)
says SageMath comes with SageTeX, and all one needs to do
is to make TeX aware of it. But the page refers to `SAGE_ROOT`,
and since I installed using the `.dmg` file, I'm not really sure
where `SAGE_ROOT` is. How does one find it?GnossosFri, 31 Jul 2020 11:07:54 -0500https://ask.sagemath.org/question/52776/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/Problems with sagetexhttps://ask.sagemath.org/question/51945/problems-with-sagetex/texmaker does not give me the required PDF file although in sage it is written : Sage processing complete. Run LaTeX on st_example.tex again
1. I took the example at https://doc.sagemath.org/html/en/tutorial/sagetex.html, pasted this code into Texmaker and saved it under the file name st_example.tex.
At this link http://www.cecm.sfu.ca/sage/spkg/upstream/sagetex/index.html I chose sagetex-3.3.tar.gz.
I put st_example.tex into the file sagetex3.3. There I compiled it using PDFLatex.
After this a new file appeared, st_example.sagetex.
2. I uploaded st_example.sagetex on cocalc.com. Then another code appeared, I clicked on Terminal wherein I wrote sage st_example.sagetex.sage. After this there was written: Sage processing complete. Run LaTeX on st_example.tex again. Especially new files appeared e.g st_example.sagetex.sout.
3. After again compiling st_example.tex in Latex with PDFLatex there were still these question marks and nothing changed.
Sorry I don't know how to write it properly:
\documentclass{article}
\usepackage{sagetex}
\begin{document}
Using Sage\TeX, one can use Sage to compute things and put them into
your \LaTeX{} document. For example, there are
$\sage{number_of_partitions(1269)}$ integer partitions of $1269$.
You don't need to compute the number yourself, or even cut and paste
it from somewhere.
Here's some Sage code:
\begin{sageblock}
f(x) = exp(x) * sin(2*x)
\end{sageblock}
The second derivative of $f$ is
\[
\frac{\mathrm{d}^{2}}{\mathrm{d}x^{2}} \sage{f(x)} =
\sage{diff(f, x, 2)(x)}.
\]
Here's a plot of $f$ from $-1$ to $1$:
\sageplot{plot(f, -1, 1)}
\end{document}
this is the log file:
This is pdfTeX, Version 3.14159265-2.6-1.40.20 (MiKTeX 2.9.7250 64-bit) (preloaded format=pdflatex 2020.1.11) 14 JUN 2020 17:36
entering extended mode
**./st_example.tex
(st_example.tex
LaTeX2e <2019-10-01> patch level 3
("C:\Users\tdami\AppData\Local\Programs\MiKTeX 2.9\tex/latex/base\article.cls"
Document Class: article 2019/10/25 v1.4k Standard LaTeX document class
("C:\Users\tdami\AppData\Local\Programs\MiKTeX 2.9\tex/latex/base\size10.clo"
File: size10.clo 2019/10/25 v1.4k Standard LaTeX file (size option)
)
\c@part=\count80
\c@section=\count81
\c@subsection=\count82
\c@subsubsection=\count83
\c@paragraph=\count84
\c@subparagraph=\count85
\c@figure=\count86
\c@table=\count87
\abovecaptionskip=\skip41
\belowcaptionskip=\skip42
\bibindent=\dimen102
) (sagetex.sty
Package: sagetex 2019/01/09 v3.3 embedding Sage into LaTeX documents
("C:\Users\tdami\AppData\Local\Programs\MiKTeX 2.9\tex/latex/tools\verbatim.sty
"
Package: verbatim 2019/11/10 v1.5r LaTeX2e package for verbatim enhancements
\every@verbatim=\toks14
\verbatim@line=\toks15
\verbatim@in@stream=\read1
)
("C:\Users\tdami\AppData\Local\Programs\MiKTeX 2.9\tex/latex/fancyvrb\fancyvrb.
sty"
Package: fancyvrb 2020/01/13 v3.5 verbatim text (tvz,hv)
("C:\Users\tdami\AppData\Local\Programs\MiKTeX 2.9\tex/latex/graphics\keyval.st
y"
Package: keyval 2014/10/28 v1.15 key=value parser (DPC)
\KV@toks@=\toks16
)
\FV@CodeLineNo=\count88
\FV@InFile=\read2
\FV@TabBox=\box27
\c@FancyVerbLine=\count89
\FV@StepNumber=\count90
\FV@OutFile=\write3
)
("C:\Users\tdami\AppData\Local\Programs\MiKTeX 2.9\tex/latex/listings\listings.
sty"
\lst@mode=\count91
\lst@gtempboxa=\box28
\lst@token=\toks17
\lst@length=\count92
\lst@currlwidth=\dimen103
\lst@column=\count93
\lst@pos=\count94
\lst@lostspace=\dimen104
\lst@width=\dimen105
\lst@newlines=\count95
\lst@lineno=\count96
\lst@maxwidth=\dimen106
("C:\Users\tdami\AppData\Local\Programs\MiKTeX 2.9\tex/latex/listings\lstmisc.s
ty"
File: lstmisc.sty 2020/03/24 1.8d (Carsten Heinz)
\c@lstnumber=\count97
\lst@skipnumbers=\count98
\lst@framebox=\box29
)
("C:\Users\tdami\AppData\Local\Programs\MiKTeX 2.9\tex/latex/listings\listings.
cfg"
File: listings.cfg 2020/03/24 1.8d listings configuration
))
Package: listings 2020/03/24 1.8d (Carsten Heinz)
("C:\Users\tdami\AppData\Local\Programs\MiKTeX 2.9\tex/latex/graphics\color.sty
"
Package: color 2016/07/10 v1.1e Standard LaTeX Color (DPC)
("C:\Users\tdami\AppData\Local\Programs\MiKTeX 2.9\tex/latex/graphics-cfg\color
.cfg"
File: color.cfg 2016/01/02 v1.6 sample color configuration
)
Package color Info: Driver file: pdftex.def on input line 147.
("C:\Users\tdami\AppData\Local\Programs\MiKTeX 2.9\tex/latex/graphics-def\pdfte
x.def"
File: pdftex.def 2018/01/08 v1.0l Graphics/color driver for pdftex
))
("C:\Users\tdami\AppData\Local\Programs\MiKTeX 2.9\tex/latex/graphics\graphicx.
sty"
Package: graphicx 2017/06/01 v1.1a Enhanced LaTeX Graphics (DPC,SPQR)
("C:\Users\tdami\AppData\Local\Programs\MiKTeX 2.9\tex/latex/graphics\graphics.
sty"
Package: graphics 2019/11/01 v1.3d Standard LaTeX Graphics (DPC,SPQR)
("C:\Users\tdami\AppData\Local\Programs\MiKTeX 2.9\tex/latex/graphics\trig.sty"
Package: trig 2016/01/03 v1.10 sin cos tan (DPC)
)
("C:\Users\tdami\AppData\Local\Programs\MiKTeX 2.9\tex/latex/graphics-cfg\graph
ics.cfg"
File: graphics.cfg 2016/06/04 v1.11 sample graphics configuration
)
Package graphics Info: Driver file: pdftex.def on input line 105.
)
\Gin@req@height=\dimen107
\Gin@req@width=\dimen108
)
("C:\Users\tdami\AppData\Local\Programs\MiKTeX 2.9\tex/latex/makecmds\makecmds.
sty"
Package: makecmds 2009/09/03 v1.0a extra command making commands
)
("C:\Users\tdami\AppData\Local\Programs\MiKTeX 2.9\tex/generic/iftex\ifpdf.sty"
Package: ifpdf 2019/10/25 v3.4 ifpdf legacy package. Use iftex instead.
("C:\Users\tdami\AppData\Local\Programs\MiKTeX 2.9\tex/generic/iftex\iftex.sty"
Package: iftex 2019/11/07 v1.0c TeX engine tests
)) ("C:\Users\tdami\AppData\Local\Programs\MiKTeX 2.9\tex/latex/base\ifthen.sty
"
Package: ifthen 2014/09/29 v1.1c Standard LaTeX ifthen package (DPC)
)
("C:\Users\tdami\AppData\Local\Programs\MiKTeX 2.9\tex/generic/iftex\ifxetex.st
y"
Package: ifxetex 2019/10/25 v0.7 ifxetex legacy package. Use iftex instead.
)
\c@ST@inline=\count99
\c@ST@plot=\count100
\c@ST@cmdline=\count101
\sagetexindent=\skip43
No file st_example.sagetex.sout.
\sagecommandlineskip=\skip44
) (st_example.aux)
\openout1 = `st_example.aux'.
LaTeX Font Info: Checking defaults for OML/cmm/m/it on input line 4.
LaTeX Font Info: ... okay on input line 4.
LaTeX Font Info: Checking defaults for T1/cmr/m/n on input line 4.
LaTeX Font Info: ... okay on input line 4.
LaTeX Font Info: Checking defaults for OT1/cmr/m/n on input line 4.
LaTeX Font Info: ... okay on input line 4.
LaTeX Font Info: Checking defaults for OMS/cmsy/m/n on input line 4.
LaTeX Font Info: ... okay on input line 4.
LaTeX Font Info: Checking defaults for OMX/cmex/m/n on input line 4.
LaTeX Font Info: ... okay on input line 4.
LaTeX Font Info: Checking defaults for U/cmr/m/n on input line 4.
LaTeX Font Info: ... okay on input line 4.
\c@lstlisting=\count102
("C:\Users\tdami\AppData\Local\Programs\MiKTeX 2.9\tex/context/base/mkii\supp-p
df.mkii"
[Loading MPS to PDF converter (version 2006.09.02).]
\scratchcounter=\count103
\scratchdimen=\dimen109
\scratchbox=\box30
\nofMPsegments=\count104
\nofMParguments=\count105
\everyMPshowfont=\toks18
\MPscratchCnt=\count106
\MPscratchDim=\dimen110
\MPnumerator=\count107
\makeMPintoPDFobject=\count108
\everyMPtoPDFconversion=\toks19
)
("C:\Users\tdami\AppData\Local\Programs\MiKTeX 2.9\tex/latex/epstopdf-pkg\epsto
pdf-base.sty"
Package: epstopdf-base 2019/11/24 v2.7 Base part for package epstopdf
("C:\Users\tdami\AppData\Local\Programs\MiKTeX 2.9\tex/generic/oberdiek\infware
rr.sty"
Package: infwarerr 2016/05/16 v1.4 Providing info/warning/error messages (HO)
)
("C:\Users\tdami\AppData\Local\Programs\MiKTeX 2.9\tex/latex/oberdiek\grfext.st
y"
Package: grfext 2016/05/16 v1.2 Manage graphics extensions (HO)
("C:\Users\tdami\AppData\Local\Programs\MiKTeX 2.9\tex/generic/oberdiek\kvdefin
ekeys.sty"
Package: kvdefinekeys 2016/05/16 v1.4 Define keys (HO)
("C:\Users\tdami\AppData\Local\Programs\MiKTeX 2.9\tex/generic/oberdiek\ltxcmds
.sty"
Package: ltxcmds 2016/05/16 v1.23 LaTeX kernel commands for general use (HO)
)))
("C:\Users\tdami\AppData\Local\Programs\MiKTeX 2.9\tex/latex/oberdiek\kvoptions
.sty"
Package: kvoptions 2016/05/16 v3.12 Key value format for package options (HO)
("C:\Users\tdami\AppData\Local\Programs\MiKTeX 2.9\tex/generic/oberdiek\kvsetke
ys.sty"
Package: kvsetkeys 2016/05/16 v1.17 Key value parser (HO)
("C:\Users\tdami\AppData\Local\Programs\MiKTeX 2.9\tex/generic/oberdiek\etexcmd
s.sty"
Package: etexcmds 2016/05/16 v1.6 Avoid name clashes with e-TeX commands (HO)
("C:\Users\tdami\AppData\Local\Programs\MiKTeX 2.9\tex/generic/iftex\ifluatex.s
ty"
Package: ifluatex 2019/10/25 v1.5 ifluatex legacy package. Use iftex instead.
))))
("C:\Users\tdami\AppData\Local\Programs\MiKTeX 2.9\tex/latex/pdftexcmds\pdftexc
mds.sty"
Package: pdftexcmds 2019/11/24 v0.31 Utility functions of pdfTeX for LuaTeX (HO
)
Package pdftexcmds Info: \pdf@primitive is available.
Package pdftexcmds Info: \pdf@ifprimitive is available.
Package pdftexcmds Info: \pdfdraftmode found.
)
Package epstopdf-base Info: Redefining graphics rule for `.eps' on input line 4
42.
Package grfext Info: Graphics extension search list:
(grfext) [.pdf,.png,.jpg,.mps,.jpeg,.jbig2,.jb2,.PDF,.PNG,.JPG,.JPE
G,.JBIG2,.JB2,.eps]
(grfext) \AppendGraphicsExtensions on input line 460.
)
\ST@sf=\write4
\openout4 = `st_example.sagetex.sage'.
LaTeX Font Info: External font `cmex10' loaded for size
(Font) <7> on input line 7.
LaTeX Font Info: External font `cmex10' loaded for size
(Font) <5> on input line 7.
LaTeX Warning: Reference `@sageinline0' on page 1 undefined on input line 8.
LaTeX Warning: Reference `@sageinline1' on page 1 undefined on input line 21.
LaTeX Warning: Reference `@sageinline2' on page 1 undefined on input line 22.
Package sagetex Warning: Graphics file sage-plots-for-st_example.tex/plot-0.pdf
on page 1 does not exist. Plot command is on input line 27.
*********************************************************************
Package sagetex Warning: there were undefined Sage formulas and/or plots.
Run Sage on st_example.sagetex.sage, and then run LaTeX on st_example.tex again
.
*********************************************************************
[1
{C:/Users/tdami/AppData/Local/MiKTeX/2.9/pdftex/config/pdftex.map}]
(st_example.aux)
LaTeX Warning: There were undefined references.
)
Here is how much of TeX's memory you used:
3452 strings out of 492484
51317 string characters out of 3121601
119239 words of memory out of 3000000
7772 multiletter control sequences out of 15000+200000
4116 words of font info for 16 fonts, out of 3000000 for 9000
1141 hyphenation exceptions out of 8191
51i,5n,40p,302b,217s stack positions out of 5000i,500n,10000p,200000b,50000s
<C:/Users/tdami/AppData/Local/Programs/MiKTeX 2.9/fonts/type1/public/amsfonts
/cm/cmbx10.pfb><C:/Users/tdami/AppData/Local/Programs/MiKTeX 2.9/fonts/type1/pu
blic/amsfonts/cm/cmmi10.pfb><C:/Users/tdami/AppData/Local/Programs/MiKTeX 2.9/f
onts/type1/public/amsfonts/cm/cmr10.pfb><C:/Users/tdami/AppData/Local/Programs/
MiKTeX 2.9/fonts/type1/public/amsfonts/cm/cmr7.pfb><C:/Users/tdami/AppData/Loca
l/Programs/MiKTeX 2.9/fonts/type1/public/amsfonts/cm/cmsy10.pfb><C:/Users/tdami
/AppData/Local/Programs/MiKTeX 2.9/fonts/type1/public/amsfonts/cm/cmtt10.pfb>
Output written on st_example.pdf (1 page, 63456 bytes).
PDF statistics:
30 PDF objects out of 1000 (max. 8388607)
0 named destinations out of 1000 (max. 500000)
1 words of extra memory for PDF output out of 10000 (max. 10000000)MoondoggySat, 13 Jun 2020 10:27:22 -0500https://ask.sagemath.org/question/51945/How allow renaming SageMath-x.y.app to SageMath.app for sagetexhttps://ask.sagemath.org/question/51969/how-allow-renaming-sagemath-xyapp-to-sagemathapp-for-sagetex/When using the `sagetex` with LaTeX under MacTeX and the TeXShop front end, the suggested method (from the TeXShop docs) is to rename `SageMath-x.y.app` to just `SageMath.app` and then to create symlinks for the executable `sage` and for `sagetex.sty` within the Contents of the app.
That works just fine to use `sagetex` in LaTeX.
However, once the renaming is done, the app itself no longer works! Once I open the renamed SageMath.app, I get a pop-up error message "Juypyter Server failed to start...", and inspecting the log reveals:
/Applications/SageMath.app/Contents/Resources/sage/src/bin/sage: line 617: /Applications/SageMath-9.1.app/Contents/Resources/sage/local/bin/python3: No such file or directory
/Applications/SageMath.app/Contents/Resources/sage/src/bin/sage: line 617: exec: /Applications/SageMath-9.1.app/Contents/Resources/sage/local/bin/python3: cannot execute: No such file or directory
Apparently access to `python3` has been hard-coded into the `sage` executable so that it is expect to be in the file tree with root the original name `SageMath-x.y`.
Is there some workaround so that one can both use `sagetex` in the way recommended by the MacTeX/TeXShop world and still be able to use the SageMath app normally to start the Jupyter server, etc.?murrayeSun, 14 Jun 2020 09:51:53 -0500https://ask.sagemath.org/question/51969/How do I get the output of this text in latex with sagetex?https://ask.sagemath.org/question/51919/how-do-i-get-the-output-of-this-text-in-latex-with-sagetex/Using Sage\TeX, one can use Sage to compute things and put them into
your \LaTeX{} document. For example, there are
`$\sage{number_of_partitions(1269)}$` integer partitions of $1269$.
You don't need to compute the number yourself, or even cut and paste
it from somewhere.
Here's some Sage code:
\begin{sageblock}
f(x) = exp(x) * sin(2*x)
\end{sageblock}
The second derivative of $f$ is
\[
\frac{\mathrm{d}^{2}}{\mathrm{d}x^{2}} \sage{f(x)} =
\sage{diff(f, x, 2)(x)}.
\]
Here's a plot of $f$ from $-1$ to $1$:
\sageplot{plot(f, -1, 1)}
\end{document}MoondoggyFri, 12 Jun 2020 09:40:34 -0500https://ask.sagemath.org/question/51919/SageTeX: formatting matriceshttps://ask.sagemath.org/question/51321/sagetex-formatting-matrices/Hello all,
I would like to have sagetex producing matrices with the columns centered. If was writing this by hand, I would do
`\begin{bmatrix*}[c] ... \end{bmatrix*}`
From my XXX.sout file, I see the result `\begin{array}{rrr} ... \end{array}`. Is there a way to control this? Either playing at the sage level directly or by controlling sagetex?
Thanks!
JCThu, 07 May 2020 20:41:24 -0500https://ask.sagemath.org/question/51321/Can sagetex be configured to read init.sage?https://ask.sagemath.org/question/50648/can-sagetex-be-configured-to-read-initsage/I have a lot of useful code stored in `$DOT_SAGE/init.sage`. I'd like `sagetex` to always have access to my useful code in `init.sage`. Is this possible? done_with_fishThu, 09 Apr 2020 15:54:19 -0500https://ask.sagemath.org/question/50648/SageTeX Warning of Sagemath-9.0 on string with Escaped 'S'https://ask.sagemath.org/question/49999/sagetex-warning-of-sagemath-90-on-string-with-escaped-s/After I installed SageMath-9.0 (MacApplication), I encountered the following warning in the log of SageTeX compilation.
```Console
/Applications/SageMath-9.0.app/Contents/Resources/sage/local/lib/python3.7/site-packages/sagetex.py:63: DeprecationWarning: invalid escape sequence \S
[re.match(' *\S', line) for line in lines]
```
I looked through the internet and found a similar situation in some other software.
* ThiefMaster
* "invalid escape sequence" DeprecationWarnings with Python 3.6 #646
* github.com/pallets/jinja/issues/646
I am trying the solution of this page on GitHub.
The relevant part is around line 63 of `sagetex.py`, which I quote here.
<pre>
```python
def strip_common_leading_spaces(s):
lines = s.splitlines()
lead = min(m.end() for m in
[re.match(r' *\S', line) for line in lines]
if m is not None) - 1
return '\n'.join(line[lead:] for line in lines)
```
</pre>
As in this quotation, I just inserted the letter 'r' to the left of the string on line 63.
It is the first line of the deepest indentation in this quotation.
Is this a good solution?
rana-aereaThu, 20 Feb 2020 04:55:33 -0600https://ask.sagemath.org/question/49999/siunitx comand \SI{number}{units} with sagetexhttps://ask.sagemath.org/question/49836/siunitx-comand-sinumberunits-with-sagetex/I'm trying to create something more like the command `\SI{number}{units}` of siunitx package but I have some trouble. Reading the PythonTex documentation this problem doesn't exist.
Starting with the answer /#49745
\begin{sagesilent}
def SIsage(number,units=0):
if units==0:
if number in ZZ or number.parent()==QQ:
return r"\SI{"+ str(number) + "}"
else:
return r"\SI{"+ str(float(number)) + "}"
else:
if number in ZZ or number.parent()==QQ:
return r"\SI{"+ str(number) + "}" +"{"+ units + "}"
else:
return r"\SI{"+ str(float(number)) + "}" +"{"+ units + "}"
\end{sagesilent}
\sagestr{SIsage(2442,"\kilo\metre\squared")}
\sagestr{SIsage(2442)}
and it works except when using `\newton` witch it become "ewton" problably cause to `\n`
After this I want to create a new custom LaTeX command that replace `\SI{}{}` but I have some trouble with non-default arguments. I didn't understand how them work. I want be able to use both of `\SI{number}{units}` that `\SI{number}` without units. Probably the best choise is to create two different commands(?)
\newcommand{\SIsage_units}[1]{,"#1"}
\newcommand{\SIsage_number}[1]{\sagestr{SIsage(#1}}
\newcommand{\SISAGE}[2]{\SIsage_number{#2}\SIsage_units{#1})} #doesn't work
The command I want:
\SISAGE{21}{\kilo\metre\squared}
\SISAGE{26}{}
So my problems are:
1. how to avoid `\n`
2. how to set an unic custom command `\SISAGE`
Thanks everybodysononicolaFri, 07 Feb 2020 00:26:49 -0600https://ask.sagemath.org/question/49836/Spanish numbers using LaTeXhttps://ask.sagemath.org/question/47018/spanish-numbers-using-latex/Dear SageMath community,
I am currently writing a LaTeX document in Spanish that relies heavily on sageTeX for computations. The rules for writing numbers in Spanish are a little different from English ones. For example, we are prohibited from using commas to separate every 1000 factor, instead using a small space, only if the number is longer than four digits; otherwise, no sign should be used. On the other hand, the decimal point is actually a decimal comma. For example,
- 1,000,000.25 should be written as 1 000 000,25
- 123,456,789.123456789 should be written as 123 456 789,123 456 789
- 4,000 should be written as 4000
Using sageTeX, SageMath's `latex` command, and LaTeX babel package, it is easy to replace the decimal point with a decimal comma. It is also easy to eliminate the commas for every 1000 factor. However, I haven't been able to put a small space instead.
I could use the `siunitx` LaTeX package, which has a command, `\num`, that does exactly this processing. However, it doesn't work with sageTeX's `\sage` command or any of it's environments. The only solution I can find is to apply the `\num` command directly to every number generated by SageMath via the `latex` command.
My problem is: I don't know how to do this, specially in cases where numbers are entries of a matrix, or the coefficients of a polynomial. So, **how could I apply the `\num` command to every number independently using the `latex` command?**
Thanks in advance for your answers! Any alternative approach is also welcomed.dsejasSat, 29 Jun 2019 23:08:29 -0500https://ask.sagemath.org/question/47018/SageTeX: sagecommandline problemhttps://ask.sagemath.org/question/49724/sagetex-sagecommandline-problem/As a simple example of the problem I have encountered
\begin{sagecommandline}
sage: M=matrix.identity(6)
sage: M
sage: v=vector([k for k in [0..5]])
sage: v
\end{sagecommandline}
the output looks fine except that the printed matrix $M$ overlaps with the definition of the vector $v.$![image description](/upfiles/15804678132883916.png)
Is there a way to add some vertical space below the displayed matrix?castorFri, 31 Jan 2020 04:51:09 -0600https://ask.sagemath.org/question/49724/Introduction: A shortcut for the compiling of SageTeX-files with ararahttps://ask.sagemath.org/question/49378/introduction-a-shortcut-for-the-compiling-of-sagetex-files-with-arara/*Note: This is a meta-post, so no answers are needed. I will answer it by myself.*
My dearest SageTeXers, Sagers, arara-users and Pythoners as well!
The normal way to compile a file `example.tex` which contains SageTeX is
`pdflatex example.tex` <br>
`sage example.sagetex.sage`<br>
`pdflatex example.tex`
So the initial question is: How to make a shortcut for this?geroyxSun, 05 Jan 2020 11:36:10 -0600https://ask.sagemath.org/question/49378/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 young_diagram sizehttps://ask.sagemath.org/question/48919/sagetex-young_diagram-size/Hello, I am printing a list of young diagramas in sagetex with something like
<code><pre>\sage{[p for p in Partitions(28) if p.is_symmetric()]}</code></pre>
How can I change the size of the cells so that they can actually fit in paper?heluaniFri, 29 Nov 2019 07:27:30 -0600https://ask.sagemath.org/question/48919/SageTex, sage, version conflict?https://ask.sagemath.org/question/47664/sagetex-sage-version-conflict/Hello to everyone,
I am trying to use sagetex in my ubuntu18.094 machine. I use the file from [this manual](http://doc.sagemath.org/html/fr/tutorial/sagetex.html). I call my file Test.tex
PdfLatex does its job. I have a `Test.sagetex.sage`file in my folder. When I run, at the same folder, from a terminal `sage Test.sagetex.sage` I get the following error
`Traceback (most recent call last):`
`File "Test.sagetex.sage.py", line 9, in <module>`
` _st_ = sagetex.SageTeXProcessor('Test', version='2015/08/26 v3.0-92d9f7a', version_check=True)`
`File "... Programs/sage-8.1/local/lib/python2.7/site-packages/sagetex.py", line 76, in __init__`
`raise VersionError(errstr)`
`sagetex.VersionError: versions of .sty and .py files do not match.`
`Test.sagetex.sage was generated by sagetex.sty version "2015/08/26 v3.0-92d9f7a", but`
`is being processed by sagetex.py version "2019/01/09 v3.2".`
`Please make sure that TeX is using the sagetex.sty`
`from your current version of Sage; see...`
I built sage from the source code, at some point, then I upgraded with `sage update`. I now have sage 8.8 but still a folder `sage-8.1`
I installed sagetex from the repos.
Anyone a suggestion?
Thanks!
JCThu, 29 Aug 2019 18:54:19 -0500https://ask.sagemath.org/question/47664/sagetex with conda installhttps://ask.sagemath.org/question/47184/sagetex-with-conda-install/ Hi folks, I have sage installed using conda. I can't seem to find the sagetex.sty file on my system which makes me think it wasn't installed. Any suggestions? rhaynes74Tue, 16 Jul 2019 09:08:53 -0500https://ask.sagemath.org/question/47184/False Directoryhttps://ask.sagemath.org/question/46731/false-directory/The directory where kpsewhich -var-value=TEXMFHOME
the command takes me is not real in my commuter. I am using this help [this one](http://fe.math.kobe-u.ac.jp/icms2010-dvd/SAGE/www.sagemath.org/doc/installation/sagetex.html)
because the mismatch occurred any clue to how I could change that directory to something else and get sage tex working?
C:/Users/Light_Wisdom/texmf
False Directory.
> BlockquoteEnlightenedFunkThu, 30 May 2019 17:47:45 -0500https://ask.sagemath.org/question/46731/Why do I get the OSError: [Errno2] when I try to run a .sage filehttps://ask.sagemath.org/question/46116/why-do-i-get-the-oserror-errno2-when-i-try-to-run-a-sage-file/Hello.
I'm new to SageMath and just installed it. Unfortunately I'm not too concerned with the importance of the information you might need to help me out - sorry for that.
So I have Windows 10 and I installed SageMath via These pre- built binaries if that's what it is called. I used the sagetex package to create a .sage file and I tried to run it with sage obviously. Therefore, I opened the Shell and typed
sage 'C:/Users/scheu/OneDrive/Desktop/sagetex.sage'
with sagetex.sage being my .sage file and I'm getting the following:
Traceback (most recent call last):
File "/opt/sagemath-8.6/src/bin/sage-preparse", line 245, in <module>
do_preparse(f)
File "/opt/sagemath-8.6/src/bin/sage-preparse", line 137, in do_preparse
with atomic_write(fname) as f:
File "/opt/sagemath-8.6/local/lib/python2.7/site-packages/sage/misc/temporary_file.py", line 422, in __enter__
fd, name = tempfile.mkstemp(dir=self.tmpdir)
File "/opt/sagemath-8.6/local/lib/python2.7/tempfile.py", line 314, in mkstemp
return _mkstemp_inner(dir, prefix, suffix, flags)
File "/opt/sagemath-8.6/local/lib/python2.7/tempfile.py", line 244, in _mkstemp_inner
fd = _os.open(file, flags, 0600)
OSError: [Errno 2] No such file or directory: '/home/sage/C:/Users/scheu/OneDrive/Desktop/Programme/LaTeX Files,Texmaker/Hilffiles/sagetex test/tmpfPP2mL'
By the way, I am sorry for putting the Code in my Question that way, I had just no idea how to Format this Code as one Code :(
Anyways, it says something I don't quite understand and I've already looked up the same Question, but it didn't help…
Thank you for your answers.LilanarusFri, 12 Apr 2019 14:44:50 -0500https://ask.sagemath.org/question/46116/Why does Sage Math crash instantly? / Running .sage files?https://ask.sagemath.org/question/46051/why-does-sage-math-crash-instantly-running-sage-files/ Hello.
First of all, I need to Mention that I am completely new to Sage Math and I have no idea what causes my problem(s), like seriousely, no idea.
When I start SageMath, it instantly crashes, I don't even touch anything. I'm running Windows 10 and I downloaded the binaries, a virtual box and this sage-8.6.tar.gz file. I am sure that I must be missing something but I don't know what.
Yesterday, I managed to get Sage to work, so in the terminal i could write simple commands like
sage:4+3
and later, I reinstalled python. Now it does not work anymore. My original aim was it to have sagetex in Latex, but for some reason running the .sage file which is created with every document using sagetex doesn't do anything and sage does not compile my document. And yes, I did follow the instructions how to make sagetex known to tex.
I have no idea how to continue, so many problems and i'm desperately trying to get things to work. (Feel like I downloaded half the Internet...) LilanarusMon, 08 Apr 2019 09:26:52 -0500https://ask.sagemath.org/question/46051/SageTeX UnicodeDecodeErrorhttps://ask.sagemath.org/question/45985/sagetex-unicodedecodeerror/Hello, Sage community.
I've been writing a book with the help of SageTeX. Until yesterday, I was working with SageMath v8.6, and everything work perfectly. Today I downloaded SageMath v8.7 binary for Linux, and replaced the corresponding SageTeX files. But when I tried to compile the book, suddenly I receive an error message:
> Traceback (most recent call last):
>
> File "book.sagetex.sage.py", line 5158, in <module>
>
> `_st_.endofdoc()`
>
> File "/SageMath/local/lib/python2.7/site-packages/sagetex.py", line 276, in endofdoc
>
> m.update(bytearray(line,'utf8'))
>
> UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 29: ordinal not in range(128)
The only difference from yesterday is the new version of SageMath. Can somebody explain/help me with this matter?
Thanks in advance for your answers!dsejasTue, 02 Apr 2019 06:03:58 -0500https://ask.sagemath.org/question/45985/Why can't I use the sagesilent environment in AtBeginDocument?https://ask.sagemath.org/question/45047/why-cant-i-use-the-sagesilent-environment-in-atbegindocument/I'm trying to write a latex `sty` file to change the default behavior of `sagetex`.
My file is
\NeedsTeXFormat{LaTeX2e}[1994/06/01]
\ProvidesPackage{examplepackage}[2018/12/24 examplepackage]
\RequirePackage{sagetex}
\RequirePackage{etoolbox}
\AtBeginDocument{%
\begin{sagesilent}
A = 3
\end{sagesilent}
}
\endinput
However, attempting to use this `sty` file in the following latex file produces the error `! File ended while scanning use of \next.`
\documentclass[12pt]{article}
\usepackage{examplepackage}
\begin{document}
hello world!
\end{document}
What's wrong with my `sty` file?done_with_fishMon, 14 Jan 2019 21:47:30 -0600https://ask.sagemath.org/question/45047/Is it possible to customize the default behavior of sagetex?https://ask.sagemath.org/question/44773/is-it-possible-to-customize-the-default-behavior-of-sagetex/When using sagetex, I want my matrices to have square brackets and my vectors to have angled brackets. Hence, the first thing I do after `\begin{document}` is include the code
\begin{sagesilent}
latex.matrix_delimiters(left='[', right=']')
latex.vector_delimiters(left='<', right='>')
\end{sagesilent}
This is very annoying. Is it possible to set sagetex up to do this by default?done_with_fishMon, 24 Dec 2018 12:19:35 -0600https://ask.sagemath.org/question/44773/Piecewise in SageTeXhttps://ask.sagemath.org/question/45278/piecewise-in-sagetex/ Hi, am trying to use the "piecewise" command in SageTeX but i get an error no matter what i try. It is like the SageTeX doesnt know what "piecewise" means, like the command "piecewise" is not implemented in SageTeX.
I tried different ways of typing the piecewise command in sage terminal and it works fine.
sage: f=piecewise([[(-15,0),6],[(0,44),sqrt(-x^2+52*x+36)]])
and
sage: f=piecewise([((-15,0), 6), ([0,44], sqrt(-x^2+52*x+36))]); f
But when i do the same in sagetex and compile with
# sage filename.sagetex.sage
Then i get
Processing Sage code for modul-2.tex...
Sage commandline 0 (line 193)
Sage commandline 1 (line 200)
Sage commandline 2 (line 209)
/usr/lib/python2.7/site-packages/sagetex.py:209: DeprecationWarning: Substitution using function-call syntax and unnamed arguments is deprecated and will be removed from a future release of Sage; you can use named arguments instead, like EXPR(x=..., y=...)
DELETED LINK
result = eval(preparse(splitup[i][2]), globals, locals)
Sage commandline 3 (line 239)
Sage commandline 4 (line 246)
Sage commandline 5 (line 252)
/usr/lib/python2.7/site-packages/sagetex.py:218: DeprecationWarning: Substitution using function-call syntax and unnamed arguments is deprecated and will be removed from a future release of Sage; you can use named arguments instead, like EXPR(x=..., y=...)
DELETED LINK
exec(preparse(splitup[i][2]), globals, locals)
Sage commandline 6 (line 309)
Sage commandline 7 (line 315)
Sage commandline 8 (line 322)
Sage commandline 9 (line 496)
Sage commandline 10 (line 505)
Sage commandline 11 (line 520)
Sage commandline 12 (line 530)
Sage commandline 13 (line 538)
Sage commandline 14 (line 559)
**** Error in Sage code on line 561 of modul-2.tex! Traceback follows.
Traceback (most recent call last):
File "modul-2.sagetex.sage.py", line 119, in <module>
""", globals(), locals(), False)
File "/usr/lib/python2.7/site-packages/sagetex.py", line 196, in commandline
splitup = self.split_sage_cmds(s)
File "/usr/lib/python2.7/site-packages/sagetex.py", line 138, in split_sage_cmds
starts[0] = re.search(prompt, s).start()
AttributeError: 'NoneType' object has no attribute 'start'
**** Running Sage on modul-2.sage failed! Fix modul-2.tex and try again.
I tried inside env, sagecommandline and \sage{} and env. sageblock.
I didnt get error in sageblock but then when i tried to plot the function later i got the error anyways.
Can anyone help me from here? How can i define piecewise functions in SageTeX??Martin MårtenssonSat, 02 Feb 2019 18:17:24 -0600https://ask.sagemath.org/question/45278/how to sage a .sage filehttps://ask.sagemath.org/question/41568/how-to-sage-a-sage-file/ I am having sage installed on a windows 10. Sage file example.sage.sage which is generated by sagetex is situated in K:\sageexample folder. How to run sage on this file. All references are full of jargonism and don't explain anything at all or give examples.
I run sage shell and prompt:
run ('K:sageexample\example.sage.sage') but no result. I run load command load ('K:sageexample\example.sage.sage') no example.
I don't want to install linux for one program.
How to "sage" a file from notebook interface?kate_l196Thu, 15 Mar 2018 12:27:18 -0500https://ask.sagemath.org/question/41568/Code highlighting and execution in sagetexhttps://ask.sagemath.org/question/38742/code-highlighting-and-execution-in-sagetex/Is there a version of
```
\begin{sageblock}
my multiline code
\end{sageblock}```
that has code highlighting and line numbering like the `sagecommandline` environment **and** code execution?
Of course typesetting with `lstlistings` and execution with `sagesilent` could be a workaround, but it would seem to require me to have the same code in my document twice. And that I find unacceptable.BjörnTue, 05 Sep 2017 07:44:22 -0500https://ask.sagemath.org/question/38742/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/