Registry / serialization / py-asciimath

py-asciimath

JSON →
library0.3.0pypypi✓ verified 87d ago

py-asciimath is a Python library designed for converting mathematical expressions between ASCIIMath, MathML, and LaTeX formats. It provides functionality to convert from ASCIIMath to LaTeX or MathML, from MathML to LaTeX, and from LaTeX to ASCIIMath. The current version is 0.3.0. The project maintains an active development status, with ongoing updates and feature expansions, evidenced by recent major version bumps and support for new translation directions.

pip install py-asciimath
INSTALL
IMPORT
SIG · PY-ASCIIMATH
P
py-asciimath
serializationpythonv0.3.0
Install
3.1s avg
Import
183ms
Disk
32MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.3.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.920 runs
installs and imports cleanly · install 0.0s · import 0.190s · 34.1MB
glibc
py 3.103.920 runs
installs and imports cleanly · install 3.1s · import 0.175s · 35MB
32MB installed
● package 32MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

ASCIIMath2MathML
from py_asciimath.translator.translator import ASCIIMath2MathML
ASCIIMath2Tex
from py_asciimath.translator.translator import ASCIIMath2Tex
MathML2Tex
from py_asciimath.translator.translator import MathML2Tex
Tex2ASCIIMath
from py_asciimath.translator.translator import Tex2ASCIIMath

This quickstart demonstrates how to initialize different translator classes and use the `translate` method to convert mathematical expressions between ASCIIMath, MathML, and LaTeX formats. Various options like `displaystyle` and `dtd` can be passed to the `translate` method for fine-grained control over the output.

from py_asciimath.translator.translator import (ASCIIMath2MathML, ASCIIMath2Tex, MathML2Tex, Tex2ASCIIMath) # Example: ASCIIMath to MathML asciimath_expr = r"e^x > 0 forall x in RR" asciimath2mathml = ASCIIMath2MathML(log=False, inplace=True) mathml_output = asciimath2mathml.translate( asciimath_expr, displaystyle=True, dtd="mathml2", dtd_validation=False, from_file=False, output="string" ) print("ASCIIMath to MathML:\n", mathml_output) # Example: ASCIIMath to LaTeX asciimath2tex = ASCIIMath2Tex() latex_output = asciimath2tex.translate(asciimath_expr) print("ASCIIMath to LaTeX:\n", latex_output) # Example: LaTeX to ASCIIMath latex_expr = r"\frac{-b \pm \sqrt{b^2-4ac}}{2a}" tex2asciimath = Tex2ASCIIMath() asciimath_from_tex_output = tex2asciimath.translate(latex_expr) print("LaTeX to ASCIIMath:\n", asciimath_from_tex_output)
Debug
Known issues
breakingPython 2.7 compatibility was officially dropped in version `0.2.3`. Users requiring Python 2.7 support must use `py-asciimath` version `0.2.2` or older.
fix
Upgrade to Python 3.x or pin the library version to `py-asciimath==0.2.2`.
affects: <=0.2.2
gotchaThe `MathML2Tex` conversion relies on an XSLT MathML Library. While generally robust, unexpected behavior may occur with certain complex or non-standard MathML structures. Users are encouraged to report any issues.
fix
Test conversions thoroughly with your specific MathML input. Report any inconsistencies or errors to the library's GitHub issue tracker.
affects: >=0.2.0
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'py_asciimath'
The Python package is named `py-asciimath`, but the importable module inside it is named `asciimath`.
fix
import asciimath
AttributeError: module 'asciimath' has no attribute 'convert_to_latex'
The user is attempting to call a non-existent function; the conversion functions have specific names like `asciimath2latex` or `latex2asciimath`.
fix
asciimath.asciimath2latex('x^2 + y^2')  # Use the correct function name for conversion
TypeError: asciimath2latex() missing 1 required positional argument: 'math'
The conversion functions require the mathematical expression string as their primary argument.
fix
asciimath.asciimath2latex('sum_(i=1)^n i')
py-asciimath: command not found
The `py-asciimath` library does not install a direct executable named `py-asciimath`; its command-line interface is accessed via `python -m asciimath`.
fix
python -m asciimath 'alpha' --to-latex
Upgrade
Version history
0.3.0latest on PyPI · released Apr 22, 2020
Audit
Dependencies
lxmlrequiredRequired for MathML parsing and XSLT-based transformations, especially MathML to LaTeX conversion.
plyrequiredUsed for parsing ASCIIMath and LaTeX expressions.
sixrequiredCompatibility layer for Python 2 and 3, though Python 2.7 support has been dropped in recent versions.
Agent activity
10 hits · last 30 days
node
10
Resources
py-asciimath — pip install py-asciimath · libregistry