0

I use MathJax with my Jekyll blog on GitHub Pages. In fact, I wrote a blog post on exactly what steps I took to set up MathJax 2.7.5: "MathJax in Jekyll" (August 2018)

For a couple of posts, I wanted to use a psmallmatrix environment, like the one from the mathtools package: $$\begin{psmallmatrix} 1 \\ 0 \end{psmallmatrix}$$. I know how I would create such an environment in actual TeX, using the \newenvironment command: "How do I make a small pmatrix?"

But to get the command "pre-loaded" in MathJax 2.7.5, I was doing this, cargo-culting some code from MathJax's version of the AMSmath package:

<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>

Sometime in the past year or so, MathJax 2.7.5 completely 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 MathJax's own config converter, but I don't know what to do about my hand-crafted psmallmatrix. 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>

How can I recover my hand-crafted psmallmatrix environment, in MathJax 3.0? The formatting need only be roughly equivalent, as long as I can keep invoking it with \begin{psmallmatrix}.

I should mention that the MathJax docs on "Defining TeX Macros" give an example of how to "preload" the TeX parser with a macro, roughly equivalent to what \newcommand would do. The docs say:

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.

2
  • 1
    I crossposted this question on the MathJax Users forum a week ago, but it seems pretty dead over there. Aug 15, 2020 at 16:04
  • The un-minified source code for MathJax 3's ams extension is here (and its sibling source files), but I can't figure out how MathJax finds one bit of code from another. Aug 17, 2020 at 14:32

1 Answer 1

2
+200

Below is a configuration that adds the psmallmatrix environment to the AMS environment list. There should be a method to pre-configure 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.AmsMethods.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.

11
  • When I try this, I get a JS error that Safari console reports as Unhandled Promise Rejection: TypeError: t.setAttribute is not a function. (In 't.setAttribute(e,r)', 't.setAttribute' is undefined) and Chrome console reports as Uncaught (in promise) TypeError: t.setAttribute is not a function / at c.setAttribute (tex-chtml.js:1) at e.assistiveMml (tex-chtml.js:1) [...] at new Promise (<anonymous>). Thoughts? Aug 18, 2020 at 20:45
  • Try disabling the assistive-mml extension (where Chrome says the error is occurring) by adding options: {renderActions: {assistiveMml: []}} to the configuration (at the top level), and see if that lets the page process. Also, this may be related to the content of the page (it worked on the page you sent me). Are there any escaped dollar signs on the page? Aug 18, 2020 at 21:00
  • Also, if you remove the configuration, does the page process (other than the missing psmallmatrix environments)? Aug 18, 2020 at 21:03
  • it worked on the page you sent me — You mean this page renders for you? For me, after adding ready(), I see this. After removing ready() again, I see this. After re-adding it and disabling assistiveMml, I see this. Aug 18, 2020 at 21:18
  • 1
    Change default to AmsMethods in the line that defines the Array variable. Version 3.1.2 changed that structure. Feb 15, 2021 at 10:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.