Ask Your Question
0

Problems with AMS symbols in Sage, Jupyter

asked 2019-10-12 09:42:12 -0600

SYLA gravatar image

How to display the square (\square) symbol in a graph (Jupyter, maybe not only). Why \boxtimes is too large?

plot(x, (x,-1,10), axes_labels=[r'$F(G\,\square\,H)$',r'$F(G\,\times\,H)$']).show()

plot(x, (x,-1,10), axes_labels=[r'$F(G\,\square\,H)$',r'$F(G\,\times\,H)$']).show()

I tried \box \square \emptybox etc. and

from sage.misc.latex import latex_extra_preamble
latex.add_to_preamble('\\usepackage{amssymb}')

I get:

ValueError: F(G\,\square\,H) ^ Unknown symbol: \square (at char 5), (line:1, col:6)

edit retag flag offensive close merge delete

Comments

kcrisman gravatar imagekcrisman ( 2019-10-18 06:39:29 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
1

answered 2019-10-15 10:33:08 -0600

dsejas gravatar image

Hello, @SYLA. As SageMath uses Matplotlib as its backend for plotting, you should import the amssymb package using Matplotlib itself. The only way I can find to do this is the following:

from matplotlib import rc
rc('text', usetex=True)
rc('text.latex', preamble=r'\usepackage{amssymb}')
plot(x, (x,-1,10), axes_labels=[r'$F(G\,\square\,H)$',r'$F(G\,\times\,H)$']).show()

Here is the result: Your expected result

First, we import rc from Matplotlib, which is used to specify configurations. In the second line, we use rc to specify the use of LaTeX as default renderer for text. The third line indicates that we want to add the amssymb package, which defines the \square command you need. Finally, we use Sage's command for plotting.

The interesting thing is that Sage first processes the plot command, and then passes it to Matplotlib for plotting, and that is when our new configurations take effect.

I hope this helps!

edit flag offensive delete link more

Comments

That is a very interesting answer. Should this maybe be reported as a bug in Sage so that people can pass more options to plot?

kcrisman gravatar imagekcrisman ( 2019-10-18 06:38:54 -0600 )edit

Hello, @kcrisman. I agree, it should be reported as a bug. However, I would like to wait a little in order to see if an alternative is proposed. Maybe there is some command for this purpose which I am not aware of. I would like to ask @john-palmieri or any of the experts in Sage about this, before posting a bug report.

dsejas gravatar imagedsejas ( 2019-10-18 11:19:57 -0600 )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

1 follower

Stats

Asked: 2019-10-12 09:42:12 -0600

Seen: 52 times

Last updated: Oct 15