Physics Derivation Graph navigation Sign in

parsing latex using Sympy - what works and what does not

Published 2020-06-25T01:28:00.002Z by Physics Derivation Graph

# python
Python 3.6.9 (default, Apr 18 2020, 01:56:04)
>>> from sympy.parsing.latex import parse_latex
>>> parse_latex('a = b')
Eq(a, b)
>>> parse_latex('\\frac{\\partial}{\\partial t} \\psi( r,t)')
Derivative(\psi(r, t), t)
>>> parse_latex('\\int_{a}^{b} f(x) dx')
Integral(f(x), (x, a, b))

To can check that the Sympy expression gets converted to Latex correctly:
>>> from sympy import *
>>> sympy.latex(parse_latex('\\int_{a}^{b} f(x) dx'))

vectors do not get parsed correctly
>>> parse_latex('\\vec{a} = \\vec{g} t')
>>> parse_latex('\\hat{x} + \\hat{y}')
The "hat" is typically used for unit vectors. These are referenced in
but I don't see a Sympy-specific notation for unit vectors.

bra-ket notation does not raise an exception but is not interpreted correctly
>>> parse_latex('\\langle \\alpha | = 1')

The following triggers an exception
>>> parse_latex('\\mathcal{H} = 5')
For a discussion of that symbol in Latex, see

Complex conjugation notation is not interpreted correctly:
>>> parse_latex('Z Z^* = 5')