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
muslpy 3.10–3.920 runs
installs and imports cleanly · install 0.0s · import 0.190s · 34.1MB
glibcpy 3.10–3.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)
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`.
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`.
fixasciimath.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.
fixasciimath.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`.
fixpython -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.