Using the python library matplotlib, I've found what suggests to be a solution to this question:
Displaying (nicely) an algebraic expression in PyQt by utilising matplotlibs TeX markup.
What I'd like to do is take TeX code from my python program which represents a mathematical expression, and save it to an image that can be displayed in my PyQt GUI, rather than displaying the equation in ugly plain text.
Something like this essentially...
import matplotlib.pyplot as plt
formula = '$x=3^2$'
fig = plt.figure()
fig.text(0,0,formula)
fig.savefig('formula.png')
However, the pyplot module is primarily for displaying graphs and plots, not the samples of text like I need. The result of that code is usually a tiny bit of text in the bottom left corner of a huge, white, blank image.
If my formula involves fractions, and thus requires downward space, it is truncated, like in the image below.
Note that this appears a blank image; look to the left side of the display
Fraction at coordinate (0,0) truncated and surrounded by whitespace
I believe I could create a very large (space wise) figure, write the formula in the middle of the blank plot, save it, and use pixel analysis to trim it to as small an image as possible, but this seems rather crude.
Are plots the only intended output of matplotlib?
Is there nothing devoted to just outputting equations, that won't require me to worry about all the extra space or position of the text?
Thanks!