A problem rendering text in 2d graphics; but whose problem is it?

asked 2022-10-21 17:43:00 +0200

richardquint gravatar image

updated 2022-10-21 20:31:17 +0200

I've run into a problem with the placement of LaTeX formatted text in 2d Graphics objects. The center point of the text object is incorrectly calculated when saving to an SVG file. There is no problem with PNG or PDF output. Here's a Sage script for creating an example.

from matplotlib import rc
rc('text', usetex=True)
A=text(r"$\textrm{XOOOOXOOOO}$",\
        (1,1),\
        fontsize=5,\
        color="red")\
        +\
    text(r"$\textrm{XOOOOXOOOOX}$",\
        (1,1),\
        fontsize=5,\
        color="green",\
        rotation=(90))\
        +\
    text(r"$\textrm{XOOOOXOOOOX}$",\
        (1,1),\
        fontsize=5,\
        color="blue",\
        rotation=(45))\
        +\
        circle((0,0), sqrt(2), color="black")\
        +\
        line([(-2,-2),(2,2)], color="black")
A.save("SP.svg")
A.save("SP.png")
A.save("SP.pdf")

I'm running SageMath 9.7 using Python 3.10.5. (I don't have enough Karma to attach the output as images.)

Is the SVG renderer the problem or is it my use of text mode inside math mode over reaching to achieve the effect of using TeX fonts?

edit retag flag offensive close merge delete