I was writing equations in my blog post, and thought about having them properly rendered.
It looks like people often use MathJax for this. Looking at mathjax, there’s a format it supports called AsciiMath, which like markdown, looks reasonable both after rendering and as plain text before rendering.
Trying it out:
` a+b `
This was basically typed into my hugo markdown file as:
\` a+b \`
It has a backslash and then backtick at the start and end.
A more complex equation:
a^b + a/(b c + sqrt d + root(3)h) +- c
` a^b + a/(b c + sqrt d + root(3)h) +- c `
Enabling MathJax in Hugo
This page showed me a script link that worked: http://docs.mathjax.org/en/v2.7-latest/start.html
This page suggested where the script link could go: https://divadnojnarg.github.io/blog/mathjax/
I put it in mathjax_support.html and linked that from footer.html
I made a new “layouts/partials” directory for the blog, which is where I put the new file mathjax_support.html and the edited file footer.html
footer.html was copied from layouts/partials in the style directory, before adding the reference to mathjax_support.html as explained at the second link.
Delimiters
` a+b ` was typed as \` a+b \`
It has a backslash and then backtick at the start and end. Back ticks are the delimiters for AsciiMath and MathJax. But I had to use backslash before that, so Hugo’s markdown doesn’t interpret the backticks first. And to show how I typed it, I added an extra 2 backslashes, at each end, to escape the backslash and the back tick:
\\\` a+b \\\`
(and to type that in I needed even more backslashes)
AsciiMath is less readable than I expected now I see the delimiters - while the main part of it is good, the back tick delimiters might be fine, but the backslash and back tick together look bad. Maybe I want to change to a different delimiter that Hugo can pass through without a backslash.