MathJax and KaTeX are display engines for complex mathematic formulas, and Notebooks supports both in combination with Markdown. The simplest option to use MathJax or KaTeX is by selecting one of Notebooks‘ pre-installed document themes which include all the necessary scripts (Scientific+MathJax or Scientific+Katex).

Alternatively you can add the necessary scripts at the bottom of your favorite document style sheet (right after the </style> tag), or you simply add these lines at the top of a Markdown document.


For MathJax, use

<script>
MathJax = {
    tex: {
        inlineMath: [ ['$','$'], ['\\(','\\)'],
        displayMath: [ ['$$','$$'], ['\[','\]'] ]
    }
};
</script>

<script id="MathJax-script" async src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script>

The definitions of inlineMath and displayMath control the way you enter your mathematical expressions. Our default implementations include single parentheses as well, which is very convenient but may also produce unexpected results. If you don’t want the single parentheses, you can use the definition above.


For KaTeX, use

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.12.0/dist/katex.min.css" integrity="sha384-AfEj0r4/OFrOo5t7NnNe46zW/tFgW6x/bCJG8FqQCEo3+Aro6EYUG4+cU+KJWu/X" crossorigin="anonymous">

<script defer src="https://cdn.jsdelivr.net/npm/katex@0.12.0/dist/katex.min.js" integrity="sha384-g7c+Jr9ZivxKLnZTDUhnkOnsh30B4H0rpLUpJ4jAIKs4fnJI+sEnkvrMWph2EDg4" crossorigin="anonymous">

</script>

<script defer src="https://cdn.jsdelivr.net/npm/katex@0.12.0/dist/contrib/auto-render.min.js" integrity="sha384-mll67QQFJfxn0IYznZYonOWZ644AWYC+Pt2cHqMaRhXVrursRwvLnLaebdGIlYNa" crossorigin="anonymous"

  onload="renderMathInElement(document.body);">

</script>

Here is a complete sample of how to create your own document style, based on Notebooks Scientific Theme.:

<style type="text/css">
@nb_include: "Scientific";
</style>

<script>
    MathJax = {
        tex: {
            inlineMath: [ ['$','$'], ['\\(','\\)'],
            displayMath: [ ['$$','$$'], ['\\[','\\]'] ],
            processEscapes: true
        }
    };
</script>

<script id="MathJax-script" async src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script>
Use Mathematic Expressions in Documents (MathJax or KaTeX)