cortex-js / compute-engine

An engine for symbolic manipulation and numeric evaluation of math formulas expressed with MathJSON
https://cortexjs.io
MIT License
373 stars 46 forks source link

MathLive: a closing parentheses after a function application is ignored #101

Closed rs-mobitech closed 1 year ago

rs-mobitech commented 1 year ago

My application has logging code and I noticed what I think is a problem with .simplify(). Here is the code, and below that are results for two expressions. One of the expressions is missing an ending parenthesis:

          let mathLatex = mf1.getValue('latex')
          let mathJson  = mf1.getValue('math-json')
          let mfExpression = mf1.expression
          let mfNLatex = MathfieldElement.computeEngine.parse(mathLatex).N().latex
          let mfSLatex = MathfieldElement.computeEngine.parse(mathLatex).simplify().latex
          let mfELatex = MathfieldElement.computeEngine.parse(mathLatex).evaluate().latex
          MathfieldElement.computeEngine.latexOptions = { precision: 6 }

          mf2.setValue(mfNLatex)
          mf3.setValue(mfSLatex)
          mf4.setValue(mfELatex)
          mf5.setValue(mathJson)

          logToConsole("mathLatex:" + mathLatex);
          logToConsole("mfExpression:" + mfExpression);
          logToConsole("mfNLatex:" + mfNLatex);
          logToConsole("mfSLatex:" + mfSLatex);
          logToConsole("mathJson:" + mathJson)
Screenshot 2023-08-25 at 17 47 36 Screenshot 2023-08-25 at 17 46 44
rs-mobitech commented 1 year ago

For reference, here's the Latex also

mfSLatex:\frac{1}{2}(\sin(1)\cos(1))

I believe the latex is correct but the mfSLatex and mfELatex are both incorrect and missing a ")" from the end

rs-mobitech commented 1 year ago

One more example

Screenshot 2023-08-25 at 18 44 38
arnog commented 1 year ago

What happens if you do mf3.setValue("\\frac{1}{2}(\\sin(1)\\cos(1))") ?

(Note: I suspect this issue has nothing to do with simplify but that there is a clipping issue with the CSS customizing the mathfield))

rs-mobitech commented 1 year ago

Here's what happens:

Screenshot 2023-08-26 at 0 05 41

Then I also added a few 1s before the \\frac and it gives me this:

Screenshot 2023-08-26 at 0 06 37

There is a lot of space and I have seen some much longer strings in that field

rs-mobitech commented 1 year ago

Here's another example, where you can see the difference with simplify. In MathLive, it's not able to simplify, but Nerdamer does simplify correctly.

Screenshot 2023-08-26 at 13 33 00
arnog commented 1 year ago

OK, so if you get the same problem when setting the LaTeX value directly, the issue is not related to Simplify.

The issue appears to be in MathLive. Entering (f(x)) will result in the final closing parenthesis not being displayed.

arnog commented 1 year ago

Fixed in MathLive with aaf6a46172bdc4b9e4dac469bb87276c5e3d6d4c