Goldmark rendering problem of '%' sign in LaTeX code snippet

I’ve already setup Katex parser in layouts JS header. LaTex math expression in inline mode ($) and display mode ($$) both work great until I type percentage sign (%).

In LaTeX, the % sign starts a comment, so it needs to be escaped with a backslash to display the symbol literally. Like this

$10\% = 0.1$

However, Goldmark and Github flavoured markdown renderer also use backslash to escape punctuation characters like !, %, &, etc. Thus, it needs double backslash in markdown to pass one \ to LaTex renderer Katex to display %. Like this,

$10\\% = 0.1$

Double backslash doesn’t work in LaTex system, neither many other markdown renderer, like pandoc.

If I change defaultMarkdownHandler of hugo configuration to pandoc, it does parse the raw LaTex snippet well and fix my problem. But pandoc leads to another problem, the code block syntax highlighting doesn’t work in Hugo.

My questions:

  1. Is there anyway to configure Goldmark to disable escaping? From my perspective, markdown is a plain text document, I never need to escape characters in a plain text file. And I don’t want to maintain two versions of code and document.
  2. If I have to switch to pandoc as markdown renderer, how to enable code block synatx highlighting in Hugo?

Thanks in advance.

I am unable to reproduce the problem. Try it:

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

Did you follow these directions?
https://gohugo.io/content-management/mathematics/

Or did you do something else?

1 Like

Thank you so much. I think I missed the “enable = true” in passthrough section. I’m so sorry. Now everything works fine.

1 Like

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