TexSoup | fault-tolerant Python3 package for searching, navigating, and modifying LaTeX documents
kandi X-RAY | TexSoup Summary
kandi X-RAY | TexSoup Summary
TexSoup is a fault-tolerant, Python3 package for searching, navigating, and modifying LaTeX documents. Created by Alvin Wan + contributors.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- Create a field node
- Extend the list
- Append an item to the end of the list
- Insert an item at position i
- Tokenize a command name
- Move the index by j
- Move forward backward
- Resolve all imports
- Read a TeX file
- Create a TexSoup from a string
- Tokenize a punctuation command name
- Count the number of pages in a text document
- Read a file
- Append the contents of the file
- Returns the descendants of the node
- Tokenize a math switch
- Return the number of records matching the criteria
- Return a list of all the tex elements in the tree
- Return a string representation of the TexText
- Return a string with the contents of the given text
- Tokenize spacer
- Tokenize a string
- Convert a Python tree to a string
- Tokenize a line comment
- Tokenize math switch
- Tokenize symbols
- Tokenize escaped symbols
TexSoup Key Features
TexSoup Examples and Code Snippets
from TexSoup import TexSoup
tex = r"""
\documentclass[12pt]{article}
\begin{document}
\begin{equation}
1 + 1
\end{equation}
\end{document}
"""
a = TexSoup(tex).count('equation')
print(a)
1
def getText(section):
for token in section.descendants:
if isinstance(token, str):
corpus.write(str(x))
from TexSoup import RArg
def getText(section):
for x in section.descendants:
>>> from TexSoup import TexSoup
>>> soup = TexSoup(open('tri7.txt').read())
>>> for i in soup.find_all('author'):
... i
...
\author{{\small Tanya Araujo$^{a,b}$ and Elsa Fontainha$^{a}$} \and {\small $^{
%{\documentstyle[aps,epsf,rotate,epsfig,preprint]{revtex}}
{'\\finDate': 'December 31, 2018', '\\startDate': 'January 1, 2018'}
from pprint import pprint
from TexSoup import TexSoup
soup = TexSoup(open('slatex.tex'))
newcommands = list(soup.find_all('newcommand'))
result
from TexSoup import TexSoup
soup = TexSoup(r"$\textbf{R}\textbf{R}_1=\textbf{R}_2\textbf{R}$")
for b in soup.find_all('textbf'):
b.replace("{args[0]}".format(args=b.args))
\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:
def replaceTex(soup, command, replacement):
for node in soup.find_all(command):
node.replace(replacement.format(args=node.args))
>>> soup = TexSoup(r"\section{hello} text \bra{(.)} haha \ket{(.
>>> from TexSoup import TexSoup
>>> string = "\documentclass[this is an option]{this is a text} this is other text ..."
>>> soup = TexSoup(string)
>>> list(soup.contents)
[\documentclass[this is an optio
Community Discussions
Trending Discussions on TexSoup
QUESTION
I am using the Python module TexSoup to parse a *.tex
file. Unfortunately it doesn't seem to work at all. It parses the file successfully but the examples never return an expected value. For demonstration purposes I use this Python example called solution_length.py
ANSWER
Answered 2019-Nov-03 at 12:46One way to make this work is
QUESTION
I'm pretty new to Django and LaTeX so I'm hoping that someone out there has done something like this before:
I'm trying to create a Django app that can read a LaTeX file, extract all of the variables (things of this form: "\newcommand{\StartDate}{January 1, 2018}
") and place them as key/value pairs into a dictionary that I can work with inside Django.
The idea is that each variable in the LaTeX file starts with a place holder value. I'll be building a dynamic form that uses the dictionary to create field/values and let's a user replace the place holder value with a real one. After a user has set all of the values, I'd like to be able to write those new values back into the LaTeX file and generate a pdf from it.
I've tried regular expressions but have run into trouble because some of the 'variables' will contain blocks of LaTeX like lists, for example. I've also looked at TexSoup which seems to be very promising but I haven't been able to totally figure out yet. Here is a section from the preamble of an example LaTeX file like the ones I'll be dealing with:
...ANSWER
Answered 2018-Jun-04 at 00:41Each of the \newcommand
s has two required arguments, denoted using {}
. As a result, we can
- access each
newcommand
's arguments, and - access the value of each argument
With your definition of slatex.tex
above, we can obtain
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install TexSoup
Quickstart Guide: how and when to use TexSoup
Example Use Cases: counting references, resolving imports, and more
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page