#NEWLINE# def math_to_image( s , filename_or_obj , prop = None , dpi = None , format = None ) : #NEWLINE# #INDENT# "\n    Given a math expression, renders it in a closely-clipped bounding\n    box to an image file.\n\n    *s*\n       A math expression.  The math portion should be enclosed in\n       dollar signs.\n\n    *filename_or_obj*\n       A filepath or writable file-like object to write the image data\n       to.\n\n    *prop*\n       If provided, a FontProperties() object describing the size and\n       style of the text.\n\n    *dpi*\n       Override the output dpi, otherwise use the default associated\n       with the output format.\n\n    *format*\n       The output format, eg. 'svg', 'pdf', 'ps' or 'png'.  If not\n       provided, will be deduced from the filename.\n    " #NEWLINE# from matplotlib import figure #NEWLINE# from matplotlib.backends import backend_agg #NEWLINE# from matplotlib.font_manager import FontProperties #NEWLINE# from matplotlib.mathtext import MathTextParser #NEWLINE# if ( prop is None ) : #NEWLINE# #INDENT# prop = FontProperties ( ) #NEWLINE# #UNINDENT# parser = MathTextParser ( 'path' ) #NEWLINE# ( width , height , depth , _ , _ ) = parser . parse ( s , dpi = 72 , prop = prop ) #NEWLINE# fig = figure . Figure ( figsize = ( ( width / 72.0 ) , ( height / 72.0 ) ) ) #NEWLINE# fig . text ( 0 , ( depth / height ) , s , fontproperties = width ) #NEWLINE# backend_agg . FigureCanvasAgg ( fig ) #NEWLINE# fig . savefig ( filename_or_obj , dpi = dpi , format = format ) #NEWLINE# return depth