Custom MathJax configuration for Jupyter Lab - SVG output

I’m trying to write a custom configuration for my MathJax installation in Jupyter Lab. Ideally I’d like to control this via an extension, but for now I’m just trying to get this to work as a global configuration. The main functionality I am trying to achieve is changing the output format from MathML to SVG.

So far I have loaded a jupyter_notebook_config.json using a jupyter_lab_config.py script, which results in the following output after running python3 -m jupyterlab_server --show-config-json, where NotebookApp is the property I am targeting with configuration:

{
 "NotebookApp": {
  "mathjax_config": {
   "SVG": {
    "font": "STIX-Web"
   },
   "jax": [
    "input/TeX",
    "output/SVG"
   ],
   "tex2jax": {
    "displayMath": [
     [
      "$$",
      "$$"
     ],
     [
      "\\[",
      "\\]"
     ]
    ],
    "inlineMath": [
     [
      "$",
      "$"
     ],
     [
      "\\(",
      "\\)"
     ]
    ],
    "processEscapes": true
   }
  },
  "nbserver_extensions": {
   "jupyter_nbextensions_configurator": true
  }
 },

However, this does not lead to the expected behavior of output cells for MathJax being SVGs, and they are still MathML components in the DOM. Am I missing something in how this customization can be set? The MathJax documentation seems to configure this on a different key loader.load, but that also hasn’t worked for me.

If I recall correctly mathjax_config was used for an older version of MathJax and has no effect on the current version. I think that customising MathJax would right now be in fact easier with an extension, but if you think some options would be universally useful I would suggest opening a feature request issue on JupyterLab’s GitHub :slight_smile:

Thanks for the response! In that case, I’ll focus my efforts on doing it via extension.

In looking at the Jupyter Lab repositories, it looks like renderers live in jupyterlab/jupyter-renderers, but I’m curious if those packages are automatically included in a base build of Jupyter Lab or if they are only there for users that want to create custom configurations for renderers (e.g. by running pip install jupyterlab-mathjax2 in a conda environment for jupyterlab) ? When I inspect the page for Jupyter Lab, I can see in the initial script that a specific MathJax script is going to be loaded from a CDN, but I don’t see any other indication of how/where MathJax is integrated/loaded in Jupyter Lab (and how to interact with it).

  "fullMathjaxUrl": "https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.7/MathJax.js",

No fullMathjaxUrl, this is not used by default in modern JupyterLab version (4.0+) either. This is just there for compatibility with older versions (JupyterLab <4 or with jupyterlab_mathjax2 installed) and comes from a jupyter-server extension.

MathJax is integrated via a renderer package, the default which is shipped with JupyterLab is here:

And the old version can still be used by installing an alternative:

or one can install katex:

The alternative plugins basically disable the built-in one (Develop Extensions — JupyterLab 4.2.4 documentation) and provide the same mime renderer interface.

You could depend on ILatexTypesetter and assuming that you know it will be a MathJaxTypesetter you could try accessing the mathDocument property.

1 Like