Convert LaTeX math to SymPy expressions
Maintained. Last release 11 months ago. Weaker on release cadence.
pip install latex2sympy2-extended![]()
latex2sympy2_extended
About
latex2sympy2_extended parses LaTeX math expressions and converts it into the equivalent SymPy form. The latex2sympy2_extended is adapted from OrangeX4/latex2sympy.
ANTLR 4.13.1 is used to generate the parser.
Features
- Arithmetic: Add (+), Sub (-), Dot Mul (·), Cross Mul (×), Frac (/), Power (^), Abs (|x|), Sqrt (√), etc...
- Alphabet: a - z, A - Z, α - ω, Subscript (x_1), Accent Bar(ā), etc...
- Common Functions: gcd, lcm, floor, ceil, max, min, log, ln, exp, sin, cos, tan, csc, sec, cot, arcsin, sinh, arsinh, etc...
- Function Symbol: f(x), f(x-1,), g(x,y), etc...
- Calculous: Limit ($lim_{n\to\infty}$), Derivation ($\frac{d}{dx}(x^2+x)$), Integration ($\int xdx$), etc...
- Linear Algebra: Matrix, Determinant, Transpose, Inverse, Elementary Transformation, etc...
- Set: Union (∪), Intersection (∩), etc...
- Other: Binomial...
NOTICE: It will do some irreversible calculations when converting determinants, transposed matrixes and elementary transformations...
NOTICE: comma separated numbers are only supported in standalone form: 1,233, not in expressions: 1,233x.
Installation
Current version supports 3 runtimes:
- 4.9.3
- 4.11.0
- 4.13.2
Use the following command to install with the runtime you need:
pip install latex2sympy2_extended[antlr4_13_2]
Requirements: sympy and antlr4-python3-runtime packages.
Usage
Basic
In Python:
from latex2sympy2_extended import latex2sympy
tex = r"\frac{d}{dx}(x^{2}+x)"
latex2sympy(tex)
# => "Derivative(x**2 + x, x)"