# 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.

edit retag close merge delete

Sort by » oldest newest most voted

In 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$".

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!

more

I 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.)

( 2014-12-10 14:00:02 -0500 )edit