| from lxml import etree |
| import latex2mathml.converter |
|
|
|
|
| def mathml_to_operator_tree(node): |
| """Convert MathML to an operator tree.""" |
| |
| if len(node) == 0: |
| return node.text |
| |
| operator_tree = "" |
| for child in node: |
| operator_tree += str(child.tag).split('}')[-1].replace('m', '') +"(" + str(mathml_to_operator_tree(child)) + ')' |
| return operator_tree |
|
|
| def latex2tree(latex_text): |
| mathml = latex2mathml.converter.convert(latex_text) |
| root = etree.fromstring(mathml.encode()) |
| operator_tree = mathml_to_operator_tree(root[0]) |
| return operator_tree |