19

I use Mathjax on my static (jekyll-generated) site : Mathjax is loaded but curly brackets don't show up.

$ \{ 2*3 \} $ -> 2*3
$ \left{ 2*3 \right} -> \left{ 2*3 \right} (math style)

I'd like to have (for instance) a simple {2*3}

Cheers

ted
  • 13,596
  • 9
  • 65
  • 107

1 Answers1

29

OK found out :

You have to escape the backslash because there seems to be 2 levels of interpretation : jekyll then mathjax. So you need to escape the backslash from Jekyll so it renders for Mathjax to escape the bracket :

$ \\{ 2*3 \\} $ -> {2*3} 
ted
  • 13,596
  • 9
  • 65
  • 107
  • 1
    You can also try to wrap it into {%raw%} ... {%endraw%} which might be more readable – deveth0 Dec 25 '16 at 09:04
  • 1
    You do not necessarily have to escape anything. By default, Jekyll uses kramdown which has built-in support for LaTeX-like input (though somewhat unusually uses $$ to delimit both inline and block-level math), see https://kramdown.gettalong.org/syntax.html#math-blocks. – Peter Krautzberger Dec 29 '16 at 14:01
  • 4
    Using two backslashes works for MathJax, but then it doesn't work for LaTeX anymore if I want to convert the same source file to PDF. Is there a way to convert the same source file to both HTML with MathJax, and PDF for such simple things? – weibeld Sep 20 '17 at 06:10
  • 1
    I would like a best practice answer to weibeld's last question. – sam Feb 28 '19 at 04:44
  • My own solution: Use Pandoc with header-includes: \def\set#1{{\left\{#1\right\}}} in the Yaml front matter. Then use MathJax with TeX: { Macros: { set: ["{\\left\\{ #1 \\right\\}}", 1] } } in the Hub Config. Then use \set{} everywhere. – sam Mar 07 '19 at 19:54
  • 1
    This also works if using Hugo instead of Jekyll. – Alan Liddell Dec 29 '20 at 17:26
  • 2
    I had to use the `\lbrace` and `\rbrace` to keep it a valid LaTex and a proper github page display. – Weishi Z Mar 13 '23 at 08:26