Use goldmark-mathjax extension

Thanks for carrying this one forward @jph00. Your hugo fork looks like a step forward in that it is good to have a proof-of-concept. In practice I imagine it is going to be tough to get non-standard hugo builds on all the machines used for our group blog; How have you found that process?

We’re only just starting on this, so I don’t have any experience to report. Our plan, if Hugo doesn’t add the extension directly, is to auto-download the patched version automatically as part of the nbdev make process. We’re currently using GitHub Actions to automatically build (and upx-compress, and release) the patched version every day.

Will that approach have the issues with _? Or any other issues of MarkDown parsing of LaTeX code?


It does. It seems setting a short code with {{ .Inner }} is basically a way to escape MarkDown parsing. right?
Is the a way to use short code to define the MathJaX span as uses by the GoldMark MathJaX extension?

I don’t like the .Inner construction and use it on this way

tags        = [ "MathJax"]
title       = "MathJax"


## Maxwell's formulas

|Gaußsches Gesetz|${\vec {\nabla }}\cdot {\vec {E}}={\frac {\rho }{\varepsilon _{0}}}$|
|Gaußsches Gesetz für Magnetfelder|${\vec {\nabla }}\cdot {\vec {B}}=0$|
|Faraday's Induktionsgesetz|${\vec {\nabla }}\times {\vec {E}}=-{\frac {\partial {\vec {B}}}{\partial t}}$|
|Ampère's Durchflutungsgesetz|${\vec {\nabla }}\times {\vec {B}}=\mu _{0}{\vec {j}}+\mu 

_{0}\varepsilon _{0}{\frac {\partial {\vec {E}}}{\partial t}}$|

with  $\mu _{0}\varepsilon _{0}={\frac {1}{c^{2}}}$ .

works for me.

The shortcode activates MathJax, thats all.
complete sample at


This thread is mentioning this case which is using the ampersand sign &. Your suggestion cannot process it well, I think.

with my solution I can get the result

$ \begin{vmatrix}a & b \\\\ c & d \end{vmatrix}$

The inline is ok but the multiline failed.

vim content/post/2020-04-02_mathjax/
$ \begin{vmatrix}a & b \\\\ c & d \end{vmatrix}$

\begin{vmatrix}a & b\\
c & d

Screen Shot 2020-12-12 at 19.51.16

I found a new workaround. It works well for me as the same as when I use the math shortcode which includes {{ .Inner }}.

But, this will break other elements, is not practical. We need the goldmark-mathjax extension to solve this problem.


{{ $content := $.Content | replaceRE "\\<br>" "\\" }}
{{ $content | safeHTML }}


{{< math >}}
\begin{vmatrix}a & b\\
c & d
{{< /math >}}

\begin{vmatrix}a & b\\
c & d

Screen Shot 2020-12-12 at 20.32.04

1 Like

Do NOT end a line with \
one space after should do the trick

That is a syntax of TeX, not Markdown, so we need the goldmark-mathjax extension.

1 Like

nope, this is embedded in markdown

@ju52 Did you read the first of this thread?

OK, I will describe the problem here again. The problem of this thread is a conflict between the Markdown spec and the MathJax spec.

When we write the next TeX document in a Markdown file.

\begin{vmatrix}a & b\\
c & d

Hugo processes the input with the goldmark (CommonMark) and we will get the following HTML output.

\begin{vmatrix}a &amp; b \<br>
c &amp; d

Since MathJax cannot process the <br> tag, the math rendering is broken.


Hugo knows nothing about LaTex. You have to write all markdown and templates to produce correct LaTex output.

If you have a solution, fine. Let’s stop here.

We cannot stop this, unfortunately…

Your example works with the {{ .inner }} template.
Do you have an example which breaks it?

I meant this (using replaceRE): my comment Use goldmark-mathjax extension

The math shortcode is ok. I have compared two output between the math shortcode (using .Inner) and my workaround (using replaceRE ). My workaround broke other elements on other pages with my theme.

What are the shortcomings of the {{ .inner }} approach vs. the GoldMark MathJaX Extension (GME? :-)) in your opinion?

The shortcode approach works but all theme need to create a shortcode for mathjax/katex. So goldmark-mathjax extension is the best solution if Hugo can get it, I think.


If you have many existing markdown files written with other editor you need to change every equation in every markdown file if you use the short code approach. If hugo can automtically handle that it would be wonderful.

1 Like

I totally agree, I also wants out of the box support for MathJaX.
Any progress on that front?