# Using quotes inside sageplot environment in SageTeX

Here's the question: how do I get the following to work in SageTeX? The quotes always lead to an error.

\sageplot{plot(cos(x),(x,0,pi),label='$\cos(x)$')}


Double quotes, escaping them, ... nothing seems to work.

-
if you press the sagetex tag and please submit a small description of what it does and can it would be nice. In that way people can read of what it actually does. I have no experience in it so have simply created the tag. –  zeroth Apr 6 '12 at 17:01
add comment

## 1 Answer

I don't know enough to tell you what's going on, but this works:

\documentclass{article}
\usepackage{sagetex}
\begin{document}
\pagestyle{empty}
\begin{sagesilent}
G=Graphics()
var('x')
G+=plot(cos(x),(x,0,pi),label='$\cos(x)$')
\end{sagesilent}
$\sageplot{G}$
\end{document}


Note, to get even more control over the placement of your text label try this:

\documentclass{article}
\usepackage{sagetex}
\begin{document}
\pagestyle{empty}
\begin{sagesilent}
G=Graphics()
H=Graphics()
var('x')
G+=plot(cos(x),(x,0,pi))
H+= text("$\cos(x)$", (3, 1), fontsize=16, color='black')
\end{sagesilent}
$\sageplot{G+H}$
\end{document}


The people at AskSage will know what's best. Here's output from the first set of code:

-
Unfortunately, I am "one of the people at AskSage" :) so that's why I came here, thanks for pointing out that one can compute in a sagesilent and then just plot that. –  kcrisman Apr 10 '12 at 15:12
I'm not worried about text placement, the real issue was the quotes not working. There must be something wrong with the parser for sageplot. Incidentally, you should be able to remove the whole extra Graphics() and var incantations and just directly do G = plot..., since x is predefined and all plots begin with empty graphics objects. –  kcrisman Apr 10 '12 at 15:12
In that case, you might be interested in knowing that I didn't get an error when I processed the .sage file resulting from your sageplot using Sage version 4.7. But when I ran LaTeX the second time I ended up getting a garbage label: instead of cos(x) it was $' on one line and oli and part of an "n" on the next line. Strange. – DJP Apr 11 '12 at 0:30 Mysteriouser and mysteriouser. Because that means the real problem is in the TeXShop engine, maybe - I used %!TEX TS-program = sage and it was during the LaTeX stage that I had problems; it never actually got to Sage. I assumed this was a SageTeX problem but apparently that was mistaken. – kcrisman Apr 11 '12 at 5:09 I tried TeXShop, Kile, LaTeXilla, Gummi, and TeXmaker and got the some output. When I tried highlighting the PDF where the garbage label was, a lot of text became visible (but crushed together); something like$\mathop{\mathgroup\symoperatorscos} and on the next line dimit. If a screenshot or the PDF file will be helpful in tracking down the problem, let me know. –  DJP Apr 11 '12 at 23:13
add comment