mathjax / MathJax-demos-web

A repository with examples using mathjax-v3
https://mathjax.github.io/MathJax-demos-web
Apache License 2.0
256 stars 106 forks source link

Demo of tagFormat #14

Closed Miniland1333 closed 5 years ago

Miniland1333 commented 5 years ago

https://mathjax.github.io/mj3-demos/#tex-extensions I'm attempting to use tagFormat as a replacement for equationNumbers from v2, but I haven't been able to figure out the syntax in the configuration using trial-and-error since I thought that the syntax would be somewhat similar to equationNumbers.

Other than this, my testing indicates that v3 will be a nice improvement for our application!

Miniland1333 commented 5 years ago
MathJax = {
  tex: {
     macros: {
        test: ["{"+front+" #1}",1]
     },
     tags: "all",
     tagFormat: function (n) {
        return `Equation ${n}`;
     }
  }
};
dpvc commented 5 years ago

I think what you want is

MathJax = {
  tex: {
     packages: {'[+]': ['tagFormat']},   // add it to the default packages
     macros: {
        test: ["{"+front+" #1}",1]
     },
     tags: "all",
     tagFormat: {
        number: function (n) {
          return `Equation ${n}`;
       }
    }
  }
};

You can also specify tag, id, and url functions. The defaults are:

    tagFormat: {
        number: (n) => n.toString(),
        tag:    (tag) => '(' + tag + ')',
        id:     (id) => 'mjx-eqn-' + id.replace(/\s/g, '_'),
        url:    (id, base) => base + '#' + encodeURIComponent(id),
    }

I hope that clears it up for you.

Sorry for not getting back to you sooner; I only just saw the message today (for some reason, I wasn't signed up to get automatic emails for this tracker!).

Miniland1333 commented 5 years ago

From the console: MathJax(?): Invalid option "tagFormat" (no default value).

MathJax = {
  tex: {
     packages: {"[+]": ["tagFormat"]},
     macros: {
        test: ["{"+front+" #1}",1]
     },
      tags: "all",
      tagFormat: {
          number: function (n) {
                    return `Equation ${n}`;
                   }
      }
  }
};

I think this is functionally equivalent to the code above, so I am not sure what is still incorrect. If it matters, I am using https://github.com/mathjax/mj3-demos/blob/master/mathjax3/tex-chtml.js as the javascript file since you had it precompiled for the demos and it seemed to be working just fine there. Maybe I have to specially compile in order to include tagFormat?

dpvc commented 5 years ago

This probably means you haven't loaded the tagFormat extension. Try

MathJax = {
  loader: {
     load: ['[tex]/tagFormat']
  },
  tex: {
     packages: {"[+]": ["tagFormat"]},
     macros: {
        test: ["{"+front+" #1}",1]
     },
     tags: "all",
     tagFormat: {
         number: function (n) {
             return `Equation ${n}`;
         }
      }
  }
};
Miniland1333 commented 5 years ago

Finally had a chance to test the loader and it worked! Do you think the documentation needs any updating to include this example of loading and using tagFormat?

dpvc commented 5 years ago

The documentation for v3 is still being written, and yes, tagFormat should be included in that.

Miniland1333 commented 5 years ago

Thanks!