code: def latex_to_png(s, encode=False, backend=None, wrap=False):
      """Render a LaTeX string to PNG.
  
      Parameters
      ----------
      s : str
          The raw string containing valid inline LaTeX.
      encode : bool, optional
          Should the PNG data base64 encoded to make it JSON'able.
      backend : {matplotlib, dvipng}
          Backend for producing PNG data.
      wrap : bool
          If true, Automatically wrap `s` as a LaTeX equation.
  
      None is returned when the backend cannot be used.
  
      """
      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
  
file_path: catboost/contrib/python/ipython/py2/IPython/lib/latextools.py
imports: from io import BytesIO, open
  import os
  import tempfile
  import shutil
  import subprocess
  from IPython.utils.process import find_cmd, FindCmdError
  from traitlets.config import get_config
  from traitlets.config.configurable import SingletonConfigurable
  from traitlets import List, Bool, Unicode
  from IPython.utils.py3compat import cast_unicode, cast_unicode_py2, PY3
label_desc: Use image node_id 1 for calling a global function with example usage: latex_to_png(s, encode, backend, wrap) and returns: bin_data, None