How can I embed math equations in my markdown files

Hi, I am very new to Hugo so apologies if I have missed something, but is there a straightforward way to embed formulas in markdown and rendering them on the pages? I would use MathJax for it I suppose, unless there is a reason not to. I did see a few guides showing how to do this on google but none worked so far. Is there any official information on how I could do this? If not, any pointers?

Thanks

Example:

git clone --single-branch -b hugo-forum-topic-41107 https://github.com/jmooring/hugo-testing hugo-forum-topic-41107
cd hugo-forum-topic-41107
hugo server

Files of interest:

  • layouts/_default/baseof.html
  • layouts/shortcodes/math.html
  • layouts/_default/_markup/render-codeblock-math.html
  • layouts/partials/mathjax.html
1 Like

I also have this interest. I came across the theme below, which uses mathjax. Search the net for “hugo mathjax” and there are a number of stackoverflow hits. Here’s one that points to a hugo MathJax tutorial.

The reveal-hugo theme makes reference to maths-and-equations-via-mathjax.

New in v0.122.0

1 Like

Hi, thank you for the link - I cloned the repo and took a look at the files you highlighted and they helped me to get it working, so thanks for that.

This update now looks like the way to go!

Yes, I would use new features in v0.122.0 instead of a shortcode or a code block render hook.

The new approach allows you to easily import mathematical markdown from other sources, and it’s compatible with GitHub, GitLab, VS Code, etc.

2 Likes

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.