jupyter / nbconvert

Jupyter Notebook Conversion
https://nbconvert.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
1.72k stars 564 forks source link

Switch to Mathjax 3 #1706

Open ktarplee opened 2 years ago

ktarplee commented 2 years ago

MathJax 3 is superior to MathJax 2 in every way so why not upgrade. MathJax 3 renders the math much faster. It is also smaller. MathJax 2.7.7 is ~177 MB while MathJax 3.2.0 is only 17 MB. When dockerizing

Simply change the MathJax config (in the HTML template) to support MathJax 3 and switch the default URl to MathJax 3.

It is not possible to simply change the mathjax_url to point to MathJax 3 since the config for MathJax 2 is incompatible with MathJax 3.

ktarplee commented 2 years ago

The new mathjax.html.j2 template looks like this

{%- macro mathjax(url="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js") -%}
    <!-- Load mathjax -->
    <script src="{{url}}"> </script>
    <script type="text/javascript" id="MathJax-script" async
        src="{{url}}">
    </script>
    <!-- MathJax configuration -->
    <script id=MathJax-configuration>
    window.MathJax = {
        tex: {
            tags: "ams",
            useLabelIds: true,
            inlineMath: [ ['$','$'], ["\\(","\\)"] ],
            displayMath: [ ['$$','$$'], ["\\[","\\]"] ],
            processEscapes: true,
            processEnvironments: true
        }
    };
    </script>
    <!-- End of mathjax configuration -->
{%- endmacro %}

I tested it with nbconvert 6.4 and it works.

bollwyvl commented 2 years ago

Some context here https://github.com/jupyterlab/jupyterlab/issues/7218

We'd want to do a roll out of an updated default mathjax major version across JupyterLab, Jupyter Notebook and nbconvert at the same time.

There's nothing stopping folks today from using newer versions, e.g. mathjax3-extension so a standalone nbconvert-mathjax3 might be a good place to evaluate this.

lorentzenchr commented 1 month ago

Any update here? Now that https://github.com/jupyterlab/jupyterlab/pull/13877 is merged, i.e. Jupyterlab v4 uses Mathjax v3.