mhchem / MathJax-mhchem

3rd-party extension to MathJax for typesetting chemical equations
Apache License 2.0
95 stars 13 forks source link

t.slice is not a function #20

Closed abnerlee closed 2 years ago

abnerlee commented 3 years ago

Hi, we received an error t.slice is not a function in our sentry server. Sorry, I didn't find the TeX script to trigger this issue.

But I guess it happens in

MhchemMethods.Machine = function(parser: TexParser, name: string, machine: string) {
  try {
    let arg = parser.GetArgument(name);
    let data = mhchemParser.go(arg, machine);
    // TODO: Harvest chemical information here from data, test looping through
    //       the array.
    let tex = texify.go(data);
    parser.string = tex + parser.string.substr(parser.i);
    parser.i = 0;
  } catch (err) {
    throw new TexError(err[0], err[1], err.slice(2));
  }
};

where err is not an Array in some cases (maybe Error thrown in some of the logic inside)

mhchem commented 3 years ago

It's a pity you did not find the TeX code to trigger this issue. What version of MathJax are you using? Do you use an external version of mhchem or the integrated one?

abnerlee commented 3 years ago

MathJax 3.2.0, I'm using the tex-svg-full.js built by MathJax.

From the code, if any unexpected Error throws in

let arg = parser.GetArgument(name);
let data = mhchemParser.go(arg, machine);
let tex = texify.go(data);

Then, err will be an Error type, which do not have the .slice function. Only expected ones (thrown by your code), it would be OK.

mhchem commented 3 years ago

@abnerlee Were you able to find TeX input that triggers the issue?

abnerlee commented 3 years ago

Sorry, No~ We found it in our sentry server, not from customers' report, so we don't know user's exact input.

abeeonthemoon commented 2 years ago

Hi!

I had an issue that was similar to this. I am using a library called rehype-mathjax to render my mathjax. Currently rehype-mathjax uses the latest version of mathjax. The issue occurred when I typed \ce in the editor.

Note: When I copy and paste the following equation: \ce{CO2 + C -> 2 CO}, it works perfectly fine. However when I am in the process of typing input, then by the time I type \ce that's when I get this error.

Please let me know if I can provide anything else to present this issue. Thank you.

wb-joona commented 2 years ago

I was able to reproduce this issue with MathJax 3.2.0. It's caused by a missing closing bracket in the input. Try rendering \ce{H2O for example (demo)

The issue is that the caught error is not an array like the catch block in MathJax assumes, but e.g.

{
  id: 'MissingCloseBrace',
  message: 'Missing close brace'
}

which does not have a .slice() method.

mhchem commented 2 years ago

That demo was very helpful. I think the bug is with MhchemConfiguration. See my comments in the MathJax issue linked above.

dpvc commented 2 years ago

I have made a PR to MathJax-src that addresses the issue.