Loading [MathJax]/jax/output/HTML-CSS/jax.js

First time here? Check out the FAQ!

Ask Your Question
2

LaTeX in plot not showing Greek letter

asked 10 years ago

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

Preview: (hide)

1 Answer

Sort by » oldest newest most voted
5

answered 10 years ago

slelievre gravatar image

updated 10 years ago

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!

Preview: (hide)
link

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 ( 10 years ago )

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 ( 0 years ago )

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: 10 years ago

Seen: 2,096 times

Last updated: Dec 11 '14