Jekyll eats backslashes in `\{` and `\}`

Hi all, I’ve been getting Github Pages set up to build and generate html for my class notes, which are written in a combination of Markdown and inline LaTeX (via the $$ style).

I’ve run into a really weird issue where the Jekyll build script seems to remove backslashes in front of the { and } characters. Since LaTeX uses {} extensively, representing sets (and literal braces) is done like so: \{ x \in \mathbb{Z} \}. As Jekyll is removing those preceding backslashes, KaTeX (the LaTeX rendering engine I’m using) doesn’t render them properly.

You can see an example of this behavior here: Automata Theory

KaTeX will render everything (sans braces) upon loading the page in a browser, but if you curl it, you’ll notice that the backslashes before the braces are gone (compared to the raw markdown). Interestingly - the same thing appears to happen on Github’s native Markdown renderer.

Markdown has backslash escape codes, which include curly brace escapes (\{, \}), so if you want a literal backslash, you often have to escape it. I.e. write \\{ to get \{. See: Daring Fireball: Markdown Syntax Documentation

Backslash escapes aren’t applied within code spans/blocks, as well as HTML block elements (div, etc). I gather there may be ways to configure MathJax/KaTeX to process those blocks so Markdown escaping can be avoided. May not be worth implementing if you only have a few problematic LaTeX expressions.

1 Like