All Projects → alvinwan → tex2py

alvinwan / tex2py

Licence: BSD-2-Clause License
converts LaTeX into a Python parse tree, allowing navigation using the default or a custom hierarchy

Programming Languages

python
139335 projects - #7 most used programming language
TeX
3793 projects

Projects that are alternatives of or similar to tex2py

l3build
A testing and building system for LaTeX
Stars: ✭ 63 (-10%)
Mutual labels:  latex
templateestagiofga
Este repositório contém o template para a realização do relatório final da disciplina de estágio obrigatório da FGA - UnB em LaTeX
Stars: ✭ 22 (-68.57%)
Mutual labels:  latex
LinearOne
LinearOne is a prototype theorem prover for first-order (multiplicative, intuitionistic) linear logic.
Stars: ✭ 16 (-77.14%)
Mutual labels:  latex
NoisyStudent
"Self-training with Noisy Student improves ImageNet classification" pytorch implementation
Stars: ✭ 31 (-55.71%)
Mutual labels:  latex
WHUT-Bachelor
武汉理工大学本科生毕业设计(论文) LaTeX 模板 LaTeX Template for Bachelor's Degree Thesis at Wuhan University of Technology (WHUT)
Stars: ✭ 18 (-74.29%)
Mutual labels:  latex
snuthesis
An UNOFFICIAL LaTeX thesis template for Seoul National University (SNU), Korea.
Stars: ✭ 38 (-45.71%)
Mutual labels:  latex
tudscr
TUD-Script
Stars: ✭ 69 (-1.43%)
Mutual labels:  latex
letter-2-reviewers-LaTeX-template
A LaTeX template to write response letters for journal revisions
Stars: ✭ 32 (-54.29%)
Mutual labels:  latex
i.upmath.me
Upmath LaTeX Renderer
Stars: ✭ 42 (-40%)
Mutual labels:  latex
latex-beamer-teamplates
My LaTeX Beamer Templates for Daily Presentation and Documentation.
Stars: ✭ 14 (-80%)
Mutual labels:  latex
hesso-latextemplate-thesis
HES-SO//Master MSE thesis template
Stars: ✭ 26 (-62.86%)
Mutual labels:  latex
TeXTemplates
LaTeX/XeLaTeX templates for academic publications: articles, dissertations, posters, and bachelor’s/master’s theses
Stars: ✭ 94 (+34.29%)
Mutual labels:  latex
DIME-LaTeX-Templates
DIME's LaTeX templates and LaTeX exercises teaching anyone new to LaTeX how to use LaTeX and how to use DIME's templates
Stars: ✭ 32 (-54.29%)
Mutual labels:  latex
tufte-markdown
Use markdown to write your handouts and books in Tufte style.
Stars: ✭ 82 (+17.14%)
Mutual labels:  latex
latex-action
GitHub Action to compile LaTeX documents
Stars: ✭ 123 (+75.71%)
Mutual labels:  latex
pseudocode.js
Beautiful pseudocode for the Web
Stars: ✭ 132 (+88.57%)
Mutual labels:  latex
cv
A LaTeX template for academic CVs
Stars: ✭ 129 (+84.29%)
Mutual labels:  latex
Learn-to-program-with-C AR
ترجمة لدرس تعلّم البرمجة بلغة السي الخاص بموقع OpenClassrooms
Stars: ✭ 51 (-27.14%)
Mutual labels:  latex
tikz favorites
collection of favorite TikZ graphics
Stars: ✭ 62 (-11.43%)
Mutual labels:  latex
markdown
📔 A package for converting and rendering markdown documents in TeX
Stars: ✭ 219 (+212.86%)
Mutual labels:  latex

LaTeX2Python (tex2py)

Build Status Coverage Status

Tex2py converts LaTeX into a Python parse tree, using TexSoup. This allows you to navigate latex files as trees, using either the default or a custom hierarchy. See md2py for a markdown parse tree.

Note tex2py currently only supports Python3.

created by Alvin Wan

Installation

Install via pip.

pip install tex2py

Usage

LaTeX2Python offers only one function tex2py, which generates a Python parse tree from Latex. This object is a navigable, "Tree of Contents" abstraction for the latex file.

Take, for example, the following latex file. (See pdf)

chikin.tex

\documentclass[a4paper]{article}
\begin{document}

\section{Chikin Tales}

\subsection{Chikin Fly}

Chickens don't fly. They do only the following:

\begin{itemize}
\item waddle
\item plop
\end{itemize}

\section{Chikin Scream}

\subsection{Plopping}

Plopping involves three steps:

\begin{enumerate}
\item squawk
\item plop
\item repeat, unless ordered to squat
\end{enumerate}

\subsection{I Scream}

\end{document}

Akin to a navigation bar, the TreeOfContents object allows you to expand a latex file one level at a time. Running tex2py on the above latex file will generate a tree, abstracting the below structure.

          <Document>
          /        \
  Chikin Tales   Chikin Scream
      /            /     \
 Chikin Fly  Plopping   I Scream

At the global level, we can access the title.

>>> from tex2py import tex2py
>>> with open('chikin.tex') as f: data = f.read()
>>> toc = tex2py(data)
>>> toc.section
Chikin Tales
>>> str(toc.section)
'Chikin Tales'

Notice that at this level, there are no subsections.

>>> list(toc.subsections)
[]

The main section has two subsections beneath it. We can access both.

>>> list(toc.section.subsections)
[Chikin Fly, Chikin Scream]
>>> toc.section.subsection
Chikin Fly

The TreeOfContents class also has a few more conveniences defined. Among them is support for indexing. To access the ith child of an <element> - instead of <element>.branches[i] - use <element>[i].

See below for example usage.

>>> toc.section.branches[0] == toc.section[0] == toc.section.subsection
True
>>> list(toc.section.subsections)[1] == toc.section[1]
True
>>> toc.section[1]
Chikin Scream

You can now print the document tree. (There is some weirdness with branches beyond titles, so for only titles, we have the following:

           ┌Chikin Tales┐
           │            └Chikin Fly
 [document]┤
           │             ┌Plopping
           └Chikin Scream┤
                         │        
                         │        
                         └I Scream

Additional Notes

  • Behind the scenes, tex2py uses TexSoup. All tex2py objects have a source attribute containing a TexSoup object.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].