Skip to content
Python3 package for searching, navigating, and modifying LaTeX documents using BeautifulSoup-esque idioms
Python TeX
Branch: master
Clone or download
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
TexSoup more list-like api--append, insert, remove etc.--and expose 'all' attr Apr 14, 2019
docs bump version to 0.2.0, update docs and links Apr 14, 2019
examples more list-like api--append, insert, remove etc.--and expose 'all' attr Apr 14, 2019
tests more list-like api--append, insert, remove etc.--and expose 'all' attr Apr 14, 2019
.coveragerc Fixed Travis (#14) Nov 19, 2017
.gitignore pushing build docs Apr 8, 2019
.travis.yml Fixed Travis (#14) Nov 19, 2017
LICENSE Initial commit Apr 2, 2016
README.md
pytest.ini Fixed Travis (#14) Nov 19, 2017
setup.py more list-like api--append, insert, remove etc.--and expose 'all' attr Apr 14, 2019

README.md

TexSoup

Build Status Coverage Status

TexSoup is a Python3 package for searching, navigating, and modifying LaTeX documents.

Created by Alvin Wan.

Installation

Pip

TexSoup is published via PyPi, so you can install it via pip. The package name is TexSoup:

$ pip install texsoup

From source

Alternatively, you can install the package from source:

$ git clone https://github.com/alvinwan/TexSoup.git
$ cd TexSoup
$ pip install .

Getting Started

There is one main utility, TexSoup, which translates any $\LaTeX$ string or iterator into a soupified object.

Basic Usage

There are two ways to input $\LaTeX$ into TexSoup. Either pass in (1) a file buffer (open('file.tex')) or (2) a string.

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 $\LaTeX$, you can now search and traverse the document tree. The code below demonstrates the basic functions that TexSoup provides.

>>> 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]

See more in the Quickstart Guide →

You can’t perform that action at this time.