jiggzson / nerdamer

a symbolic math expression evaluator for javascript
http://www.nerdamer.com
MIT License
514 stars 82 forks source link

ConvertToLaTeX doesn't convert negative exponents into a fraction. #570

Closed Nick481 closed 3 years ago

Nick481 commented 4 years ago

When using nerdamer.convertToLaTeX, any string/expression with a negative exponent is left in a negative exponent format instead of being converted to a fraction where the exponent term is moved to the denominator and becomes a positive exponent.

For example, the result of convertToLaTeX on the string "s^(-2)" is "s^{\left(-2\right)}" which renders as this: http://prntscr.com/ultj83

If it converted said input string to fraction form, it would output as "\frac{1}{s^2}" which would render as this: https://prnt.sc/ultk1g

ElectrifyPro commented 3 years ago

convertToLaTeX does not evaluate the expression, according to the docs, which is what you are expecting. If you want this behavior, you probably need to simplify it first before calling convertToLaTeX.

Nick481 commented 3 years ago

I think you are correct on that, I went and tested some different scenarios and things like nerdamer.diff and nerdamer.divide are what produces the negative exponents. I was not expecting convertToLaTeX to evaluate anything however, only expecting it to prettify/clean up the formatting as it parsed. Ideally, there could be an option for outputting negative exponents in fraction form when converting to LaTeX.

As of right now, nerdamer.simplify does not convert negative exponents to fraction denominators. In fact, the simplify function and other math functions in Nerdamer will convert fractional expressions to negative exponents (i.e. nerdamer.simplify("2*y/x") outputs 2*x^(-1)*y). I will see if I can find a workaround or solution. I know Martin is busy with other things and this isn't a problem that is critical for most Nerdamer users.

jiggzson commented 3 years ago

@Nick481, I agree. Ideally, the output should be consistent. I'll look into it.

jiggzson commented 3 years ago

@Nick481, I know it's been a while but I'm going to be revisiting this issue as my last issue for 1.1.8. I'm hoping to have a solution for this. Any additional insight on this issue? Any good workarounds that I can incorporate?