Curiosities

Adding MathJax to WordPress via HTML

Ever ask yourself how to add beautiful Latex to WordPress pages? I was frustrated by the quality of Latex in WordPress using whatever internal rendering engine is set on by default. The default engine renders equations as PNG image files, which both fit poorly for in-line expressions and, more importantly, are exceptionally ugly and not scalable. Fortunately, there is a simple way to get the excellent MathJax package to render your equations as beautiful vector graphics in WordPress. You need to add an HTML block to your code (I found it works anywhere on the page, but now I just put it at the top) and paste the following code:

<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>

That snippet comes from MathJax | Beautiful math in all browsers.

Here is an example of a beautifully-rendered equation:

$$s_j = \int \frac{\exp(\delta_j(\beta))}{1+\sum_{k \in K} \exp(\delta_k(\beta))} dF(\beta), $$

compared to this ugly monstrosity using the default rendering engine:

s_j  = \int \frac{\exp(\delta_j(\beta))}{1+\sum_{k \in K} \exp(\delta_k(\beta))} dF(\beta).

Leave a Reply

Your email address will not be published. Required fields are marked *