Latex2Sympy2 Extended
latex2sympy2-extended parses LaTeX math expressions and converts them into equivalent SymPy forms. It supports a wide range of mathematical constructs including arithmetic, common functions, calculus, and linear algebra. The current version is 1.11.0, with a release cadence reflecting active development and maintenance.
Warnings
- breaking The library is not compatible with Python 3.13 due to the removal of 'typing.io'. It requires Python 3.12 or below.
- deprecated The `latex2sympy2_extended.math_normalization.equations` module/functionality is deprecated as its handling is now integrated directly into the parser.
- gotcha When converting certain linear algebra expressions (e.g., determinants, transposed matrices, elementary transformations), the conversion process may involve irreversible calculations, meaning the resulting SymPy expression might not be algebraically identical to the original if interpreted purely symbolically.
- gotcha Comma-separated numbers are only supported in standalone forms (e.g., '1,233') and not within expressions (e.g., '1,233x').
Install
-
pip install latex2sympy2-extended -
pip install latex2sympy2_extended[antlr4_13_2]
Imports
- latex2sympy
from latex2sympy2_extended import latex2sympy
Quickstart
from latex2sympy2_extended import latex2sympy
# Define a LaTeX expression for a derivative
tex_expression = r"\frac{d}{dx}(x^{2}+x)"
# Convert the LaTeX expression to a SymPy expression
sympy_expression = latex2sympy(tex_expression)
print(sympy_expression)
# Expected output: Derivative(x**2 + x, x)