erwanp / pytexit

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

simplify_fractions doesn't work #22

Open turner-eng opened 3 years ago

turner-eng commented 3 years ago

print(py2tex('theta = w_k * a 4 / t 4 / E',simplify_fractions=True)) prints out:

$$\theta=\frac{\frac{w_k a^4}{t^4}}{E}$$

instead of:

$$\theta=\frac{w_k a^4}{t^4E}$$

erwanp commented 3 years ago

Thank you for spotting it !

I think that simplify_fractions could only deal with small decimals and write them as function, i.e. turn 0.5 to 1/2. The "simplify_fraction" may be a little misleading. @alexhagen can you confirm ?

It would be a nice featur e!!

alexhagen commented 3 years ago

I'll look further into this on the weekend, but simplify_fractions uses looks_like_int on both the denominator and numerator to check if it can be simplified - and doesn't simplify if both the numerator and denominator don't "look like integers". So at first blush, that looks like expected behavior - I'll verify that. This could be a feature request, however.

turner-eng commented 3 years ago

This is a very handy feature, looking forwards to see it been added!

alexhagen commented 3 years ago

All, I've opened a fork and a new feature branch to add this in. My plan is to use sympy to do the simplification.