mathjax / MathJax-demos-web

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

Properly translating skipStartupTypeset into v3 config #16

Closed dainiak closed 4 years ago

dainiak commented 5 years ago

Currently there is the line skipStartupTypeset: Translate.transfer('startup.typeset'), in the automated translator. But if skipStartupTypeset was true in MJ2, then the typeset parameter should be false in MJ3 and vice versa.

dainiak commented 5 years ago

Tried to fix this myself, yet internal config v2 parser does not parse things JSON style, so I didn’t manage to make skipStartupTypeset: true and skipStartupTypeset: false both convert smoothly. Currently tried something like:

  identityMap: function(x) {
    return x;
  },

  booleanNegation: function(x) {
    return !x;
  },

  transfer: function (name, mapping=Translate.identityMap) {
    return function (prefix, key, value, config) {
      Translate.checkValue(prefix, key, value) && Translate.set(name, mapping(value), config);
    }
  },

…

skipStartupTypeset: Translate.transfer('startup.typeset', Translate.booleanNegation),
dpvc commented 5 years ago

I've made a PR that fixe this problem (and one with autoNumber) based on your suggestion of adding a transformation function to the transfer() method.

internal config v2 parser does not parse things JSON style

This is because the MathJax v2 config is not JSON (e.g., it can have values that are functions, can have expressions that produce the values, can include comments, and so on). So the parsing ends up being a bit complicated (and a bit fragile as well). It also tries to retain comments that might be in the original when it can.

The value parameters are actually arrays that are made up of two parts: the value of the key (as a string) and the comment that follows if, if any. So your !x was being applied to the array. My PR deals with the array properly.