cortex-js / compute-engine

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

\mathrm and a variable with sub-script causes error in evaluation #60

Closed aniketkotal closed 1 year ago

aniketkotal commented 2 years ago

@cortex-js/compute-engine: v0.8.0 from npm vue: v3.2.40 Minimal Stackblitz demo: https://stackblitz.com/edit/vue-agjdaa?file=src/App.vue

What's happening

Substituting any variable with 0 returns an evaluated equation with the variable substituted with 0 untouched.

What should happen

The variable should be treated as 0 and the equation should evaluate as normal

Steps to Reproduce

  1. Create a new ComputeEngine
  2. Parse a latex equation which has both a \mathrm and variable with subscript(ex: F_i) with the created CE. (take \pi-a-\mathrm{AD}-F_o as example)
  3. Substitute the variables with any values.
  4. Evaluate and check the output

Quick Demonstration

Equation: \pi-a-\mathrm{AD}-F_o Variables: AD: 1, F_o: 2, Pi: 3.14, a: 1 Expected Output: Evaluated output Actual Output: 1.14-\mathrm{F_{o}}

arnog commented 1 year ago

Fixed now.

Note that instead of .map((symbol) => symbol._name) you should use .map((x) => x.symbol). In general, properties prefixed with _ are for internal use only.