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
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:
- Quickstart Guide: how and when to use TexSoup
- Example Use Cases: counting references, resolving imports, and more
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file TexSoup-0.3.1.tar.gz
.
File metadata
- Download URL: TexSoup-0.3.1.tar.gz
- Upload date:
- Size: 26.2 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
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3f6b2ad0abe3688a6656f544c1ba04d0eb25f423f8c377b7369f9ce061ddb70b |
|
MD5 | 2130d0ed9648cbe0da1d6d15c6a2ce65 |
|
BLAKE2b-256 | 84581c503390ed1a81cdcbff811dbf7a54132994acef8dd2194d55cf657a9e97 |
File details
Details for the file TexSoup-0.3.1-py3-none-any.whl
.
File metadata
- Download URL: TexSoup-0.3.1-py3-none-any.whl
- Upload date:
- Size: 27.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.31.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.8.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ae8f08d17f86a905b7c2ce01c9f2da613fbca0bcea78c71d727719e896045bed |
|
MD5 | 780702c5e214d105db52281655406245 |
|
BLAKE2b-256 | 5ca7e9eb0e14633710b51b8472a3beccc7d6a44d55a0a3ef4493ebb4b7977253 |