TexSoup | fault-tolerant Python3 package for searching, navigating, and modifying LaTeX documents

 by   alvinwan Python Version: 0.3.1 License: BSD-2-Clause

kandi X-RAY | TexSoup Summary

kandi X-RAY | TexSoup Summary

TexSoup is a Python library typically used in Template Engine, Latex applications. TexSoup has no bugs, it has no vulnerabilities, it has build file available, it has a Permissive License and it has low support. You can install using 'pip install TexSoup' or download it from GitHub, PyPI.

TexSoup is a fault-tolerant, Python3 package for searching, navigating, and modifying LaTeX documents. Created by Alvin Wan + contributors.
Support
    Quality
      Security
        License
          Reuse

            kandi-support Support

              TexSoup has a low active ecosystem.
              It has 212 star(s) with 40 fork(s). There are 10 watchers for this library.
              OutlinedDot
              It had no major release in the last 12 months.
              There are 19 open issues and 80 have been closed. On average issues are closed in 305 days. There are 3 open pull requests and 0 closed requests.
              It has a neutral sentiment in the developer community.
              The latest version of TexSoup is 0.3.1

            kandi-Quality Quality

              TexSoup has 0 bugs and 0 code smells.

            kandi-Security Security

              TexSoup has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.
              TexSoup code analysis shows 0 unresolved vulnerabilities.
              There are 0 security hotspots that need review.

            kandi-License License

              TexSoup is licensed under the BSD-2-Clause License. This license is Permissive.
              Permissive licenses have the least restrictions, and you can use them in most projects.

            kandi-Reuse Reuse

              TexSoup releases are available to install and integrate.
              Deployable package is available in PyPI.
              Build file is available. You can build the component from source.
              Installation instructions, examples and code snippets are available.
              TexSoup saves you 1127 person hours of effort in developing the same functionality from scratch.
              It has 2547 lines of code, 242 functions and 27 files.
              It has high code complexity. Code complexity directly impacts maintainability of the code.

            Top functions reviewed by kandi - BETA

            kandi has reviewed TexSoup and discovered the below as its top functions. This is intended to give you an instant insight into TexSoup implemented functionality, and help decide if they suit your requirements.
            • 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
            Get all kandi verified functions for this library.

            TexSoup Key Features

            No Key Features are available at this moment for TexSoup.

            TexSoup Examples and Code Snippets

            Pythons TexSoup not parsing document
            Pythondot img1Lines of Code : 26dot img1License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            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
            
            Extract only body text from arXiv articles formatted as .tex
            Pythondot img2Lines of Code : 18dot img2License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            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:
                
            Parsing LaTex author tag to extract author names
            Pythondot img3Lines of Code : 13dot img3License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            >>> 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 $^{
            How to open a LaTeX file in Python that starts with a comment
            Pythondot img4Lines of Code : 2dot img4License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            %{\documentstyle[aps,epsf,rotate,epsfig,preprint]{revtex}}
            
            copy iconCopy
            {'\\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
            Use plasTeX on short strings
            Pythondot img6Lines of Code : 6dot img6License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            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))
            
            Extract all text from \section tag in LaTeX
            Pythondot img7Lines of Code : 24dot img7License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            \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:
            
            Latex command substitution using regexp in python
            Pythondot img8Lines of Code : 19dot img8License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            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{(.
            Regexp to catch multiple latex command in a single line
            Pythondot img9Lines of Code : 9dot img9License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            >>> 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

            QUESTION

            Pythons TexSoup not parsing document
            Asked 2019-Nov-03 at 12:46

            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:46

            One way to make this work is

            Source https://stackoverflow.com/questions/58674641

            QUESTION

            How Can I Extract Variables from a LaTeX Doc into a Python Dictionary So That I Can Pull it into Django?
            Asked 2018-Jun-04 at 00:41

            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:41

            Each of the \newcommands has two required arguments, denoted using {}. As a result, we can

            1. access each newcommand's arguments, and
            2. access the value of each argument

            With your definition of slatex.tex above, we can obtain

            Source https://stackoverflow.com/questions/50595901

            Community Discussions, Code Snippets contain sources that include Stack Exchange Network

            Vulnerabilities

            No vulnerabilities reported

            Install TexSoup

            To parse a $LaTeX$ document, pass an open filehandle or a string into the TexSoup constructor. With the soupified $\LaTeX$, you can now search and traverse the document tree. The code below demonstrates the basic functions that TexSoup provides. For more use cases, see the Quickstart Guide. Or, try TexSoup online, via repl.it →.
            Quickstart Guide: how and when to use TexSoup
            Example Use Cases: counting references, resolving imports, and more

            Support

            For any new features, suggestions and bugs create an issue on GitHub. If you have any questions check and ask questions on community page Stack Overflow .
            Find more information at:

            Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items

            Find more libraries
            Install
          • PyPI

            pip install TexSoup

          • CLONE
          • HTTPS

            https://github.com/alvinwan/TexSoup.git

          • CLI

            gh repo clone alvinwan/TexSoup

          • sshUrl

            git@github.com:alvinwan/TexSoup.git

          • Stay Updated

            Subscribe to our newsletter for trending solutions and developer bootcamps

            Agree to Sign up and Terms & Conditions

            Share this Page

            share link