MathJax-mhchem icon indicating copy to clipboard operation
MathJax-mhchem copied to clipboard

t.slice is not a function

Open abnerlee opened this issue 3 years ago • 8 comments

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)

abnerlee avatar Jul 23 '21 09:07 abnerlee

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?

mhchem avatar Jul 23 '21 10:07 mhchem

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.

abnerlee avatar Jul 24 '21 01:07 abnerlee

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

mhchem avatar Sep 13 '21 20:09 mhchem

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

abnerlee avatar Sep 15 '21 06:09 abnerlee

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.

abeeonthemoon avatar Oct 26 '21 03:10 abeeonthemoon

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.

wb-joona avatar Feb 14 '22 11:02 wb-joona

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

mhchem avatar Feb 14 '22 16:02 mhchem

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

dpvc avatar Feb 19 '22 00:02 dpvc