@staticmethod<EOL><INDENT>def getHeadingLevel(ts, hierarchy=default_hierarchy):<DEDENT>
try:<EOL><INDENT>return hierarchy.index(ts.name)+<NUM_LIT:1><EOL><DEDENT>except ValueError:<EOL><INDENT>if ts.name.endswith('<STR_LIT>'):<EOL><INDENT>i, name = <NUM_LIT:0>, ts.name<EOL>while name.startswith('<STR_LIT>'):<EOL><INDENT>name, i = name[<NUM_LIT:3>:], i+<NUM_LIT:1><EOL><DEDENT>if name == '<STR_LIT>':<EOL><INDENT>return i+<NUM_LIT:2><EOL><DEDENT><DEDENT>return float('<STR_LIT>')<EOL><DEDENT>except (AttributeError, TypeError):<EOL><INDENT>return float('<STR_LIT>')<EOL><DEDENT>
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