def parseBranches(self, descendants):
i, branches = self.parseTopDepth(descendants), []<EOL>for descendant in descendants:<EOL><INDENT>if self.getHeadingLevel(descendant, self.hierarchy) == i:<EOL><INDENT>branches.append({'<STR_LIT:source>': descendant})<EOL><DEDENT>if self.getHeadingLevel(descendant, self.hierarchy) > iand branches:<EOL><INDENT>branches[-<NUM_LIT:1>].setdefault('<STR_LIT>', []).append(descendant)<EOL><DEDENT><DEDENT>return [TOC(str(descendant), depth=i, hierarchy=self.hierarchy,<EOL>**branch) for branch in branches]<EOL>
Parse top level of latex
:param list elements: list of source objects
:return: list of filtered TreeOfContents objects

>>> toc = TOC.fromLatex(r'\section{h1}\subsection{subh1}\section{h2}\
... \subsection{subh2}')
>>> toc.parseTopDepth(toc.descendants)
1
>>> toc.parseBranches(toc.descendants)
[h1, h2]
>>> len(toc.branches)
2
>>> len(toc.section.branches)
1