Skip to main content

parses valid LaTeX and provides variety of Beautiful-Soup-esque methods and Pythonic idioms for iterating over and searching the parse tree

Project description

TexSoup

Build Status Coverage Status

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

Created by Alvin Wan + contributors.

Getting Started

To parse a $LaTeX$ document, pass an open filehandle or a string into the 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 $\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]

For more use cases, see the Quickstart Guide. Or, try TexSoup online, via repl.it →

Links:

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 .

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

TexSoup-0.3.0.tar.gz (25.9 kB view details)

Uploaded Source

File details

Details for the file TexSoup-0.3.0.tar.gz.

File metadata

  • Download URL: TexSoup-0.3.0.tar.gz
  • Upload date:
  • Size: 25.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.6.2 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.7

File hashes

Hashes for TexSoup-0.3.0.tar.gz
Algorithm Hash digest
SHA256 ccacd864f13a195561b6d392a1a233626a562522f90cd228066eef98bc02cbc9
MD5 2e05c65d3663e6316352b0de90a25f83
BLAKE2b-256 00f124bc2bc67f877919a6a03b7feba2b593a0fbeb2c4aff7fd5549d7ace818e

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page