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

Setting latexOptions before setting latexDictionary causes custom latexDictionary entries to be ignored #170

Closed lafkpages closed 2 months ago

lafkpages commented 2 months ago

Description

(Optional) Provide a brief summary of the issue.

Adding custom entries to the latexDictionary usually works as intended. However, if you modify latexOptions before modifying latexDictionary, any custom dictionary entries get ignored. This does not happen when latexOptions are modified after modifying latexDictionary.

Steps to Reproduce

import { ComputeEngine } from "@cortex-js/compute-engine";

const ce = new ComputeEngine();

ce.latexOptions.fractionStyle = () => "quotient";

ce.latexDictionary = [
  ...ce.latexDictionary,
  {
    name: "Absolute",
    kind: "matchfix",
    openTrigger: ["\\left|"],
    closeTrigger: ["\\right|"],
    serialize(serializer, expr) {
      return `\\left|${serializer.serialize(expr[1])}\\right|`;
    },
  },
];

console.log(ce.box(["Absolute", "2"]).latex);

Actual Behavior

The code outputs \mathrm{Absolute}(2).

Expected Behavior

The code outputs \left|2\right|.

Environment

Operating System macOS 14.3.1

Browser Node and Bun

arnog commented 2 months ago

The latexOptions property has been removed. Specify an argument with expr.toLatex() or ce.parse() instead.