Gawaboumga / PyMatex

Parser for only mathematical expression of latex
MIT License
1 stars 0 forks source link

Some question about this project #1

Open wlsAuto opened 2 years ago

wlsAuto commented 2 years ago

I want to use the parsed tree structure of latex math expression, specifically, operations like visit the tree. And I wonder if this project can parse a latex math expression into a syntax tree? And if it can do this, how can I visit this tree? Thank you very much.

Gawaboumga commented 2 years ago

This project was intended to convert latex formulas into AST, in such way that it could be 'parsed' and used to do 'similarity' searches (if I'm looking for 2x+1, I wanted to also retrieve ax+b).

You can view how to write 'Visitor' here: https://github.com/Gawaboumga/PyMatex/blob/master/tests/listener/MatexASTVisitor.py

You can find and extend the grammar over here: https://github.com/Gawaboumga/PyMatex/blob/master/pymatex/grammar/MatexLexer.g4 https://github.com/Gawaboumga/PyMatex/blob/master/pymatex/grammar/MatexParser.g4 And I just used 'ANTLR' to produce the associated code.

Just to be clear, the grammar I wrote is 'loose', it means that it allows some kind of ambiguous typing. Example: 3x!, does it mean 3 x! or (3x)! ? It's also not very clear what is the priority of Summation in regards to Integral, the 'inner most' should have priority, but that's not something you can express within the grammar, it should be in the code.