erwanp / pytexit

Convert a Python expression to a LaTeX formula
https://pytexit.readthedocs.io/
Other
114 stars 31 forks source link

Issue #59 Nested subtraction order of operations #60

Closed abuyukyi101198 closed 1 year ago

abuyukyi101198 commented 1 year ago

Hi, Issue #59 shows that nested subtraction operations have their parentheses removed, which results in the output being a different formula.

I added a special condition for nested subtractions, encasing them in parentheses in visit_BinOp().

This process adds some redundant parentheses, which I removed by two regex substitutions in simplify(). They still don't remove outermost parentheses, so I added a TODO for that.

erwanp commented 1 year ago

Thanks for fixing this. As it's a hotfix, can you mention this PR as comment in the code so future developers can quickly understand why we did this?

abuyukyi101198 commented 1 year ago

Added the comments but I have no idea why the checks failed this time.

abuyukyi101198 commented 1 year ago

Alright, I got why the builds are failing.

They still don't remove outermost parentheses, so I added a TODO for that.

That's why. Finding a way of adding an exception to the special condition added so that the outermost subtraction is not encased in parentheses should fix everything. Wouldn't be a hotfix then, I guess.

erwanp commented 1 year ago

Try if you can. Else, you can also adjust the hard-coded test to match the new output (assuming it's mathematically correct of course!)

You'll also need to add a new text corresponding to #59 to make sure any future change never breaks your use case.

And then we'll be able to merge