def math_to_image(s, filename_or_obj, prop=None, dpi=None, format=None):
from matplotlib import figure<EOL>from matplotlib.backends import backend_agg<EOL>from matplotlib.font_manager import FontProperties<EOL>from matplotlib.mathtext import MathTextParser<EOL>if prop is None:<EOL><INDENT>prop = FontProperties()<EOL><DEDENT>parser = MathTextParser('<STR_LIT:path>')<EOL>width, height, depth, _, _ = parser.parse(s, dpi=<NUM_LIT>, prop=prop)<EOL>fig = figure.Figure(figsize=(width / <NUM_LIT>, height / <NUM_LIT>))<EOL>fig.text(<NUM_LIT:0>, depth/height, s, fontproperties=prop)<EOL>backend_agg.FigureCanvasAgg(fig)<EOL>fig.savefig(filename_or_obj, dpi=dpi, format=format)<EOL>return depth<EOL>
Given a math expression, renders it in a closely-clipped bounding
box to an image file.

*s*
   A math expression.  The math portion should be enclosed in
   dollar signs.

*filename_or_obj*
   A filepath or writable file-like object to write the image data
   to.

*prop*
   If provided, a FontProperties() object describing the size and
   style of the text.

*dpi*
   Override the output dpi, otherwise use the default associated
   with the output format.

*format*
   The output format, eg. 'svg', 'pdf', 'ps' or 'png'.  If not
   provided, will be deduced from the filename.