Skip to content
Branch: master
Find file Copy path
Find file Copy path
2 contributors

Users who have contributed to this file

@alvinwan @threecgreen
103 lines (74 sloc) 2.63 KB


Build Status Coverage Status

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

Created by Alvin Wan.



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
$ 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("""

\section{Hello \textit{world}.}


(n.) A sacred fruit. Also known as:

\item red lemon
\item life

Here is the prevalence of each synonym.

\begin{tabular}{c c}
red lemon & uncommon \\
life & common


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.string
'Hello \\textit{world}.'
>>> soup.tabular
\begin{tabular}{c c}
red lemon & uncommon \\
life & common
>>> 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.