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.Tue, 24 Feb 2015 07:46:29 +0100How do I use a sage graph in LaTEX?https://ask.sagemath.org/question/25896/how-do-i-use-a-sage-graph-in-latex/I created a project in Sage that graphed multiple curves at once. Is there a way I can just import this graph or the code into LaTEX?Mon, 23 Feb 2015 04:42:20 +0100https://ask.sagemath.org/question/25896/how-do-i-use-a-sage-graph-in-latex/Answer by dazedANDconfused for <p>I created a project in Sage that graphed multiple curves at once. Is there a way I can just import this graph or the code into LaTEX?</p>
https://ask.sagemath.org/question/25896/how-do-i-use-a-sage-graph-in-latex/?answer=25902#post-id-25902Suppose you plot the sine function in Sage:
plot(sin(x), (x, 0, 2*pi))
and you want to save the picture. First, call the plot something:
plt = plot(sin(x), (x, 0, 2*pi))
And now save it as a pdf:
plt.save("MyPic.pdf")
The tex engine you use will determine how you save your picture. Many people use pdflatex as the engine, in which case the pdf format is fine. If you are using a regular latex engine then eps, rather than pdf, is expected. The different options, and the process of including the picture using the graphicx package are covered in the LaTeX Wikibooks [here](https://en.wikibooks.org/wiki/LaTeX/Importing_Graphics). The [sagetex package](http://www.ctan.org/tex-archive/macros/latex/contrib/sagetex/) provides another way of getting your image in without saving. It lets you run Sage code when you use LaTeX--see the documentation on how to use it. But you need both LaTeX and Sage on your computer. Unless you're using [Sagemath Cloud](https://cloud.sagemath.com/), getting Sage and LaTeX set up to communicate on your PC can be a hassle.Tue, 24 Feb 2015 02:07:30 +0100https://ask.sagemath.org/question/25896/how-do-i-use-a-sage-graph-in-latex/?answer=25902#post-id-25902Comment by ecain17 for <p>Suppose you plot the sine function in Sage:</p>
<pre><code>plot(sin(x), (x, 0, 2*pi))
</code></pre>
<p>and you want to save the picture. First, call the plot something:</p>
<pre><code>plt = plot(sin(x), (x, 0, 2*pi))
</code></pre>
<p>And now save it as a pdf:</p>
<pre><code>plt.save("MyPic.pdf")
</code></pre>
<p>The tex engine you use will determine how you save your picture. Many people use pdflatex as the engine, in which case the pdf format is fine. If you are using a regular latex engine then eps, rather than pdf, is expected. The different options, and the process of including the picture using the graphicx package are covered in the LaTeX Wikibooks <a href="https://en.wikibooks.org/wiki/LaTeX/Importing_Graphics">here</a>. The <a href="http://www.ctan.org/tex-archive/macros/latex/contrib/sagetex/">sagetex package</a> provides another way of getting your image in without saving. It lets you run Sage code when you use LaTeX--see the documentation on how to use it. But you need both LaTeX and Sage on your computer. Unless you're using <a href="https://cloud.sagemath.com/">Sagemath Cloud</a>, getting Sage and LaTeX set up to communicate on your PC can be a hassle.</p>
https://ask.sagemath.org/question/25896/how-do-i-use-a-sage-graph-in-latex/?comment=25904#post-id-25904Thank you for the answer. I use texmaker as my complier. So I use plt.save("MyPic.pdf") and then how do I put it into texmaker?Tue, 24 Feb 2015 05:41:40 +0100https://ask.sagemath.org/question/25896/how-do-i-use-a-sage-graph-in-latex/?comment=25904#post-id-25904Comment by dazedANDconfused for <p>Suppose you plot the sine function in Sage:</p>
<pre><code>plot(sin(x), (x, 0, 2*pi))
</code></pre>
<p>and you want to save the picture. First, call the plot something:</p>
<pre><code>plt = plot(sin(x), (x, 0, 2*pi))
</code></pre>
<p>And now save it as a pdf:</p>
<pre><code>plt.save("MyPic.pdf")
</code></pre>
<p>The tex engine you use will determine how you save your picture. Many people use pdflatex as the engine, in which case the pdf format is fine. If you are using a regular latex engine then eps, rather than pdf, is expected. The different options, and the process of including the picture using the graphicx package are covered in the LaTeX Wikibooks <a href="https://en.wikibooks.org/wiki/LaTeX/Importing_Graphics">here</a>. The <a href="http://www.ctan.org/tex-archive/macros/latex/contrib/sagetex/">sagetex package</a> provides another way of getting your image in without saving. It lets you run Sage code when you use LaTeX--see the documentation on how to use it. But you need both LaTeX and Sage on your computer. Unless you're using <a href="https://cloud.sagemath.com/">Sagemath Cloud</a>, getting Sage and LaTeX set up to communicate on your PC can be a hassle.</p>
https://ask.sagemath.org/question/25896/how-do-i-use-a-sage-graph-in-latex/?comment=25905#post-id-25905You'd create the picture using Sage. After running Sage, it would create the MyPic.pdf file. Place that in the file where your LaTeX document is. Make sure you've included the graphicx package in your latex preamble and then \includegraphics{MyPic.pdf} as explained in detail [here](https://en.wikibooks.org/wiki/LaTeX/Importing_Graphics).Tue, 24 Feb 2015 06:42:01 +0100https://ask.sagemath.org/question/25896/how-do-i-use-a-sage-graph-in-latex/?comment=25905#post-id-25905Comment by ecain17 for <p>Suppose you plot the sine function in Sage:</p>
<pre><code>plot(sin(x), (x, 0, 2*pi))
</code></pre>
<p>and you want to save the picture. First, call the plot something:</p>
<pre><code>plt = plot(sin(x), (x, 0, 2*pi))
</code></pre>
<p>And now save it as a pdf:</p>
<pre><code>plt.save("MyPic.pdf")
</code></pre>
<p>The tex engine you use will determine how you save your picture. Many people use pdflatex as the engine, in which case the pdf format is fine. If you are using a regular latex engine then eps, rather than pdf, is expected. The different options, and the process of including the picture using the graphicx package are covered in the LaTeX Wikibooks <a href="https://en.wikibooks.org/wiki/LaTeX/Importing_Graphics">here</a>. The <a href="http://www.ctan.org/tex-archive/macros/latex/contrib/sagetex/">sagetex package</a> provides another way of getting your image in without saving. It lets you run Sage code when you use LaTeX--see the documentation on how to use it. But you need both LaTeX and Sage on your computer. Unless you're using <a href="https://cloud.sagemath.com/">Sagemath Cloud</a>, getting Sage and LaTeX set up to communicate on your PC can be a hassle.</p>
https://ask.sagemath.org/question/25896/how-do-i-use-a-sage-graph-in-latex/?comment=25907#post-id-25907Thank you I got it to work!Tue, 24 Feb 2015 07:46:29 +0100https://ask.sagemath.org/question/25896/how-do-i-use-a-sage-graph-in-latex/?comment=25907#post-id-25907