Fixing KaTeX Rendering in Hugo PaperMod
In my hugo papermod powered website where math is rendered by Katex, math blocks were silently failing to render mid-page. Everything after a certain point appeared as raw LaTeX. Here’s the fix. NOTE: The fix is generated by Claude. It works. But I’m not sure if the mechanism is 100% correct. But it works. Root Causes 1. Goldmark mangles math before KaTeX sees it Hugo uses Goldmark as its Markdown renderer. Goldmark processes the .md file first — and it escapes or corrupts characters like \, _, {, } inside math delimiters. By the time KaTeX receives the string, the LaTeX is broken. ...