code: def format_document(
      doc: Document, keep_refs: bool = False
  ) -> Tuple[str, Dict[str, str]]:
      """
      The `format_document` function takes a `doc` object of type `Document` and a boolean `keep_refs` as input and returns a tuple containing the formatted text of the document and a dictionary of figures found in the document.
  
      :param doc: The `doc` parameter is of type `Document`, which is presumably a custom class representing a document
      :type doc: Document
      :param keep_refs: The `keep_refs` parameter is a boolean flag that determines whether to keep references in the formatted document or not. If `keep_refs` is set to `True`, the references will be included in the formatted document. If `keep_refs` is set to `False`, the references will be excluded, defaults to False
      :type keep_refs: bool (optional)
      :return: The function `format_document` returns a tuple containing two elements: a formatted text document and a dictionary of figures.
      """
      parts = []
  
      if doc.title:
          parts.extend([*format_element(doc.title), "\n"])
      parts.append("\n")
      parts.extend(format_children(doc, keep_refs))
      text = "".join(parts)
      text = text.replace("\xa0", " ")  # replace non-breakable spaces
      text = re.sub(r" $", "", text, flags=re.MULTILINE)
      text = re.sub(r"\n[\t ]*$", "\n", text, flags=re.MULTILINE)
      text = re.sub(r"(?<!\n) {2,}", " ", text)
      text = re.sub(r"\n{3,}", "\n\n", text).lstrip()
      figures = {
          unidecode(m[0] + m[1]): m[2].strip()
          for m in figure_regex.findall(text)
      }
      text = figure_regex.sub(
          r"[\1\2][END\1]",
          text,
      )
      return text, figures
  
file_path: nougat/nougat/dataset/parser/markdown.py
imports: from typing import Iterable, List, Optional, Tuple
  import re
  from uuid import uuid4
  from nougat.dataset.utils import normalize_tex
  from nougat.dataset.parser.document import *
  from nougat.dataset.parser.latexml_parser import _clean_html_whitespace
  from unidecode import unidecode
label_desc: Use image node_id 9 for calling a global function with example usage: format_document(doc, keep_refs) and returns: text,  figures