code: def count_special_chars(string: str, char_ind: int) -> int:
      if len(string) == 0:
          return 0
      add_space_ind = 0
      while True:
          string_ = string[: char_ind + add_space_ind]
          # last_first = string[: char_ind + add_space_ind+]
          add = (
              string_.count(" ")
              + string_.count("\\ ") * 2
              + string_.count("\n")
              + string_.count("*")
              + string_.count("_")
              + string_.count("^")
              + string_.count("\\[") * 2
              + string_.count("\\]") * 2
              + string_.count("\\(") * 2
              + string_.count("\\)") * 2
              + string_.count("\\right") * 6
              + string_.count("\\left") * 5
              + string_.count("\\sum")
              * 3  # replaced to X that's why not 4
              + string_.count("{")
              + string_.count("}")
              + string_.count("#")
              + string_.count("[REF]") * 5
              + string_.count("[ENDREF]") * 8
              + string_.count("\\varphi") * 3
              + string_.count("\\quad") * 5
              + string_.count("\\qquad") * 6
              + string_.count("\\hskip") * 6
              + string_.count("\\vskip") * 6
              + string_.count("\\frac") * 5
              + string_.count("\\rm") * 3
              + string_.count("\\,") * 2
              + string_.count("-")
          )
          if add == add_space_ind:
              break
          add_space_ind = add
      if len(string) <= char_ind + add_space_ind:
          add_space_ind = max(0, len(string) - 1 - char_ind)
  
      # check first chars of rest if they match closing expressions
      while True:
          rest = string[char_ind + add_space_ind :]
          string_ = string[: char_ind + add_space_ind]
          section_title = re.match(r"#+\s?\d*\s*$", string_)
          if rest.startswith("\\]") or rest.startswith("\\)"):
              add_space_ind += 2
          elif (
              rest.startswith(")") or rest.startswith("]")
          ) and string_.endswith("\\"):
              add_space_ind += 1
          elif (
              rest.startswith("(") or rest.startswith("[")
          ) and string_.endswith("\\"):
              add_space_ind -= 1
          elif rest.startswith(" "):
              add_space_ind += 1
          elif section_title:
              add_space_ind -= (
                  section_title.end() - section_title.start()
              )
          elif (
              re.match(r"^[^\w\s]*_\s", rest)
              or re.match(r"^[^\w\s]*\*\*?\s", rest)
              or re.match(r"^.\n", rest)
          ):
              add_space_ind += 1
          else:
              break
      # check if it starts in a math env and include everything before
      end = math_end_regex.search(rest)
      if end is not None:
          start = math_start_regex.search(rest)
          if start is None or start.start() > end.start():
              inds = [
                  m.start()
                  for m in math_start_regex.finditer(string_)
                  if m.start() < end.start() + len(string_)
              ]
              if len(inds) > 0:
                  add_space_ind = inds[-1] - char_ind
                  # assert string_[char_ind+add_space_ind]=='\\'
      return add_space_ind
  
imports: from difflib import SequenceMatcher
  from operator import itemgetter
  from typing import List, Tuple, Union
  import re
  import numpy
  from Levenshtein.StringMatcher import StringMatcher
  import Levenshtein
  from fuzzysearch import find_near_matches
label_desc: Use image node_id 3 for calling the Splitter obj's underlying member method code with example usage: obj.count_special_chars(string, char_ind) and returns: add_space_ind, int