# Command line option to get tree view structure of LaTeX project

I would like to get a tree-view of a latex project showing things like sections, chapters, figures.

- Table of contents
- Introduction (1.0)
--- fig 1  fig one title
--- fig 2   fig two title
- Second section (2.0)
--- fig 3 fig three title
- First Subsection in section 2 (2.1)
- Conclusion (3.0)
- References (4.0)


Is there a nice command line tool which is available for this such as texcount is available for wordcounts.

• Probably, but… where you want that tree to be displayed? If it's in a terminal and you're using Unix, then tree is your friend to list your files (but then you'll have to put your figures in separate files). If it's in an IDE as TexStudio, then by playing a bit with the options, you should be able to do that too. If it's in your document, you could achieve that by modifying the tableofcontents command, I guess. – Clément Feb 5 '16 at 15:24
• @Clément: I don't believe tree is correct here. I think, the tool should analyze the .toc and .tof files, most likely? – user31729 Feb 5 '16 at 15:26
• I have modified the example a bit. I was looking for the structure LaTeX see's it as via a unix command line option rather than a Unix tree or using an IDE. Doing something with tableofcontents seems quite smart. Ideally there would be a working solution much like there is for wordcount with texcount. – henry.oswald Feb 5 '16 at 15:32

Not really a tool, sorry, but generating a very simple tree

\documentclass{article}

\newwrite\tvhandle%

\usepackage{pgffor}
\usepackage{xpatch}

\makeatletter
\newcounter{mylevel}

\newcommand{\writetv}[3]{%
\edef\mydef{\space}
\ifnum #3 > 0
\foreach \x in {1,...,#3}
{
\xdef\mydef{\mydef-}
}
\fi
\immediate\write\tvhandle{\mydef #1 #2}
}

\xapptocmd{\tableofcontents}{%
}{}{}

\xapptocmd{\listoffigures}{%
}{}{}

\newcommand\starttreeview{%
\immediate\openout\tvhandle=\jobname.tv
\@starttoc{tvaux}%
\immediate\closeout\tvhandle
}

\xpatchcmd{\@sect}{%
\ifnum #2>\c@secnumdepth \else
\protect\numberline{\csname the#1\endcsname}%
\fi
#7}%
}{%
\ifnum #2>\c@secnumdepth \else
\protect\numberline{\csname the#1\endcsname}%
\fi
#7}%
}{}{}

\makeatother

\begin{document}
\starttreeview
\tableofcontents
\listoftables
\listoffigures

\section{first}

\subsection{first}

\subsubsection{first}

\paragraph{first}

\subparagraph{first}

\section{Second}

\subsection{second}

\subsubsection{second}

\paragraph{second}

\subparagraph{second}

\end{document}


This produces an unaligned 'tree' (sorry, no figures yet) in the \jobname.tv file

 Contents
List of Figures
-1 first
--1.1 first
---1.1.1 first
-2 Second
--2.1 second
---2.1.1 second

• Patching \@ssect would provide the functionality for \section* etc. as well -- \tableofcontents etc. would make an entry automatically then and do not have to be patched separately. – user31729 Feb 5 '16 at 16:18