code: def split_texts_by_positions(
      texts,
      positions,
      direction,
      alignment="high",
      discard_empty_sections=True,
      enrich_with_positions=False,
  ):
      """
      Split textboxes in <texts> into sections according to <positions> either horizontally or vertically (depending on
      <direction>.)
  
      <alignment> must be one of ('low', 'middle', 'high') and is used to determine the text box border (or center
      for 'middle') to use for checking if this text box is inside of a section
  
      <positions> must be sorted from low to high!
      """
      if direction not in (DIRECTION_HORIZONTAL, DIRECTION_VERTICAL):
          raise ValueError(
              "direction must be  DIRECTION_HORIZONTAL or DIRECTION_VERTICAL (see pdftabextract.common)"
          )
  
      if alignment not in ("low", "middle", "high"):
          raise ValueError("alignment must be  'low' or 'high'")
  
      if len(positions) == 0:
          raise ValueError("positions must be non-empty sequence")
  
      if alignment != "middle":
          if direction == DIRECTION_VERTICAL:
              attr = "bottom" if alignment == "high" else "top"
          else:
              attr = "right" if alignment == "high" else "left"
          t_in_section = lambda t, p1, p2: p1 < t[attr] <= p2
      else:
          if direction == DIRECTION_VERTICAL:
              t_in_section = (
                  lambda t, p1, p2: p1
                  < t["top"] + t["height"] / 2
                  <= p2
              )
          else:
              t_in_section = (
                  lambda t, p1, p2: p1
                  < t["left"] + t["width"] / 2
                  <= p2
              )
  
      prev_pos = -1
      split_texts = []
      n_added_texts = 0
      for pos in positions:
          texts_in_section = [
              t for t in texts if t_in_section(t, prev_pos, pos)
          ]
  
          if texts_in_section or not discard_empty_sections:
              if enrich_with_positions:
                  to_append = (texts_in_section, (prev_pos, pos))
              else:
                  to_append = texts_in_section
              split_texts.append(to_append)
              n_added_texts += len(texts_in_section)
  
          prev_pos = pos
  
      assert n_added_texts == len(texts)
  
      return split_texts
  
file_path: pdftabextract/pdftabextract/textboxes.py
imports: import math
  import numpy
  from pdftabextract.common import update_text_dict_pos, sorted_by_attr, DIRECTION_HORIZONTAL, DIRECTION_VERTICAL, SKEW_X, SKEW_Y
  from pdftabextract.geom import pt, vecrotate
label_desc: Use image node_id 2 for calling a global function with example usage: split_texts_by_positions(texts, positions, direction, alignment, discard_empty_sections, enrich_with_positions) and returns: split_texts