logseq-live-math icon indicating copy to clipboard operation
logseq-live-math copied to clipboard

[FR] Add compute engine plugin to easily compute formulas too

Open simon-schober opened this issue 3 months ago • 4 comments

It would be really cool to be able to compute formulas using this Logseq plugin too and cortex-js/compute-engine already does this really well in the math field element itself by just adding an extra script. Here's a basic HTML example that adds this to a MathField element

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script src="https://unpkg.com/mathlive"></script>
  <script type="module">
    import "https://esm.run/@cortex-js/compute-engine"
  </script>
  <math-field id="mf" virtual-keyboard-mode="on"></math-field>
</body>

</html>
<!-- MathLive provides a <math-field> web component -->

I tried to implement this into the plugin, but there seems to be issues with a simple

import "https://esm.run/@cortex-js/compute-engine"
Uncaught Error: Dynamic require of "https://esm.run/@cortex-js/compute-engine" is not supported
    at index.js:1:402
    at index.js:155:1305
    at index.js:163:3967

as I don't think the configuration or Logseq itself or the build command allows this.

adding it using html in index.html also didn't work

  <script src="https://unpkg.com/mathlive"></script>
  <script src="https://cdn.jsdelivr.net/npm/@cortex-js/compute-engine/compute-engine.min.umd.js"></script>
  <script type="module" src="./dist/index.js"></script>
index.html:15 
GET https://cdn.jsdelivr.net/npm/@cortex-js/compute-engine/compute-engine.min.umd.js net::ERR_ABORTED 404 (Not Found)
index.html:1 Refused to execute script from 'https://cdn.jsdelivr.net/npm/@cortex-js/compute-engine/compute-engine.min.umd.js' because its MIME type ('text/plain') is not executable, and strict MIME type checking is enabled.

I don't have too much experience with any of the tech stack here, so I couldn't do it myself, but maybe this helps

simon-schober avatar Sep 26 '25 06:09 simon-schober

Could you add more context about how this feature is supposed to work, and why adding this feature would be helpful? Currently, I dont't think most of the users will benefit from this.

AllanChain avatar Sep 27 '25 15:09 AllanChain

When you add the ComputeEngine plugin like in my HTML example and the MathField element realises the ComputeEngine plugin is available, the MathField element automatically adds buttons to evaluate, simplify and expand the expression to the MathField element.

No developer has to code these three buttons in by himself, they are already in the upstream MathField element and set to appear when the ComputeEngine plugin is detected. This is already a feature of the upstream MathField element, the library just needs to be imported.

Try out my HTML example: When you type in an expression like 3(x+9) into the MathField component in my HTML example, then press the three vertical bars (so the button to the right of the keyboard logo), you see the buttons for the compute engine features that are already baked in to the MathField element. This is immensely helpful and is already a feature of the upstream elememt if I was just able to import the ComputeEngine plugin

This feature is immensely helpful for a student like me using this in math class for simplifying a term, calculating an expression (like 3+3) or similar, because it saves time over copying it into an external LaTex calculator and you just get the result right in Logseq

simon-schober avatar Sep 27 '25 16:09 simon-schober

Sorry, I accidentally closed the issue

simon-schober avatar Sep 27 '25 16:09 simon-schober

I have added compute engine support in b64b092. However, we have to wait for the next release of @cortex-js/compute-engine since the current version is bugged. If you want to try it today, you need to edit node_modules/.pnpm/@[email protected]/node_modules/@cortex-js/compute-engine/package.json and apply the changes as described by https://github.com/cortex-js/compute-engine/commit/102d5c1cd22818a44bb44163bf2f55245bab2b7d

AllanChain avatar Sep 28 '25 03:09 AllanChain