2 Alternatives to Jetpack’s Latex Support for WordPress

I’ve been trying (mostly unsuccessfully) to upload LaTeX here to my blog. Here’s what I have found so far.

Using MathJax:

We simply load the MathJax library by adding this code to our webpage (typically this should go in the header of your page):

…< script type=”text/javascript” async
src=”https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js?config=TeX-MML-AM_CHTML”>
< /script>

And now everything we put in double-dollar signs \$\$ … \$\$ will become beautiful LaTeX. I even defined a \newcommand for those bold-faced vectors:

\[
\newcommand{\vect}[1]{\boldsymbol{#1}}
\]

$$
\begin{align*}
U \sum V &= [\vect{u_1} \quad \vect{u_2} \quad … \quad \vect{u_m}] \quad
\begin{bmatrix}
\sigma_1 \\
\quad & \sigma_2 \\
\quad & \quad & \ddots \\
\quad & \quad & \quad & \sigma_{r} \\
\quad & \quad & \quad & \quad & 0_{r+1} \\
\quad& \quad & \quad& \quad & \quad & \ddots \\
\quad& \quad & \quad& \quad & \quad & \quad & 0_n \\
\end{bmatrix} \quad
\begin{bmatrix}
\vect{p_1^T} \\
\cdot \\
\cdot \\
\cdot \\
\cdot \\
\cdot \\
\cdot \\
\vect{p_n^T}
\end{bmatrix} \\
& = \sum\limits_{k} \sigma_k \, u_{ik} \, v_{kj}^T \\
& = \sum\limits_{k} \sigma_k \, u_{ik} \, v_{jk}
\end{align*}
$$

Actually, MathJax is pretty reasonable and renders on a separate server, cdnjs (thanks to CloudFlare).

Using ‘knitr’ to generate all the javascript:

This is particularly useful since all my report writing is done using Yihui’s knitr package through R-Studio:








  1. The \(DetM = ab4\) since the matrix is in (upper) triangular form and the determinate is the product of all \(M_{ij}\) where \(i=j\).

\[
\begin{bmatrix}
1 & 0 & 4 \\
0 & 1 & 7 \\
0 & 0 & 1 \\
\end{bmatrix}
\bullet
\begin{bmatrix}
0 & -1 & 0 \\
1 & 0 & 0 \\
0 & 0 & 1 \\
\end{bmatrix}
\bullet
\begin{bmatrix}
1 & 0 & -4 \\
0 & 1 & -7 \\
0 & 0 & 1 \\
\end{bmatrix}
\]



However, the biggest issue here is the size since ‘knitr’ seems to script the necessary MathJax library locally here in the text of the page. The better option surely is MathJax, but in case that server becomes unavailable, ‘knitr’ would be a good backup.

Posted in Blogosphere, Uncategorized and tagged , , , .