I have many markdown files with lots of mathjax formulas. When rendering those files, the underscore character ‘_’ in math formulas are treated as italic mark. I have noticed the official document provided a solution, but it requires modify the markdown files, which will be a hard work since there are lots of formulas.

Is there any way to ignore underscore when rendering markdown?

I think I’ve found a perfect solution to insert math equations in a markdown file. Just using pandoc to convert all math equations to png files. It works fine.

Thanks for bringing this up @lianera . “Tutorials” isn’t always the most obvious place to look for this kind of information.

NB, the “Tutorials” section no longer exists in the new concept site.

Can’t the Markdown parser used by Hugo be made smarter about ignoring underscores inside math formulas? Or is it that it has no awareness of math formulas at all?

Yep, Blackfriday doesn’t understand math formulas.

This has remained unmerged for years: Add Math support (MathJaX) to blackfriday.v2 by Vonng · Pull Request #412 · russross/blackfriday · GitHub.

My hope is that when Hugo upgrades to a more actively maintained Markdown parser ( Make Goldmark the new default markdown renderer · Issue #5963 · gohugoio/hugo · GitHub ), such issues could probably resolved in a more timely manner.

Thanks for the reply! That’s unfortunate, and hope the situation improves soon. Meanwhile I discovered that in addition to underscores, also expressions like `\{`

and `\\`

need to be escaped inside math expressions, which makes it all quite inconvenient. Thanks for the glimmer of hope

You have just started; there’s a lot more!

(I am the maintainer of an Org mode → Markdown Emacs package. It produces Markdown which is compatible with Blackfriday, without messing up the LaTeX equations; above is how I need to handle it there.)

I would like to know if there’s now a complete solution for MathJax. The tutorial link above is dead and I couldn’t find such tutorial anywhere, it seems to be outdated thus removed?

@kaushalmodi I have read the README of your `ox-hugo`

and I’m sorry to say that I still have no idea what the package does and how to use it with Hugo. If `ox-hugo`

can fix the issue with the math formulas then I would love to give it a try.

`ox-hugo`

is a package for the Emacs text editor. If you do not use Emacs, they it won’t be of much help.

*Read further if you are still interested.*

`ox-hugo`

basically takes the user’s blog content in Org mode, which I believe is far superior to Markdown, and transforms that to Markdown that Hugo (Goldmark/Blackfriday) can understand. In the process of that conversion, it also puts in workarounds for the bugs in Goldmark/Blackfriday (like MathJAX support). In the above example I posted, ox-hugo auto-escapes the characters that need to be. That way, the user does not need to write overly-escaped MathJAX in their source Org file.

Asking again in 2022. Is there a way to escape underscore characters in equations so they aren’t processed as markdown? I’m using katex with the default goldmark renderer.