Rendering math symbols with KaTex in Hugo

I am looking for a solution to fix the partial rendering of Latex code inside my .md post file.

I start out writing some KaTeX code using ( … ) for marking when the math notation begins. Yet, it seems like the ‘’ gets rendered as markdown so the math equation inside the above gets rendered as markdown, too.

Any ideas for a fix? Seems like a lot of people are having trouble with this. I found some hacks for MathJax, like this: https://gohugo.io/tutorials/mathjax/ Is there some hack like this for KaTeX? Thanks!

I am not sure as I haven’t use KaTex, but you could try, for instance, to put your KaTeX block within a <div></div>. This will avoid the Markdown processor from triggering in that region, which could solve your problem.

1 Like

Hi @hnarayanan. I tried that along with a bunch of the traditional ways of signaling the markdown processor to ignore some text. Nothing seems to work… What was also mentioned in the article I posted above was to use

after including some modifications to the rendering of katex (well, it’s meant for mathjax in the article). This is because the inline formulas /(…/) would still be problematic even after putting it in between the div tags. In my example, it seems like this problem is prevalent both for display + inline math as ‘/’ slash just gets rendered either way… So I’m clueless.

Perhaps give up on KaTeX and use MathJax? :slightly_smiling:

I use MathJax and the only additional thing that tripped me up over standard LaTeX is the need to use \_ instead of _ when I had many underscores in an expression.