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.Sat, 13 Jun 2020 10:26:46 +0200How 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}Fri, 12 Jun 2020 16:40:34 +0200https://ask.sagemath.org/question/51919/how-do-i-get-the-output-of-this-text-in-latex-with-sagetex/Comment by Emmanuel Charpentier for <p>Using Sage\TeX, one can use Sage to compute things and put them into
your \LaTeX{} document. For example, there are
<code>$\sage{number_of_partitions(1269)}$</code> integer partitions of $1269$.
You don't need to compute the number yourself, or even cut and paste
it from somewhere.</p>
<p>Here's some Sage code:</p>
<p>\begin{sageblock}
f(x) = exp(x) * sin(2*x)
\end{sageblock}</p>
<p>The second derivative of $f$ is</p>
<p>[
\frac{\mathrm{d}^{2}}{\mathrm{d}x^{2}} \sage{f(x)} =
\sage{diff(f, x, 2)(x)}.
]</p>
<p>Here's a plot of $f$ from $-1$ to $1$:</p>
<p>\sageplot{plot(f, -1, 1)}</p>
<p>\end{document}</p>
https://ask.sagemath.org/question/51919/how-do-i-get-the-output-of-this-text-in-latex-with-sagetex/?comment=51921#post-id-51921And your question is ?Fri, 12 Jun 2020 18:20:36 +0200https://ask.sagemath.org/question/51919/how-do-i-get-the-output-of-this-text-in-latex-with-sagetex/?comment=51921#post-id-51921Comment by Moondoggy for <p>Using Sage\TeX, one can use Sage to compute things and put them into
your \LaTeX{} document. For example, there are
<code>$\sage{number_of_partitions(1269)}$</code> integer partitions of $1269$.
You don't need to compute the number yourself, or even cut and paste
it from somewhere.</p>
<p>Here's some Sage code:</p>
<p>\begin{sageblock}
f(x) = exp(x) * sin(2*x)
\end{sageblock}</p>
<p>The second derivative of $f$ is</p>
<p>[
\frac{\mathrm{d}^{2}}{\mathrm{d}x^{2}} \sage{f(x)} =
\sage{diff(f, x, 2)(x)}.
]</p>
<p>Here's a plot of $f$ from $-1$ to $1$:</p>
<p>\sageplot{plot(f, -1, 1)}</p>
<p>\end{document}</p>
https://ask.sagemath.org/question/51919/how-do-i-get-the-output-of-this-text-in-latex-with-sagetex/?comment=51923#post-id-51923I don't know how to run a code in latex with sagetex. I have got some calculations in sage and I want latex to print them out.Fri, 12 Jun 2020 18:25:42 +0200https://ask.sagemath.org/question/51919/how-do-i-get-the-output-of-this-text-in-latex-with-sagetex/?comment=51923#post-id-51923Answer by Emmanuel Charpentier for <p>Using Sage\TeX, one can use Sage to compute things and put them into
your \LaTeX{} document. For example, there are
<code>$\sage{number_of_partitions(1269)}$</code> integer partitions of $1269$.
You don't need to compute the number yourself, or even cut and paste
it from somewhere.</p>
<p>Here's some Sage code:</p>
<p>\begin{sageblock}
f(x) = exp(x) * sin(2*x)
\end{sageblock}</p>
<p>The second derivative of $f$ is</p>
<p>[
\frac{\mathrm{d}^{2}}{\mathrm{d}x^{2}} \sage{f(x)} =
\sage{diff(f, x, 2)(x)}.
]</p>
<p>Here's a plot of $f$ from $-1$ to $1$:</p>
<p>\sageplot{plot(f, -1, 1)}</p>
<p>\end{document}</p>
https://ask.sagemath.org/question/51919/how-do-i-get-the-output-of-this-text-in-latex-with-sagetex/?answer=51924#post-id-51924**EDIT:** a good starting point is [this documentation](https://doc.sagemath.org/html/en/tutorial/sagetex.html).
Very roughly :
- create your text in LaTeX, interspeding Sage fragments as needed : this will be, say, `yourtext.tex`.
- `pdflatex yourtext.tex` : this will create `yourtext.sagetex.sage`, and give warninges about undefined references.
- `sage yourtext.sagetex.sage`. This will, among other effects, update `yourtext.tex`.
- `pdflatex yourtext.tex` (usually, you have to do it twice).
`yourtext.pdf` is now the sought document...
**EDIT :** The documenntation compiled in PDF form an an example tec=xt are available in `$SAGE_ROOT/local/share/doc/sagetex/`.
To recompile it (and get the indices) : in your installation, you have:
(sage-sh) charpent@zen-book-flip:~$ ls $SAGE_ROOT/local/share/texmf/tex/latex/sagetex/
CONTRIBUTORS py-and-sty.dtx sagetex.dtx scripts.dtx
example.tex remote-sagetex.dtx sagetex.ins
extractsagecode.py remote-sagetex.py sagetexparse.py
makestatic.py run-sagetex-if-necessary.py sagetex.sty
Compiling `sagetex.dtx` with pdflatex (in a scratch directory) will give you instructions on how to compile both Sagetex and its documentation. More details [here](https://en.wikibooks.org/wiki/LaTeX/Installing_Extra_Packages).
This cannot be done automatically in Sage's installation, because it requires a (not inconsequential) functional installation of LaTeX, which is not a Sage dependency.
The fie `example.tex` is also quite instructive... Fiddle with it a bit.
HTH,Fri, 12 Jun 2020 19:16:42 +0200https://ask.sagemath.org/question/51919/how-do-i-get-the-output-of-this-text-in-latex-with-sagetex/?answer=51924#post-id-51924Comment by Moondoggy for <p><strong>EDIT:</strong> a good starting point is <a href="https://doc.sagemath.org/html/en/tutorial/sagetex.html">this documentation</a>.</p>
<p>Very roughly :</p>
<ul>
<li><p>create your text in LaTeX, interspeding Sage fragments as needed : this will be, say, <code>yourtext.tex</code>.</p></li>
<li><p><code>pdflatex yourtext.tex</code> : this will create <code>yourtext.sagetex.sage</code>, and give warninges about undefined references.</p></li>
<li><p><code>sage yourtext.sagetex.sage</code>. This will, among other effects, update <code>yourtext.tex</code>.</p></li>
<li><p><code>pdflatex yourtext.tex</code> (usually, you have to do it twice).</p></li>
</ul>
<p><code>yourtext.pdf</code> is now the sought document...</p>
<p><strong>EDIT :</strong> The documenntation compiled in PDF form an an example tec=xt are available in <code>$SAGE_ROOT/local/share/doc/sagetex/</code>.</p>
<p>To recompile it (and get the indices) : in your installation, you have:</p>
<pre><code>(sage-sh) charpent@zen-book-flip:~$ ls $SAGE_ROOT/local/share/texmf/tex/latex/sagetex/
CONTRIBUTORS py-and-sty.dtx sagetex.dtx scripts.dtx
example.tex remote-sagetex.dtx sagetex.ins
extractsagecode.py remote-sagetex.py sagetexparse.py
makestatic.py run-sagetex-if-necessary.py sagetex.sty
</code></pre>
<p>Compiling <code>sagetex.dtx</code> with pdflatex (in a scratch directory) will give you instructions on how to compile both Sagetex and its documentation. More details <a href="https://en.wikibooks.org/wiki/LaTeX/Installing_Extra_Packages">here</a>.</p>
<p>This cannot be done automatically in Sage's installation, because it requires a (not inconsequential) functional installation of LaTeX, which is not a Sage dependency.</p>
<p>The fie <code>example.tex</code> is also quite instructive... Fiddle with it a bit.</p>
<p>HTH,</p>
https://ask.sagemath.org/question/51919/how-do-i-get-the-output-of-this-text-in-latex-with-sagetex/?comment=51933#post-id-51933Thank you for your patience. I do not really know how to do step 3. If I recompile the latex file nothing changes.Sat, 13 Jun 2020 00:19:53 +0200https://ask.sagemath.org/question/51919/how-do-i-get-the-output-of-this-text-in-latex-with-sagetex/?comment=51933#post-id-51933Comment by Moondoggy for <p><strong>EDIT:</strong> a good starting point is <a href="https://doc.sagemath.org/html/en/tutorial/sagetex.html">this documentation</a>.</p>
<p>Very roughly :</p>
<ul>
<li><p>create your text in LaTeX, interspeding Sage fragments as needed : this will be, say, <code>yourtext.tex</code>.</p></li>
<li><p><code>pdflatex yourtext.tex</code> : this will create <code>yourtext.sagetex.sage</code>, and give warninges about undefined references.</p></li>
<li><p><code>sage yourtext.sagetex.sage</code>. This will, among other effects, update <code>yourtext.tex</code>.</p></li>
<li><p><code>pdflatex yourtext.tex</code> (usually, you have to do it twice).</p></li>
</ul>
<p><code>yourtext.pdf</code> is now the sought document...</p>
<p><strong>EDIT :</strong> The documenntation compiled in PDF form an an example tec=xt are available in <code>$SAGE_ROOT/local/share/doc/sagetex/</code>.</p>
<p>To recompile it (and get the indices) : in your installation, you have:</p>
<pre><code>(sage-sh) charpent@zen-book-flip:~$ ls $SAGE_ROOT/local/share/texmf/tex/latex/sagetex/
CONTRIBUTORS py-and-sty.dtx sagetex.dtx scripts.dtx
example.tex remote-sagetex.dtx sagetex.ins
extractsagecode.py remote-sagetex.py sagetexparse.py
makestatic.py run-sagetex-if-necessary.py sagetex.sty
</code></pre>
<p>Compiling <code>sagetex.dtx</code> with pdflatex (in a scratch directory) will give you instructions on how to compile both Sagetex and its documentation. More details <a href="https://en.wikibooks.org/wiki/LaTeX/Installing_Extra_Packages">here</a>.</p>
<p>This cannot be done automatically in Sage's installation, because it requires a (not inconsequential) functional installation of LaTeX, which is not a Sage dependency.</p>
<p>The fie <code>example.tex</code> is also quite instructive... Fiddle with it a bit.</p>
<p>HTH,</p>
https://ask.sagemath.org/question/51919/how-do-i-get-the-output-of-this-text-in-latex-with-sagetex/?comment=51925#post-id-51925Thanks for your help. I do not really understand the third point. Now latex is telling me the following:"Run Sage on sage.sagetex.sage, and then run LaTeX on sage.tex again.".Fri, 12 Jun 2020 19:42:32 +0200https://ask.sagemath.org/question/51919/how-do-i-get-the-output-of-this-text-in-latex-with-sagetex/?comment=51925#post-id-51925Comment by Emmanuel Charpentier for <p><strong>EDIT:</strong> a good starting point is <a href="https://doc.sagemath.org/html/en/tutorial/sagetex.html">this documentation</a>.</p>
<p>Very roughly :</p>
<ul>
<li><p>create your text in LaTeX, interspeding Sage fragments as needed : this will be, say, <code>yourtext.tex</code>.</p></li>
<li><p><code>pdflatex yourtext.tex</code> : this will create <code>yourtext.sagetex.sage</code>, and give warninges about undefined references.</p></li>
<li><p><code>sage yourtext.sagetex.sage</code>. This will, among other effects, update <code>yourtext.tex</code>.</p></li>
<li><p><code>pdflatex yourtext.tex</code> (usually, you have to do it twice).</p></li>
</ul>
<p><code>yourtext.pdf</code> is now the sought document...</p>
<p><strong>EDIT :</strong> The documenntation compiled in PDF form an an example tec=xt are available in <code>$SAGE_ROOT/local/share/doc/sagetex/</code>.</p>
<p>To recompile it (and get the indices) : in your installation, you have:</p>
<pre><code>(sage-sh) charpent@zen-book-flip:~$ ls $SAGE_ROOT/local/share/texmf/tex/latex/sagetex/
CONTRIBUTORS py-and-sty.dtx sagetex.dtx scripts.dtx
example.tex remote-sagetex.dtx sagetex.ins
extractsagecode.py remote-sagetex.py sagetexparse.py
makestatic.py run-sagetex-if-necessary.py sagetex.sty
</code></pre>
<p>Compiling <code>sagetex.dtx</code> with pdflatex (in a scratch directory) will give you instructions on how to compile both Sagetex and its documentation. More details <a href="https://en.wikibooks.org/wiki/LaTeX/Installing_Extra_Packages">here</a>.</p>
<p>This cannot be done automatically in Sage's installation, because it requires a (not inconsequential) functional installation of LaTeX, which is not a Sage dependency.</p>
<p>The fie <code>example.tex</code> is also quite instructive... Fiddle with it a bit.</p>
<p>HTH,</p>
https://ask.sagemath.org/question/51919/how-do-i-get-the-output-of-this-text-in-latex-with-sagetex/?comment=51928#post-id-51928I suppose you named your LaTeX file `sage.tex`, right ? So just do what you're instructed to do :
- Step 1 : `pdflatex sage.tex` gives you :
- a`sage.pdf` file with `[??]` marks in place of your Sage results, which are supposed to exist in files yet nonexistant.
- a `sage.sagetex.sage` file (as well as other files), which contain your Sage code (wrapped in execution instructions).
- Step 2 : `sage sage.sagetex.sage` will run this file through Sage, generating a bunch of `.tex` files containing your results.
- Step 3 `pdflatex sage.tex` will reconpile your tex file, where the references can now be obtained from the files created at step 2.
The new material added in step 2 may well change page, figure and table numbering, thus entailing further recompilation.Fri, 12 Jun 2020 23:26:33 +0200https://ask.sagemath.org/question/51919/how-do-i-get-the-output-of-this-text-in-latex-with-sagetex/?comment=51928#post-id-51928Comment by Moondoggy for <p><strong>EDIT:</strong> a good starting point is <a href="https://doc.sagemath.org/html/en/tutorial/sagetex.html">this documentation</a>.</p>
<p>Very roughly :</p>
<ul>
<li><p>create your text in LaTeX, interspeding Sage fragments as needed : this will be, say, <code>yourtext.tex</code>.</p></li>
<li><p><code>pdflatex yourtext.tex</code> : this will create <code>yourtext.sagetex.sage</code>, and give warninges about undefined references.</p></li>
<li><p><code>sage yourtext.sagetex.sage</code>. This will, among other effects, update <code>yourtext.tex</code>.</p></li>
<li><p><code>pdflatex yourtext.tex</code> (usually, you have to do it twice).</p></li>
</ul>
<p><code>yourtext.pdf</code> is now the sought document...</p>
<p><strong>EDIT :</strong> The documenntation compiled in PDF form an an example tec=xt are available in <code>$SAGE_ROOT/local/share/doc/sagetex/</code>.</p>
<p>To recompile it (and get the indices) : in your installation, you have:</p>
<pre><code>(sage-sh) charpent@zen-book-flip:~$ ls $SAGE_ROOT/local/share/texmf/tex/latex/sagetex/
CONTRIBUTORS py-and-sty.dtx sagetex.dtx scripts.dtx
example.tex remote-sagetex.dtx sagetex.ins
extractsagecode.py remote-sagetex.py sagetexparse.py
makestatic.py run-sagetex-if-necessary.py sagetex.sty
</code></pre>
<p>Compiling <code>sagetex.dtx</code> with pdflatex (in a scratch directory) will give you instructions on how to compile both Sagetex and its documentation. More details <a href="https://en.wikibooks.org/wiki/LaTeX/Installing_Extra_Packages">here</a>.</p>
<p>This cannot be done automatically in Sage's installation, because it requires a (not inconsequential) functional installation of LaTeX, which is not a Sage dependency.</p>
<p>The fie <code>example.tex</code> is also quite instructive... Fiddle with it a bit.</p>
<p>HTH,</p>
https://ask.sagemath.org/question/51919/how-do-i-get-the-output-of-this-text-in-latex-with-sagetex/?comment=51930#post-id-51930Now I have the file .sagetex.sout:
% This file was *autogenerated* from 2020-06-12-230428.sagetex.sage with
% sagetex.py version 2019/01/09 v3.3
%b138f8a4fc7b23f763cd933974ea7272% md5sum of corresponding .sage file (minus "goboom", "current_tex_line", and pause/unpause lines)Fri, 12 Jun 2020 23:32:07 +0200https://ask.sagemath.org/question/51919/how-do-i-get-the-output-of-this-text-in-latex-with-sagetex/?comment=51930#post-id-51930Comment by Emmanuel Charpentier for <p><strong>EDIT:</strong> a good starting point is <a href="https://doc.sagemath.org/html/en/tutorial/sagetex.html">this documentation</a>.</p>
<p>Very roughly :</p>
<ul>
<li><p>create your text in LaTeX, interspeding Sage fragments as needed : this will be, say, <code>yourtext.tex</code>.</p></li>
<li><p><code>pdflatex yourtext.tex</code> : this will create <code>yourtext.sagetex.sage</code>, and give warninges about undefined references.</p></li>
<li><p><code>sage yourtext.sagetex.sage</code>. This will, among other effects, update <code>yourtext.tex</code>.</p></li>
<li><p><code>pdflatex yourtext.tex</code> (usually, you have to do it twice).</p></li>
</ul>
<p><code>yourtext.pdf</code> is now the sought document...</p>
<p><strong>EDIT :</strong> The documenntation compiled in PDF form an an example tec=xt are available in <code>$SAGE_ROOT/local/share/doc/sagetex/</code>.</p>
<p>To recompile it (and get the indices) : in your installation, you have:</p>
<pre><code>(sage-sh) charpent@zen-book-flip:~$ ls $SAGE_ROOT/local/share/texmf/tex/latex/sagetex/
CONTRIBUTORS py-and-sty.dtx sagetex.dtx scripts.dtx
example.tex remote-sagetex.dtx sagetex.ins
extractsagecode.py remote-sagetex.py sagetexparse.py
makestatic.py run-sagetex-if-necessary.py sagetex.sty
</code></pre>
<p>Compiling <code>sagetex.dtx</code> with pdflatex (in a scratch directory) will give you instructions on how to compile both Sagetex and its documentation. More details <a href="https://en.wikibooks.org/wiki/LaTeX/Installing_Extra_Packages">here</a>.</p>
<p>This cannot be done automatically in Sage's installation, because it requires a (not inconsequential) functional installation of LaTeX, which is not a Sage dependency.</p>
<p>The fie <code>example.tex</code> is also quite instructive... Fiddle with it a bit.</p>
<p>HTH,</p>
https://ask.sagemath.org/question/51919/how-do-i-get-the-output-of-this-text-in-latex-with-sagetex/?comment=51931#post-id-51931That has been generated by Step 2, and contains (references to) your Sage results. They are referenced by the sagetex.tex file (via the `\sagexxx` macroes), and ill be read during Step 3. Go ahead !Fri, 12 Jun 2020 23:46:26 +0200https://ask.sagemath.org/question/51919/how-do-i-get-the-output-of-this-text-in-latex-with-sagetex/?comment=51931#post-id-51931Comment by Emmanuel Charpentier for <p><strong>EDIT:</strong> a good starting point is <a href="https://doc.sagemath.org/html/en/tutorial/sagetex.html">this documentation</a>.</p>
<p>Very roughly :</p>
<ul>
<li><p>create your text in LaTeX, interspeding Sage fragments as needed : this will be, say, <code>yourtext.tex</code>.</p></li>
<li><p><code>pdflatex yourtext.tex</code> : this will create <code>yourtext.sagetex.sage</code>, and give warninges about undefined references.</p></li>
<li><p><code>sage yourtext.sagetex.sage</code>. This will, among other effects, update <code>yourtext.tex</code>.</p></li>
<li><p><code>pdflatex yourtext.tex</code> (usually, you have to do it twice).</p></li>
</ul>
<p><code>yourtext.pdf</code> is now the sought document...</p>
<p><strong>EDIT :</strong> The documenntation compiled in PDF form an an example tec=xt are available in <code>$SAGE_ROOT/local/share/doc/sagetex/</code>.</p>
<p>To recompile it (and get the indices) : in your installation, you have:</p>
<pre><code>(sage-sh) charpent@zen-book-flip:~$ ls $SAGE_ROOT/local/share/texmf/tex/latex/sagetex/
CONTRIBUTORS py-and-sty.dtx sagetex.dtx scripts.dtx
example.tex remote-sagetex.dtx sagetex.ins
extractsagecode.py remote-sagetex.py sagetexparse.py
makestatic.py run-sagetex-if-necessary.py sagetex.sty
</code></pre>
<p>Compiling <code>sagetex.dtx</code> with pdflatex (in a scratch directory) will give you instructions on how to compile both Sagetex and its documentation. More details <a href="https://en.wikibooks.org/wiki/LaTeX/Installing_Extra_Packages">here</a>.</p>
<p>This cannot be done automatically in Sage's installation, because it requires a (not inconsequential) functional installation of LaTeX, which is not a Sage dependency.</p>
<p>The fie <code>example.tex</code> is also quite instructive... Fiddle with it a bit.</p>
<p>HTH,</p>
https://ask.sagemath.org/question/51919/how-do-i-get-the-output-of-this-text-in-latex-with-sagetex/?comment=51940#post-id-51940Check your compilation logs after each step. Also try it on this:
\documentclass{standalone} % Get a pdf file cropped around the printed portion.
\usepackage{sagetex}
\begin{document}
Sage tells us that $\displaystyle{\sage{arctan(x).integrate(x,hold=True)==arctan(x).integrate(x)}}$. Nice isn't it\,?
\end{document}Sat, 13 Jun 2020 10:26:46 +0200https://ask.sagemath.org/question/51919/how-do-i-get-the-output-of-this-text-in-latex-with-sagetex/?comment=51940#post-id-51940