跳转到主要内容

解析有效的LaTeX,并提供Beautiful-Soup风格的多种方法和Pythonic习惯用法,用于遍历和搜索解析树

项目描述

TexSoup

PyPi Downloads per Day Build Status Coverage Status

TexSoup是一个容错性强、适用于Python3的包,用于搜索、导航和修改LaTeX文档。

Alvin Wan + 贡献者创建。

入门指南

要解析一个$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 查看哈希值)

上传时间 Python 3

由以下提供支持