def latex_to_png(s, encode=False, backend=None, wrap=False):
 s = cast_unicode(s)
 allowed_backends = LaTeXTool.instance().backends
 if (backend is None):
  backend = allowed_backends[0]
 if (backend not in allowed_backends):
  return None
 if (backend == 'matplotlib'):
  f = latex_to_png_mpl
 elif (backend == 'dvipng'):
  f = latex_to_png_dvipng
 else:
  raise ValueError('No such backend {0}'.format(backend))
 bin_data = f(s, wrap)
 if (encode and bin_data):
  bin_data = encodebytes(bin_data)
 return bin_data

def latex_to_png ( s , encode = False , backend = None , wrap = False ) : s = cast_unicode ( s ) allowed_backends = LaTeXTool . instance ( ) . backends if ( backend is None ) : backend = allowed_backends [ 0 ] if ( backend not in allowed_backends ) : return None if ( backend == 'matplotlib' ) : f = latex_to_png_mpl elif ( backend == 'dvipng' ) : f = latex_to_png_dvipng else : raise ValueError ( 'No such backend {0}' . format ( backend ) ) bin_data = f ( s , wrap ) if ( encode and bin_data ) : bin_data = encodebytes ( bin_data ) return bin_data
render a latex string to png .