解析有效的LaTeX,并提供Beautiful-Soup风格的多种方法和Pythonic习惯用法,用于遍历和搜索解析树
项目描述
TexSoup
TexSoup是一个容错性强、适用于Python3的包,用于搜索、导航和修改LaTeX文档。
入门指南
要解析一个$LaTeX$文档,将打开的文件句柄或字符串传递给
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}
""")
使用soupified $\LaTeX$,您现在可以搜索和遍历文档树。下面的代码演示了TexSoup提供的基本功能。
>>> 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]
有关更多用例,请参阅快速入门指南。或者,通过repl.it在线尝试TexSoup →
链接
安装
Pip
TexSoup通过PyPi发布,因此您可以通过pip
安装它。包名为TexSoup
$ pip install texsoup
从源代码安装
或者,您可以从源代码安装此包
$ git clone https://github.com/alvinwan/TexSoup.git
$ cd TexSoup
$ pip install .
项目详情
下载文件
下载适用于您平台的应用程序。如果您不确定要选择哪一个,请了解更多关于安装包的信息。
源分布
TexSoup-0.3.1.tar.gz (26.2 kB 查看哈希值)
构建发行版
TexSoup-0.3.1-py3-none-any.whl (27.8 kB 查看哈希值)
关闭
TexSoup-0.3.1.tar.gz的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 3f6b2ad0abe3688a6656f544c1ba04d0eb25f423f8c377b7369f9ce061ddb70b |
|
MD5 | 2130d0ed9648cbe0da1d6d15c6a2ce65 |
|
BLAKE2b-256 | 84581c503390ed1a81cdcbff811dbf7a54132994acef8dd2194d55cf657a9e97 |
关闭
TexSoup-0.3.1-py3-none-any.whl的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | ae8f08d17f86a905b7c2ce01c9f2da613fbca0bcea78c71d727719e896045bed |
|
MD5 | 780702c5e214d105db52281655406245 |
|
BLAKE2b-256 | 5ca7e9eb0e14633710b51b8472a3beccc7d6a44d55a0a3ef4493ebb4b7977253 |