code: def normalize_tex(math: str, inline: bool) -> str:
      """
      Normalize TeX math expressions.
  
      This function takes a TeX math expression and performs various normalization steps to ensure
      consistency and proper formatting.
  
      Args:
          math (str): The input TeX math expression.
          inline (bool): Indicates whether the expression should be inline (True) or displayed (False).
  
      Returns:
          str: The normalized TeX math expression.
      """
      math = math.strip()
      if not math:
          return ""
      if (
          math.startswith(r"\(")
          or math.startswith(r"\[")
          or math.startswith("$$")
      ):
          math = math[2:]
      elif math.startswith("$"):
          math = math[1:]
      if (
          math.endswith(r"\)")
          or math.endswith(r"\]")
          or math.endswith("$$")
      ):
          math = math[:-2]
      elif math.endswith("$"):
          math = math[:-1]
      math = math.strip()
      if not math:
          return ""
      math = remove_line_breaks(math.strip())
      math = replace_duplicate_definitions(math)
      math = remove_style(math)
      if inline:
          return rf"\({math}\)"
      return rf"\[{math}\]"
  
file_path: nougat/nougat/dataset/utils/latex_conversion.py
imports: import re
  from pylatexenc.latexencode import UnicodeToLatexEncoder
  from pylatexenc.latex2text import LatexNodes2Text
  from unidecode import unidecode
label_desc: Use image node_id 5 for calling a global function with example usage: normalize_tex(math, inline) and returns: str, math, str, str, str, str, math, str