Ask Your Question
2

LaTeX in plot not showing Greek letter

asked 2014-12-10 20:22:46 +0100

mathochist gravatar image

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 flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
5

answered 2014-12-10 20:39:07 +0100

slelievre gravatar image

updated 2014-12-11 13:31:08 +0100

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

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!

edit flag offensive delete link more

Comments

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

kcrisman gravatar imagekcrisman ( 2014-12-10 21:00:02 +0100 )edit

Second kcrisman -- I can't upvote yet but this solution is brilliant -- the kind of "Should have known! How did I not ..."(no, I know about escaping characters, but I would not have come up with this by myself).

Christian Roettger gravatar imageChristian Roettger ( 2024-10-08 15:09:30 +0100 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

2 followers

Stats

Asked: 2014-12-10 20:22:46 +0100

Seen: 2,033 times

Last updated: Dec 11 '14