asnunes / mathml-to-latex

A JavaScript tool to convert mathml string to LaTeX equation string.
MIT License
55 stars 14 forks source link

using <mmultiscripts> resuts in TypeError: Cannot destructure property 'name' of 'this._mathMLElement' as it is undefined. #27

Closed jamesrchen closed 3 weeks ago

jamesrchen commented 3 months ago

When using the following code with ts-node:

import { MathMLToLaTeX } from 'mathml-to-latex';

const mathml = `
  <math xmlns="http://www.w3.org/1998/Math/MathML"><mmultiscripts><mi mathvariant="normal">U</mi><mprescripts></mprescripts><mn>238</mn></mmultiscripts></math>
`;

console.log(MathMLToLaTeX.convert(mathml));

There is a resulting error:

> ts-node test.ts
webpack://MathMLToLaTeX/./src/data/usecases/mathml-to-latex-convertion/mathml-element-to-latex-converter-adapter.ts:13
    const { name } = this._mathMLElement;
            ^
TypeError: Cannot destructure property 'name' of 'this._mathMLElement' as it is undefined.
    at t.MathMLElementToLatexConverterAdapter.toLatexConverter (webpack://MathMLToLaTeX/./src/data/usecases/mathml-to-latex-convertion/mathml-element-to-latex-converter-adapter.ts:13:13)
    at mathMLElementToLaTeXConverter (webpack://MathMLToLaTeX/./src/data/helpers/mathml-element-to-latex-converter.ts:6:59)
    at t.MMultiscripts._prescriptLatex (webpack://MathMLToLaTeX/./src/data/usecases/mathml-to-latex-convertion/converters/mmultiscripts.ts:38:22)
    at t.MMultiscripts.convert (webpack://MathMLToLaTeX/./src/data/usecases/mathml-to-latex-convertion/converters/mmultiscripts.ts:21:17)
    at map (webpack://MathMLToLaTeX/./src/data/usecases/mathml-to-latex-convertion/converters/math.ts:16:37)
    at Array.map (<anonymous>)
    at t.Math.convert (webpack://MathMLToLaTeX/./src/data/usecases/mathml-to-latex-convertion/converters/math.ts:16:8)
    at map (webpack://MathMLToLaTeX/./src/main/mathml-to-latex.ts:11:53)
    at Array.map (<anonymous>)
    at Function.convert (webpack://MathMLToLaTeX/./src/main/mathml-to-latex.ts:11:8)

With vanilla javascript, the conversion results in an empty string. Both behaviors are unexpected and I suspect this has to do with the use of mmultiscripts?

asnunes commented 3 weeks ago

Hey, @jamesrchen!

The issue with mmultiscripts should now be fixed in v1.4.3. Appreciate the heads-up!