mika-cn / mathml2latex

A Javascript library to convert mathML to LaTeX
MIT License
43 stars 17 forks source link

sinh don't work properly #16

Closed Wenangsani closed 3 years ago

Wenangsani commented 3 years ago

why <mo>sinh</mo><mn>45</mn> become \sin h45?

murkle commented 3 years ago

Looks like it's checking for sin before sinh. Swapping the order so sinh is before sin doesn't seem to work though...

  parseMathFunction: function (it) {
    this.mathFunction.names.forEach((name, index) => {
      const regExp = new RegExp(name, 'g');
      if(it.match(regExp)){
        it = it.replace(regExp, this.mathFunction.scripts[index] + ' ');
      }
    });
    return it;
  },

    names: [
      "sin", "arcsin", "sinh", "sec",

    scripts: [
      "\\sin", "\\arcsin", "\\sinh", "\\sec",
murkle commented 3 years ago

Oh, changing the order does this sinh-> \\sinh but then sin is also replaced so it becomes \\\\sin h

mika-cn commented 3 years ago

@Wenangsani

Thanks for the feedback.

@murkle

Thanks for the really useful analysis. These overlap function names should be reordered and we need to avoid the \\\\sin h situation.

I'll fix it.

mika-cn commented 3 years ago

I've published version 1.1.2 to npm, it should work now.