MathJax icon indicating copy to clipboard operation
MathJax copied to clipboard

\def commands containing numbers

Open hbghlyj opened this issue 3 years ago • 2 comments

Issue Summary

The error occurs when using \def to define a command containing numbers, for example

\def\b0{{\bf0}}

Steps to Reproduce:

In MathJax: image

In LaTeX : image

Technical details:

  • MathJax Version: 3.2
  • Client OS: Windows 11
  • Browser: Firefox

hbghlyj avatar Jul 15 '22 19:07 hbghlyj

Note that TeX control sequences can't contain numbers, so what you are actually doing is defining \b with a template that requires it to be followed by 0. It looks like there is a bug with macros that have templates but no arguments. I will look into it.

dpvc avatar Jul 18 '22 18:07 dpvc

I have submitted a pull request that resolves the problem, and it should be in the next release. In the meantime, you can use the configuration

MathJax = {
  startup: {
    ready() {
      const TexError = MathJax._.input.tex.TexError.default;
      const ParseUtil = MathJax._.input.tex.ParseUtil.default;
      const NewcommandUtil = MathJax._.input.tex.newcommand.NewcommandUtil.default;
      const NewcommandMethods = MathJax._.input.tex.newcommand.NewcommandMethods.default;
      const MacroWithTemplate = NewcommandMethods.MacroWithTemplate;
      NewcommandMethods.MacroWithTemplate = function (parser, name, text, n, ...params) {
        const argCount = parseInt(n);
        if (argcount || !params.length) {
          MacroWithTemplate(parser, name, text, n, ...params);
        } else {
          parser.GetNext();
          if (params[0] && !NewcommandUtil.MatchParam(parser, params[0])) {
            throw new TexError('MismatchUseDef', 'Use of %1 doesn\'t match its definition', name);
          }
          parser.string = ParseUtil.addArgs(parser, text, parser.string.slice(parser.i));
          parser.i = 0;
          ParseUtil.checkMaxMacros(parser);
        }
      }
      MathJax.startup.defaultReady();
    }
  }
};

to work around the problem.

dpvc avatar Jul 19 '22 11:07 dpvc