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.Wed, 10 Dec 2014 21:00:02 +0100LaTeX in plot not showing Greek letterhttps://ask.sagemath.org/question/25209/latex-in-plot-not-showing-greek-letter/ Hello. I'm using the following code to generate an image of a triangle for a trigonometry quiz.
p = polygon2d([[0,0], [0,3], [4,0]], fill = False, axes = False)
p += text("$\theta$", (3, 0.2), fontsize = 22)
show(p)
The issue is that Sage doesn't seem to recognise $\theta$ as LaTeX, even though it's in dollar signs. In the corner of the triangle, it puts "heta". Why isn't this typesetting correctly? How can I fix it?
Thank you.Wed, 10 Dec 2014 20:22:46 +0100https://ask.sagemath.org/question/25209/latex-in-plot-not-showing-greek-letter/Answer by slelievre for <p>Hello. I'm using the following code to generate an image of a triangle for a trigonometry quiz.</p>
<pre><code>p = polygon2d([[0,0], [0,3], [4,0]], fill = False, axes = False)
p += text("$\theta$", (3, 0.2), fontsize = 22)
show(p)
</code></pre>
<p>The issue is that Sage doesn't seem to recognise $\theta$ as LaTeX, even though it's in dollar signs. In the corner of the triangle, it puts "heta". Why isn't this typesetting correctly? How can I fix it?</p>
<p>Thank you.</p>
https://ask.sagemath.org/question/25209/latex-in-plot-not-showing-greek-letter/?answer=25210#post-id-25210In the string `"$\theta$"`, the group `\t` becomes a tab.
You can escape the backslash this way: `"$\\theta$"`.
But it is more convenient to use a raw string: `r"$\theta$"`.
So your code becomes:
p = polygon2d([[0,0], [0,3], [4,0]], fill = False, axes = False)
p += text(r"$\theta$", (3, 0.2), fontsize = 22)
show(p)
Use this trick whenever you have text containing `\`, which is often the case if your text is latex code!Wed, 10 Dec 2014 20:39:07 +0100https://ask.sagemath.org/question/25209/latex-in-plot-not-showing-greek-letter/?answer=25210#post-id-25210Comment by kcrisman for <p>In the string <code>"$\theta$"</code>, the group <code>\t</code> becomes a tab.</p>
<p>You can escape the backslash this way: <code>"$\\theta$"</code>.</p>
<p>But it is more convenient to use a raw string: <code>r"$\theta$"</code>.</p>
<p>So your code becomes:</p>
<pre><code>p = polygon2d([[0,0], [0,3], [4,0]], fill = False, axes = False)
p += text(r"$\theta$", (3, 0.2), fontsize = 22)
show(p)
</code></pre>
<p>Use this trick whenever you have text containing <code>\</code>, which is often the case if your text is latex code!</p>
https://ask.sagemath.org/question/25209/latex-in-plot-not-showing-greek-letter/?comment=25212#post-id-25212I want to give this more than one up vote! (I mean without messing with the admin panel.) I must have answered this very question 10 times at AIMS, and it happens to me at least once a semester as well. I wonder where a good place to document this would be? (Since our FAQ is moribund - though that would be a pretty good place.)Wed, 10 Dec 2014 21:00:02 +0100https://ask.sagemath.org/question/25209/latex-in-plot-not-showing-greek-letter/?comment=25212#post-id-25212