TexSoup is a Python3 package for searching, navigating, and modifying LaTeX documents.
Created by Alvin Wan.
- Quickstart Guide: how and when to use TexSoup
- Example Use Cases: counting references, resolving imports, and more
To parse a TexSoup constructor.
from TexSoup import TexSoup
soup = TexSoup("""
\begin{document}
\section{Hello \textit{world}.}
\subsection{Watermelon}
(n.) A sacred fruit. Also known as:
\begin{itemize}
\item red lemon
\item life
\end{itemize}
Here is the prevalence of each synonym.
\begin{tabular}{c c}
red lemon & uncommon \\
life & common
\end{tabular}
\end{document}
""")With the soupified
>>> soup.section # grabs the first `section`
\section{Hello \textit{world}.}
>>> soup.section.name
'section'
>>> soup.section.string
'Hello \\textit{world}.'
>>> soup.section.parent.name
'document'
>>> soup.tabular
\begin{tabular}{c c}
red lemon & uncommon \\
life & common
\end{tabular}
>>> soup.tabular.args[0]
'c c'
>>> soup.item
\item red lemon
>>> list(soup.find_all('item'))
[\item red lemon, \item life]Does this look promising? See more in the Quickstart Guide →
TexSoup is published via PyPi, so you can install it via pip. The package
name is TexSoup:
$ pip install texsoupAlternatively, you can install the package from source:
$ git clone https://github.com/alvinwan/TexSoup.git
$ cd TexSoup
$ pip install .