cortex-js / compute-engine

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

Request for a very small sample application that we could use as a template #112

Open OleksiyPetroKovalenko opened 1 year ago

OleksiyPetroKovalenko commented 1 year ago

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

I'm struggling to grasp how to utilize MathLive and the compute engine. When I check Gitter, I notice many others have posed similar queries, frequently repeating the same questions.

Describe the solution you'd like

Would you be able to supply a few straightforward sample applications showcasing the various functionalities and capabilities? For instance, I'm currently facing a minor issue, and our discussions have been extensive. If a sample program had been available, it could have eliminated the need for this prolonged conversation.

For my own needs, I'd like to ask for a sample that encompasses, at a minimum, the following. Other would I am sure benefit from a larger sample that showed how to use MathLive and the many other capabilities.

<!DOCTYPE html>
<html>
<head>

<script type="module" src="mathlive.ms"></script>
<script type="module" src="compute-engine.js"></script>

   <script type="module">
        document.addEventListener('DOMContentLoaded', function() {
        window.mf = document.getElementById('mf');

        import {ComputeEngine} from "compute-engine.js";

        const ce = new ComputeEngine({
            latexDictionary: [
            ...ComputeEngine.getLatexDictionary().filter((x) => x.name !== 'PlusMinus'),
            {
                trigger: ['\\smoll'],
                parse: function(parser) {
                return [
                    'Divide',
                    parser.matchRequiredLatexArgument() ?? ['Error', "'missing'"],
                    parser.matchRequiredLatexArgument() ?? ['Error', "'missing'"],
                ];
                },
            },
            ],
        });
        });
   </script>

</head>
<body>
     <math-field class="mf" id="mf" ></math-field>
  </body>
</html>

This doesn't use NPM, doesn't use external files. Just uses the source for your MathLive and ComputeEngine.

Describe alternatives you've considered

I've attempted the above solution, including relocating the script to a main.js file and performing the import from there. Despite dedicating several hours and exploring every possible avenue, I can't seem to access the static function getLatexDictionary. While I'll keep seeking guidance in the other thread, having a sample application to reference would simplify the process for all involved.

Additional context

I'm convinced that such a resource would be advantageous for everyone. It would not only save time but also simplify the process of understanding how to use the applications, easing the challenging learning curve for all. Even better, when you add new capabilities if you added those and updated the sample, we would all know what's available.

rs-mobitech commented 12 months ago

+1