Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

\def commands containing numbers #2901

Open
hbghlyj opened this issue Jul 15, 2022 · 2 comments
Open

\def commands containing numbers #2901

hbghlyj opened this issue Jul 15, 2022 · 2 comments
Labels
Accepted Issue has been reproduced by MathJax team Code Example Contains an illustrative code example, solution, or work-around Merged Merged into develop branch Test Needed v2 v3
Milestone

Comments

@hbghlyj
Copy link

hbghlyj commented Jul 15, 2022

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
@dpvc
Copy link
Member

dpvc commented Jul 18, 2022

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
Copy link
Member

dpvc commented Jul 19, 2022

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 dpvc added Test Needed Code Example Contains an illustrative code example, solution, or work-around labels Jul 19, 2022
@dpvc dpvc added this to the 3.3.0 milestone Aug 5, 2022
dpvc added a commit to mathjax/MathJax-src that referenced this issue Aug 12, 2022
Fix handling of template macros with no actual arguments. (mathjax/MathJax#2901)
@dpvc dpvc added Merged Merged into develop branch and removed Ready for Review labels Aug 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Accepted Issue has been reproduced by MathJax team Code Example Contains an illustrative code example, solution, or work-around Merged Merged into develop branch Test Needed v2 v3
Projects
None yet
Development

No branches or pull requests

2 participants