title: Creating images of mathematical expressions from TeX, using matplotlib
body: <p>Using the python library matplotlib, I've found what suggests to be a solution to this question:<br>
  <a href="https://stackoverflow.com/questions/14097463/displaying-nicely-an-algebraic-expression-in-pyqt">Displaying (nicely) an algebraic expression in PyQt</a> by utilising matplotlibs <a href="http://matplotlib.org/users/mathtext.html" rel="nofollow noreferrer">TeX markup</a>.</p>
  
  <p>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.</p>
  
  <p>Something like this essentially...</p>
  
  <pre><code>import matplotlib.pyplot as plt
  formula = '$x=3^2$'
  
  fig = plt.figure()
  fig.text(0,0,formula)
  fig.savefig('formula.png')
  </code></pre>
  
  <p>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.<br>
  If my formula involves fractions, and thus requires downward space, it is truncated, like in the image below.</p>
  
  <p><strong>Note that this appears a blank image; look to the left side of the display</strong><br>
  <a href="https://i.stack.imgur.com/gbxek.png" rel="nofollow noreferrer">Fraction at coordinate (0,0) truncated and surrounded by whitespace</a></p>
  
  <p>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.</p>
  
  <p>Are plots the only intended output of matplotlib?<br>
  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?</p>
  
  <p>Thanks!</p>