Easily Add LaTex Math to a Ghost Blog
Updated KaTex from v0.10.1 to v0.16.0 (July 2022)
This is a guide to get LaTex math to work on a Ghost Blog. I chose a fast JavaScript Library developed by Khan Academy called KaTex. To see it in action, check my previous blog post on P-NP. Here are the steps to get it working:
-
Login to the Ghost Administration Panel, and click the "Code Injection" tab on the sidebar.
-
Paste in the following code block into the "Blog Header" section and Save:
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.16.0/dist/katex.css" crossorigin="anonymous"> <script defer src="https://cdn.jsdelivr.net/npm/katex@0.16.0/dist/katex.js" crossorigin="anonymous"></script> <script defer src="https://cdn.jsdelivr.net/npm/katex@0.16.0/dist/contrib/auto-render.min.js" crossorigin="anonymous" onload="renderMathInElement(document.body);"></script>
-
Create your LaTex equations in the Ghost editor:
For the New Koenig Editor
For inline equations, simply surround the LaTex math with a backslash and parentheses:
\( LaTex_HERE \)
. Example: \(\sum_{i=1}^{n}{n} = \frac{n(n-1)}{2}\). To get a large and centred expression, surround the LaTex math with a backslash and square brackets:\[ LaTex_HERE \]
. Example: \[\mathcal L_{\mathcal T}(\vec{\lambda}) = \sum_{(\mathbf{x},\mathbf{s})\in \mathcal T} \log P(\mathbf{s}\mid\mathbf{x}) - \sum_{i=1}^m \frac{\lambda_i^2}{2\sigma^2} \]For the Old Markdown Editor
In Markdown, you will have to escape some of the control characters, as explained here. Usually, all that needs to be escaped are the surrounding backslashes. To get the same expressions as above, surround the LaTex with double backslashes:
\\( LaTex_HERE \\)
and\\[ LaTex_HERE \\]
.