Skip to main content

A lightweight LaTeX-to-Python parser

Project description

LaTeX-to-Python Parser (latex2py)

This is a lightweight LaTeX-to-Python parser.

We needed a parser that could convert LaTeX math expressions into Python-like expressions. However, SymPy is an extremely large library (~50 MB) and leads to bundle size issues when deploying code as an AWS lambda function (max. size 250MB). This codebase strips out the minimal code that we need, and is around ~200kb in size.

The parser is inspired by the sympy LaTeX parser, but instead of returning symbolic SymPy expressions, we return lines of Python-like code which could can then be evaluated in the interpreter.

Setup

Run poetry install to create a virtual environment and install dependencies.

You can also run poetry shell to activate the virtual environment.

Usage

from latex2py.parser import parse_latex

latex = r'\frac{1}{2} + \frac{3}{4}'
python = parse_latex(latex)
print(python)

# Output:
# (1 / 2) + (3 / 4)

You can also adjust the parsing behavior using the Config object - see latex2py/config.py for more details.

Tests

Run pytest tests to run the test suite. You can find examples of parseable LaTeX syntex there too.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

latex2py-0.1.2.tar.gz (33.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

latex2py-0.1.2-py3-none-any.whl (36.2 kB view details)

Uploaded Python 3

File details

Details for the file latex2py-0.1.2.tar.gz.

File metadata

  • Download URL: latex2py-0.1.2.tar.gz
  • Upload date:
  • Size: 33.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.2 CPython/3.12.3 Darwin/23.3.0

File hashes

Hashes for latex2py-0.1.2.tar.gz
Algorithm Hash digest
SHA256 8d08de6e09d9b908943173dba26152b289e855454d7bcbbea019fdaec59a2e39
MD5 5387d8eb7ebbacb3fb5c1cd14ef0e1cc
BLAKE2b-256 d79a9baaca713968c198f78e82aa23566d5c81c7c08db867480259c5559f143c

See more details on using hashes here.

File details

Details for the file latex2py-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: latex2py-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 36.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.2 CPython/3.12.3 Darwin/23.3.0

File hashes

Hashes for latex2py-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 0ea8fdae51dc0b46505583c11c958a618908b989392ee79fa11fd745e6162e85
MD5 5aba52c7faed5742e6917d7c7656f59b
BLAKE2b-256 b5e171ceca0c1f68d7c83ea7a4eeb47bd49b6830a9344057b357c34ce8f1c5eb

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page