cortex-js / compute-engine

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

[FEATURE] Include support for phi #148

Closed rwmorton closed 7 months ago

rwmorton commented 7 months ago

Is your feature request related to a problem? Please describe. It would be nice to include the phi symbol. What I do currently is I parse the latex and replace any occurence of \phi with the value of phi itself as a latex fraction.

eg. useLatex = useLatex.replaceAll(/\\phi/g, '\\frac{1 + \\sqrt{5}}{2}')

Describe the solution you'd like It would be nice for compute-engine to support phi natively.

Describe alternatives you've considered Pre-processing of the latex before giving it to compute-engine.

arnog commented 7 months ago

The LaTeX command \varphi already maps to GoldenRatio.

If you want the \phi command to also map to GoldenRatio, use:

ce.latexDictionary = [
  ...ce.latexDictionary,
  {
    latexTrigger: "\\phi",
    parse: "GoldenRatio",
  }
];
rwmorton commented 7 months ago

Ah great thank you so much!