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

Some symbols are not rendered #3272

Open
vivek-shadija opened this issue Aug 15, 2024 · 2 comments
Open

Some symbols are not rendered #3272

vivek-shadija opened this issue Aug 15, 2024 · 2 comments
Labels
Expected Behavior This is how MathJax works

Comments

@vivek-shadija
Copy link

Issue: Below mentioned 4 math commands are not recognized by mathjax and they are not rendered.

  1. \parallelogram
  2. \overarc{x}
  3. \questeq
  4. \longdiv{x}
@dpvc
Copy link
Member

dpvc commented Aug 16, 2024

First, you have filed this issue in the wrong place. As the issue template indicates, this issue tracker is only for structural problems with the source code repository, not for general MathJax issues, which should be filed here. Don't just erase the information given in the issue template and ignore it.

I am transferring this issue to the proper issue tracker.

@dpvc dpvc transferred this issue from mathjax/MathJax-src Aug 16, 2024
@dpvc dpvc added the Expected Behavior This is how MathJax works label Aug 16, 2024
@dpvc
Copy link
Member

dpvc commented Aug 16, 2024

Not every LaTeX command is implemented in MathJax, and none of these is. You can find a list of the commands that are available in the documentation. You don't indicate which version of MathJax you are using, so I've pointed to the v3 documentation.

For \parallelogram you could use \unicode{x25B1}, and could do \newcommand{\parallelogram}{\unicode{0x25B1}} to define \parallelogram to produce that.

For \overarc perhaps the best substitute is \overparen, and you can do \let\overarc=\overparen to define \overarc to produce that.

For \questeq you could use \stackrel{?}{=} and could do \newcommand{\questeq}{\stackrel{?}{=}} to define \questeq to equal that.

These three could be added to your MathJax configuration as described in the documentation.

The \longdiv macro is more challenging. If you are looking for \longdiv{num}{den} where num and den are integers, then there is an old v2 implementation here. For v4, I worked up a configuration that implements it:

MathJax = {
  tex: {
    packages: {'[+]': ['longdiv']}   
  },
  startup: {
    ready() {
      const {Configuration} = MathJax._.input.tex.Configuration;
      const {CommandMap} = MathJax._.input.tex.TokenMap;
      const TexError = MathJax._.input.tex.TexError.default;
      const TexParser = MathJax._.input.tex.TexParser.default;
      
      new CommandMap('longdiv', {
        longdiv: 'LongDiv'
      }, {
        LongDiv(parser, name) {
          const num = parser.GetArgument(name);
          const den = parser.GetArgument(name);
          if (!num.match(/^\d+$/) || !den.match(/^\d+/)) {
            throw new TexError('LONGDIV:NumDen', 'Numerator and denominator of %1 must be positive integers', name);
          }
          const n = parseInt(num);
          const d = parseInt(den);
          const q = Math.floor(n / d);
          let m = n;
          const tex = [
            '\\begin{array}[t]{r}',
            `${q} \\kern.2em \\\\[-3px]`,
            `${d}\\kern.1em \\enclose{longdiv}{\\kern.075em ${n}} \\\\[-4px]`
          ];
          const digits = String(q).split('');
          while (digits.length) {
            const digit = parseInt(digits.shift() + digits.join('').replace(/./g, '0'));
            if (digit === 0) continue;
            const p = d * digit;
            m -= p;
            tex.push(
              `\\underline{\\kern .2em ${p}\\Space{.2em}{0em}{.125em}} \\\\[-3px]`,
              `${m}\\Space{.2em}{0em}{.125em} \\\\[-4px]`
            );
          }
          tex.push('\\end{array}');
          parser.Push(new TexParser(tex.join('\n'), parser.stack.env, parser.configuration).mml());
        }
      });
      
      Configuration.create('longdiv', {
        handler: {
          macro: ['longdiv']
        }
      });
      
      MathJax.startup.defaultReady();
    }
  }
};

If you are using v3, this should also work there, with one change: TokenMap should be changed to SymbolMap in the second line of the ready() function.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Expected Behavior This is how MathJax works
Projects
None yet
Development

No branches or pull requests

2 participants