allofphysicsgraph / proofofconcept

Physics Derivation Graph: mathematical connections among equations
https://derivationmap.net/
Other
20 stars 6 forks source link

convert LaTeX to semantically meaningful representation #44

Closed bhpayne closed 4 years ago

bhpayne commented 6 years ago

Content in the Physics Derivation Graph is currently stored as LaTeX. LaTeX is not meaningful for computer algebra systems, so a semantically meaningful representation like Content MathML or SymPy or Sage would be better.

For new content, manually entry in Content MathML is burdensome. Therefore collecting expressions in LaTeX and converting to Content MathML is preferable.

bhpayne commented 6 years ago

Candidates for converters from LaTeX to Content MathML:

https://www2.ph.ed.ac.uk/snuggletex/documentation/generating-content-mathml.html https://www2.ph.ed.ac.uk/snuggletex/UpConversionDemo

Converter written in Perl: https://dlmf.nist.gov/LaTeXML/

http://pillars.che.pitt.edu/LaTeXMathML/

bhpayne commented 6 years ago

For LaTeX to SymPy, see

https://github.com/augustt198/latex2sympy

and

https://github.com/sympy/sympy/issues/5418

bhpayne commented 4 years ago

This issue is blocked by the need for an Abstract Syntax Tree (AST)

bhpayne commented 4 years ago

Now supported (experimentally): https://docs.sympy.org/latest/modules/parsing.html#experimental-latex-parsing

My mention is here: https://github.com/sympy/sympy/issues/5418

The merge is here: https://github.com/sympy/sympy/pull/13706

from https://docs.sympy.org/latest/modules/printing.html

import sympy
expr = sympy.parsing.latex.parse_latex(r"\frac {1 + \sqrt {\a}} {\b}")
print(sympy.printing.latex(expr))

bonus: MathML

sympy.printing.print_mathml(expr)

and an expression tree (from https://docs.sympy.org/latest/tutorial/manipulation.html):

sympy.srepr(expr)

visualize the tree using graphviz:

sympy.printing.dotprint(expr)
bhpayne commented 4 years ago

Converting Latex to SymPy (with user review and intervention as needed) addresses this requirement