code: def parse_latex(sympy, strict=False):
      antlr4 = import_module("antlr4")
  
      if None in [antlr4, MathErrorListener] or not version(
          "antlr4-python3-runtime"
      ).startswith("4.11"):
          raise ImportError(
              "LaTeX parsing requires the antlr4 Python package,"
              " provided by pip (antlr4-python3-runtime) or"
              " conda (antlr-python-runtime), version 4.11"
          )
  
      sympy = sympy.strip()
      matherror = MathErrorListener(sympy)
  
      stream = antlr4.InputStream(sympy)
      lex = LaTeXLexer(stream)
      lex.removeErrorListeners()
      lex.addErrorListener(matherror)
  
      tokens = antlr4.CommonTokenStream(lex)
      parser = LaTeXParser(tokens)
  
      # remove default console error listener
      parser.removeErrorListeners()
      parser.addErrorListener(matherror)
  
      relation = parser.math().relation()
      if strict and (
          relation.start.start != 0
          or relation.stop.stop != len(sympy) - 1
      ):
          raise LaTeXParsingError("Invalid LaTeX")
      expr = convert_relation(relation)
  
      return expr
  
imports: from importlib.metadata import version
  import sympy
  from sympy.external import import_module
  from sympy.printing.str import StrPrinter
  from sympy.physics.quantum.state import Bra, Ket
  from .errors import LaTeXParsingError
label_desc: Use image node_id 1 for calling a global function with example usage: parse_latex(sympy, strict) and returns: expr