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

The option 'family' for tex2svg / tex2chtml has no default value #2512

Closed
christianp opened this issue Aug 27, 2020 · 3 comments
Closed

The option 'family' for tex2svg / tex2chtml has no default value #2512

christianp opened this issue Aug 27, 2020 · 3 comments
Labels
Accepted Issue has been reproduced by MathJax team Fixed Test Needed v3 v3.1
Milestone

Comments

@christianp
Copy link
Contributor

I use MathJax.getMetricsFor to get an options object for tex2chtml or tex2svg, as described in the typesetting page in the docs.

It includes an attribute family whose value is the empty string. When I pass the object to tex2chtml, I get an error "Invalid option "family" (no default exists)". So it looks easy to fix, but I don't know where to look for the default values.

Here's a node script which produces the error:

const MathJax = require('mathjax');

MathJax.init({
    loader: {load: ['input/tex', 'output/svg']}
}).then(MathJax => {
    const svg = MathJax.tex2svg('2x',{family:''});
}).catch(err => {
    console.error(err);
});

(I'd love to fix this myself, but I can't remember how to run unminified MathJax v3)

@dpvc dpvc added Accepted Issue has been reproduced by MathJax team v3 labels Aug 27, 2020
@dpvc
Copy link
Member

dpvc commented Aug 27, 2020

Ok, this is caused by the addition of the family property to the extended metric data used by the HTML MathDocument class, which was not taken into account by the convert() macro that underlies tex2svg() and the other similar conversion functions. Unfortunately, the default list is not in a place that is easily adjusted on the fly. Here is a configuration that can be used to replace the convert() function with a fixed one. This not only allows the family property, but actually handles it to provide support for mtextInheritFont and the other similar output options.

<script>
MathJax = {
  startup: {
    ready() {
      const {HTMLDocument} = MathJax._.handlers.html.HTMLDocument;
      const {userOptions} = MathJax._.util.Options;
      const {STATE} = MathJax._.core.MathItem;
      HTMLDocument.prototype.convert = function (math, options = {}) {
        let {family, format, display, end, ex, em, containerWidth, lineWidth, scale} = userOptions({
          family: '', format: this.inputJax[0].name, display: true, end: STATE.LAST,
          em: 16, ex: 8, containerWidth: null, lineWidth: 1000000, scale: 1
        }, options);
        if (containerWidth === null) {
          containerWidth = 80 * ex;
        }
        const jax = this.inputJax.reduce((jax, ijax) => (ijax.name === format ? ijax : jax), null);
        const mitem = new this.options.MathItem(math, jax, display);
        if (this.outputJax.options.mtextInheritFont) {
          mitem.outputData.mtextFamily = family;
        }
        if (this.outputJax.options.merrorInheritFont) {
          mitem.outputData.merrorFamily = family;
        }
        mitem.start.node = this.adaptor.body(this.document);
        mitem.setMetrics(em, ex, containerWidth, lineWidth, scale);
        mitem.convert(this, end);
        return (mitem.typesetRoot || mitem.root);
      };
      MathJax.startup.defaultReady();
    }
  }
};
</script>

It is longer than I would like, but you have to replace the entire convert() function in order to make the needed changes. I will make a PR that fixes the function for the next release. We'll probably have to make a point release to fix this. Sigh.

@Niranjan-Rathod
Copy link

When will this fix be released?

@dpvc
Copy link
Member

dpvc commented Sep 6, 2020

We are hoping to get a release out later this week.

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 Fixed Test Needed v3 v3.1
Projects
None yet
Development

No branches or pull requests

3 participants