cortex-js / compute-engine

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

Could you enhance your documentation by including more details about how the compute engine integrates with MathLive #117

Closed OleksiyPetroKovalenko closed 11 months ago

OleksiyPetroKovalenko commented 1 year ago

Is your feature request related to a problem? Please describe.

I am very confused. Does each MathLive, use its own ComputeEngine. Does every instance of MathLive utilize its own ComputeEngine? I'm uncertain about when and where both the instances and the static compute engine come into play.. When working with an application that integrates both MathLive and the ComputeEngine I have tried to modify the Latex dictionary and I have not been able to do that as I am told it's a static function.

Describe the solution you'd like

I would like to understand when the instance of the compute engine and when the compute engine object are used. As I am having difficult accessing the latex dictionary of the compute engine class, could I access this as a non-static function.

Describe alternatives you've considered

I have tried to modify my copy of the compute engine code like this:

    // static getLatexDictionary(domain = "all") {
    getLatexDictionary(domain = "all") {
      return LatexSyntax.getDictionary(domain);
    }

and then

           window.ce = MathfieldElement.computeEngine;
           window.ce.latexDictionary = [
               // Remove the `PlusMinus` entry from the default dictionary...
               //...window.ce.getLatexDictionary().filter((x) => x.name !== 'PlusMinus'),
               ...window.ce.getLatexDictionary().filter((x) => x.name == 'PlusMinus'),
               // ... and add one for the `\smoll` command
               {
                   trigger: ['\\smoll'],
                   parse: (parser) => {
                       return [
                           'Divide',
                           parser.matchRequiredLatexArgument() ?? ['Error', "'missing'"],
                           parser.matchRequiredLatexArgument() ?? ['Error', "'missing'"],
                       ];
                   },
               },
           ];

This modified the instance version of the latex dictionary, but I didn't see any change when entering data into my MathField. Maybe may solution works, maybe not. But as I cannot understand the different ways the compute engine is used then I cannot proceed any further.

Additional context

I believe some simple explanations would help everyone and make this library easier to use.

rs-mobitech commented 1 year ago

+1

arnog commented 11 months ago

There is information about this here: https://cortexjs.io/mathlive/guides/interacting/#using-a-mathfield-with-the-cortexjs-compute-engine