# Custom MathJax configuration for Jupyter Lab - SVG output

**URL:** https://discourse.jupyter.org/t/custom-mathjax-configuration-for-jupyter-lab-svg-output/27621
**Category:** JupyterLab
**Tags:** how-to, help-wanted
**Created:** [August 15, 2024, 3:58pm UTC](https://discourse.jupyter.org/t/custom-mathjax-configuration-for-jupyter-lab-svg-output/27621 "2024-08-15T15:58:11Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![mclare](https://avatars.discourse-cdn.com/v4/letter/m/0ea827/32.png) [@mclare](https://discourse.jupyter.org/u/mclare)
#### Post date: [August 15, 2024, 3:58pm UTC](https://discourse.jupyter.org/t/custom-mathjax-configuration-for-jupyter-lab-svg-output/27621/1 "2024-08-15T15:58:11Z")

</div>

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:

```auto
{
 "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](https://docs.mathjax.org/en/latest/web/configuration.html#loading-components-individually) seems to configure this on a different key `loader.load`, but that also hasn’t worked for me.

---

<div class="post-metadata">

### Author: ![krassowski](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.jupyter.org/krassowski/32/1685_2.png) [@krassowski](https://discourse.jupyter.org/u/krassowski)
#### Post date: [August 18, 2024, 8:43pm UTC](https://discourse.jupyter.org/t/custom-mathjax-configuration-for-jupyter-lab-svg-output/27621/2 "2024-08-18T20:43:32Z")

</div>

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 🙂

---

<div class="post-metadata">

### Author: ![mclare](https://avatars.discourse-cdn.com/v4/letter/m/0ea827/32.png) [@mclare](https://discourse.jupyter.org/u/mclare)
#### Post date: [August 18, 2024, 9:53pm UTC](https://discourse.jupyter.org/t/custom-mathjax-configuration-for-jupyter-lab-svg-output/27621/3 "2024-08-18T21:53:05Z")

</div>

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](https://github.com/jupyterlab/jupyter-renderers?tab=readme-ov-file), 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).

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

```

---

<div class="post-metadata">

### Author: ![krassowski](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.jupyter.org/krassowski/32/1685_2.png) [@krassowski](https://discourse.jupyter.org/u/krassowski)
#### Post date: [August 19, 2024, 8:17am UTC](https://discourse.jupyter.org/t/custom-mathjax-configuration-for-jupyter-lab-svg-output/27621/4 "2024-08-19T08:17:54Z")

</div>

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:

> **[jupyterlab/packages/mathjax-extension at main · jupyterlab/jupyterlab](https://github.com/jupyterlab/jupyterlab/tree/main/packages/mathjax-extension)**
>
> JupyterLab computational environment. Contribute to jupyterlab/jupyterlab development by creating an account on GitHub.

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

> **[jupyter-renderers/packages/mathjax2-extension at main ·...](https://github.com/jupyterlab/jupyter-renderers/tree/main/packages/mathjax2-extension)**
>
> Renderers and renderer extensions for JupyterLab. Contribute to jupyterlab/jupyter-renderers development by creating an account on GitHub.

or one can install katex:

> **[jupyter-renderers/packages/katex-extension at main ·...](https://github.com/jupyterlab/jupyter-renderers/tree/main/packages/katex-extension)**
>
> Renderers and renderer extensions for JupyterLab. Contribute to jupyterlab/jupyter-renderers development by creating an account on GitHub.

The alternative plugins basically disable the built-in one ([Develop Extensions — JupyterLab 4.2.4 documentation](https://jupyterlab.readthedocs.io/en/stable/extension/extension_dev.html#disabling-other-extensions)) 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.
