Post

mathjax - a math equations renderer

How to render math equations in a webpage.

mathjax - a math equations renderer

mathjax renders math equations in a better format. It can be used with markdown, and static site generators.

Setup

  • Visit mathjax website, https://www.mathjax.org/. There you can see various methods of integration.
  • The most simple one is Web Integration.

For v3 you have to add this to you html page:

<script src="https://polyfill.io/v3/polyfill.min.js?features=es6"></script> <script id="MathJax-script" async src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script>

For v2,

<script type="text/javascript" async src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.7/latest.js?config=TeX-MML-AM_CHTML"> </script>

Usage

First you have to write some math, mostly it is same as used in latex. For e.g. ax^2 + bx + c. Now you have to use some delimiters to enclose this text so that it can be rendered by mathjax. Here is what it looks after rendering,

  • Inline $ax^2 + bx + c$
  • Block
\[ax^2 + bx + c\]
  • The default math delimiters are $$...$$ and \[...\] for displayed mathematics, and \(...\) for in-line mathematics.
  • Also note that, $...$ in-line delimiters are not used by default (because dollar signs appear too often in non-mathematical settings like in case of money).
  • Also note that if you are using a static site generator, you parser might remove \ from \( and inline math won’t work, you can either than change config and use $ or use \\(

Configuration

This is a basic way to configure mathjax.

<script type="text/x-mathjax-config"> MathJax.Hub.Config({tex2jax: {inlineMath: [['$','$'], ['\\(','\\)']]}}); </script> <script type="text/javascript" async src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.7/latest.js?config=TeX-MML-AM_CHTML"> </script>

Another way you can do the same things is,

<script type="text/javascript" async src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.3/MathJax.js?config=TeX-MML-AM_CHTML"> MathJax.Hub.Config({ tex2jax: { inlineMath: [["$", "$"], ["\\(", "\\)"]], processEscapes: true } }); </script>

Also you can always refer to documentation for more details, https://docs.mathjax.org/en/latest/.

This post is licensed under CC BY 4.0 by the author.