code: def find_page_equation_regions(pnum, page, block_types):
      i = 0
      equation_boxes = [
          b.bbox for b in block_types[pnum] if b.block_type == "Formula"
      ]
      reformatted_blocks = set()
      reformat_regions = []
      block_lens = []
      while i < len(page.blocks):
          block = page.blocks[i]
          block_text = block.prelim_text
          bbox = block.bbox
          # Check if the block contains an equation
          if not block.contains_equation(equation_boxes):
              i += 1
              continue
  
          selected_blocks = [(i, block)]
          if i > 0:
              # Find previous blocks to merge
              j = i - 1
              prev_block = page.blocks[j]
              prev_bbox = prev_block.bbox
              while (
                  (
                      should_merge_blocks(prev_bbox, bbox)
                      or prev_block.contains_equation(equation_boxes)
                  )
                  and j >= 0
                  and j not in reformatted_blocks
              ):
                  bbox = merge_boxes(prev_bbox, bbox)
                  prev_block = page.blocks[j]
                  prev_bbox = prev_block.bbox
                  prelim_block_text = (
                      prev_block.prelim_text + " " + block_text
                  )
                  if (
                      get_total_texify_tokens(prelim_block_text)
                      >= settings.TEXIFY_MODEL_MAX
                  ):
                      break
  
                  block_text = prelim_block_text
                  selected_blocks.append((j, prev_block))
                  j -= 1
  
          if i < len(page.blocks) - 1:
              # Merge subsequent boxes
              next_block = page.blocks[i + 1]
              next_bbox = next_block.bbox
              while (
                  should_merge_blocks(bbox, next_bbox)
                  or next_block.contains_equation(equation_boxes)
              ) and i + 1 < len(page.blocks):
                  bbox = merge_boxes(bbox, next_bbox)
                  prelim_block_text = (
                      block_text + " " + next_block.prelim_text
                  )
                  if (
                      get_total_texify_tokens(prelim_block_text)
                      >= settings.TEXIFY_MODEL_MAX
                  ):
                      break
  
                  block_text = prelim_block_text
                  i += 1
                  selected_blocks.append((i, next_block))
                  if i + 1 < len(page.blocks):
                      next_block = page.blocks[i + 1]
                      next_bbox = next_block.bbox
  
          total_tokens = get_total_texify_tokens(block_text)
          ordered_blocks = sorted(([sb[0] for sb in selected_blocks]))
          if total_tokens < settings.TEXIFY_MODEL_MAX:
              # Get indices of all blocks to merge
              reformat_regions.append(ordered_blocks)
              block_lens.append(total_tokens)
              reformatted_blocks.update(ordered_blocks)
          else:
              # Reset i to the original value
              i = selected_blocks[0][0]
  
          i += 1
  
      return reformat_regions, block_lens
  
imports: import io
  from copy import deepcopy
  from functools import partial
  from typing import List
  import torch
  from texify.inference import batch_inference
  from texify.model.model import load_model
  from texify.model.processor import load_processor
  import re
  from PIL import Image, ImageDraw
  from marker.bbox import should_merge_blocks, merge_boxes
  from marker.debug.data import dump_equation_debug_data
  from marker.settings import settings
  from marker.schema import Page, Span, Line, Block, BlockType
  import os
label_desc: Use image node_id 6 for calling a global function with example usage: find_page_equation_regions(pnum, page, block_types) and returns: reformat_regions,  block_lens