Upgrading from 2.7.5 to 3.0, trying to preserve a custom TeX command

52 views
Skip to first unread message

arthur....@gmail.com

unread,
Aug 10, 2020, 9:15:04 PM8/10/20
to MathJax Users
Please read this question even if it starts off irrelevant to you! I suspect the answer might be something simple.

I wrote a blog post in 2018 on how to use MathJax 2.7.5 with GitHub Pages:

At the moment, my blog's _includes/mathjax.js is using MathJax 2.7.5 (or thereabouts), and looks like this.
The tricky part here is that I hand-crafted a \psmallmatrix{} environment by cargo-culting some code from the old AMSmath package.
I use \psmallmatrix{} in at least two of my blog posts.

<script type="text/x-mathjax-config">

  MathJax.Hub.Config({

    extensions: [

      "MathMenu.js",

      "MathZoom.js",

      "AssistiveMML.js",

      "a11y/accessibility-menu.js"

    ],

    jax: ["input/TeX", "output/CommonHTML"],

    TeX: {

      extensions: [

        "AMSmath.js",

        "AMSsymbols.js",

        "noErrors.js",

        "noUndefined.js",

      ]

    }

  });

  MathJax.Hub.Register.StartupHook("TeX Jax Ready",function () {

    var TEX = MathJax.InputJax.TeX;

    var COLS = function (W) {

      var WW = [];

      for (var i = 0, m = W.length; i < m; i++)

        {WW[i] = TEX.Parse.prototype.Em(W[i])}

      return WW.join(" ");

    };

    TEX.Definitions.Add({

      environment: {

        psmallmatrix: ['Array',null,'(',')','c',COLS([1/3]),".2em",'S',1],

      }

    });

  });

</script>

<script type="text/javascript" async

  src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/latest.js">

</script>



Somehow MathJax 2.7.5 stopped working on GitHub, so I'm trying to upgrade to MathJax 3.0.

I have managed to translate the non-tricky parts of this config by using the config converter:

However, I don't know what to do about my hand-crafted \psmallmatrix{} environment.
Here's what I have now:

<script type="text/javascript">

window.MathJax = {

  tex: {

    packages: ['base', 'ams'],

  },

  loader: {

    load: ['ui/menu', '[tex]/ams'],

  }

};

</script>

<script type="text/javascript" id="MathJax-script" async

  src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-chtml.js">

</script>


Can I recover my hand-crafted \psmallmatrix{} environment, in MathJax 3.0?
How should my MathJax 3.0 configuration look?

Rough equivalents are acceptable.
For example, if you can tell me how to "pre-load" my TeX environment with
    \newenvironment{psmallmatrix} {\left(\begin{smallmatrix}}{\end{smallmatrix}\right)}
then that would be good enough.

Or, if the solution is for someone to implement the "mathtools" package (which provides \psmallmatrix out of the box), that'd be cool with me, as long as I'm not the one who has to implement it!

Thanks,
Arthur

arthur....@gmail.com

unread,
Aug 10, 2020, 9:30:33 PM8/10/20
to MathJax Users
Ah, I should have mentioned that
gives an example of how to "preload" the TeX parser with a macro, roughly equivalent to what \newcommand would do.
window.MathJax = {
  tex: {
    macros: {
      RR: "{\\bf R}",
      bold: ["{\\bf #1}", 1]
    }
  }
};

But the docs are missing any examples of how to do the same kind of thing for \newenvironment.
If the docs had contained an example of "preloading" a \newenvironment via something like
MathJax = {
  tex: {
    environments: {
      psmallmatrix: "{\left(\begin{smallmatrix}}{\end{smallmatrix}\right)}",
    }
  }
};
then I wouldn't have needed to ask this question.
(But as it stands, all I know is that the syntax above is incorrect. I don't know whether there exists any simple syntax for what I'm trying to do.)

–Arthur

Davide Cervone

unread,
Aug 18, 2020, 4:19:07 PM8/18/20
to mathja...@googlegroups.com
Here is a configuration that adds the psmallmatrix environment to the AMS environment list.  That is probably the easiest way to handle this for now.  There needs to be something like what you are suggesting below for the environments that is similar to what is done for macros.  I've made a feature request for it in the MathJax GitHub repository.

For now, add

<script>
MathJax = {
  startup: {
    ready() {
      MathJax.startup.defaultReady();
      const Macro = MathJax._.input.tex.Symbol.Macro;
      const MapHandler = MathJax._.input.tex.MapHandler.MapHandler;
      const Array = MathJax._.input.tex.ams.AmsMethods.default.Array;
      const env = new Macro('psmallmatrix', Array, [null,'(',')','c',['.333em'],'.2em','S',1]);
      
MapHandler.getMap('AMSmath-environment').add('psmallmatrix', env);
    }
  }
};

</script>

as your configuration to enable the psmallmatrix environment.

Davide



--
You received this message because you are subscribed to the Google Groups "MathJax Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mathjax-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mathjax-users/7edad66f-5274-47af-91b7-7813022b25d3o%40googlegroups.com.

Reply all
Reply to author
Forward
0 new messages