code: def getHeadingLevel(ts, hierarchy=default_hierarchy):
          
          try:
              return hierarchy.index(ts.name)+1
          except ValueError:
              if ts.name.endswith('section'):
                  i, name = 0, ts.name
                  while name.startswith('sub'):
                      name, i = name[3:], i+1
                  if name == 'section':
                      return i+2
              return float('inf')
          except (AttributeError, TypeError):
              return float('inf')
docs: Extract heading level for a particular Tex element, given a specified
          hierarchy.
  
          >>> ts = TexSoup(r'\section{Hello}').section
          >>> TOC.getHeadingLevel(ts)
          2
          >>> ts2 = TexSoup(r'\chapter{hello again}').chapter
          >>> TOC.getHeadingLevel(ts2)
          1
          >>> ts3 = TexSoup(r'\subsubsubsubsection{Hello}').subsubsubsubsection
          >>> TOC.getHeadingLevel(ts3)
          6