Package: pytextree
PyTexTreeCreate a tree object from a LaTeX project. v0.1.1.1. FeaturesThis project was done to provide a way to handle / analyse LaTeX projects more easily.
Feature highlights:Support opening LaTeX projects consisting of multiple files (using\include)Extract several, maybe useful, stats on the fileCreate a traversable tree from the LaTeX projectBuilt upon the awesomeNodeMixinofanytreeExport to a graph to support visualisationAdictwithedgesandnodesCreates edges between references within the projectSpecifically export to.csvfiles supported byGephi2. InstallationUsing pip:$ pip install pytextree3. UsageBasic workflow with thePyTexTreeconsists of two steps:Load the tex file into textParse the text into a treeNOTE:For testing, you can use the provided .texexample.3.1. Loading a LaTeX project into a treeYou can use thetextree.open_tex_project()to load your LaTeX project into a stringimportpytextreeastttxt=tt.open_tex_project('examples/lorem.tex')Then you can simply parse the text into a tree:tree=tt.parse_tex_to_tree(txt)# >>> <TNode [Root]: Root (0, 5502)>The function returns the root node of the created tree. You can traverse it with.childrenand.parentattributes.3.1.1. Tree node attributesThe node, describing a section or an evironment in the LaTeX project, contains some information about the containing text:AttributeDescriptionExample.commandsList of found LaTeX commands in this node["\textbf", "\ref{fig:my_fig}"].commentsList of comments in this node["% A comment"].word_countNumber of words, excluding comments and commands527.labelLaTeX label of the node if one exists"fig:my_graph".citationsCited labels["Lamport1984", "Rossum1991"].textsText contents["This is a paragraph.", "And another."]3.2. Printing the treeYou can also pretty print the created tree for more information:tree.pretty_print()Output:<TNode [Root]: Root (0, 5502)>
└── <TEnv [document]>: None (114, 5500)
   ├── <TNode [section]: S1 (144, 1129)>
   │   ├── <TNode [subsection]: S1.S1 (619, 869)>
   │   └── <TNode [subsection]: S1.S2 (870, 1129)>
   ├── <TNode [section]: S2 (1130, 2542)>
   │   └── <TNode [subsection]: S2.S1 (1460, 2542)>
   │       ├── <TEnv [itemize]>: list:mylist (1606, 1867)
   │       │   ├── <TEnv [itemize]>: None (1695, 1771)
   │       │   └── <TEnv [itemize]>: None (1776, 1853)
   │       ├── <TEnv [itemize]>: list:mylist (1869, 1959)
   │       ├── <TEnv [tabular]>: table:synonyms (2032, 2136)
   │       ├── <TNode [subsubsection]: S2.S1.S1 (2140, 2230)>
   │       └── <TNode [subsubsection]: S2.S1.S2 (2231, 2542)>
   ├── <TNode [section]: S3 (2543, 5485)>
   │   ├── <TNode [paragraph]: This is a paragraph (3417, 4368)>
   │   ├── <TNode [paragraph]: And have another paragraph (4369, 5299)>
   │   └── <TNode [subsection]: S3.S1  (5300, 5484)>
   └── <TEnv [appendices]>: None (5435, 5485)3.3. ExportingTo visualise your project as a network / graph with some external software you can export the project as adictcontaining nodes and edges.graph=tree.to_graph()print(graph['nodes'][0])print(graph['edges'][0])Output:{'id':'$','name':'Root','tag':'Root','texlabel':None,'word count':0,'n comments':0,'n commands':5,'n references':0,'n citations':0,'value':0,'label':'[Root]: Root','group':-1,'title':'words: 0'}{'id':'p1','from':'$','to':'n0','weight':1,'type':'undirected','value':1,'source':'$','target':'n0'}Alternativaly, you can export to a.csvfiles combatible withGephi:tree.to_gephi_csv()This will create two files, one containing the nodes and one containing the edges.4. NotesSome limitations of the project:If you are laoding a project with includes, make sure the main file ends withmain.texe.g.my_latex_project_main.texThe files this includes, should be in the same directoryRequired package version compatablity not checkedEarlier versions might be fine as wellTNode.pretty_print()does not work on Windows console due characters