Enable math expressions (LaTeX) on blogdown/Hugo blog

I am trying to enable math expressions (LaTeX expressions) on a blogdown/Hugo blog.

I am using the xmin theme.

I followed Xie's directions in the blogdown book (see the Support Math Expressions Through MathJax section) here. Specifically, I added the following to the foot_custom.html file for the theme:

<script src="//yihui.name/js/math-code.js"></script>
<script async
src="//cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js">
</script>

But, some math expressions still didn't render--see this post here.

The source for my blog is here (and the foot_custom.html is here).

Not sure it's helpful, but did you try using LaTeX directly? I'm using blogdown as well and I didn't need to do anything for LaTeX to render correctly.

Source - https://github.com/romatik/netlify-blog/blob/master/content/post/2018-10-27-hitchiker-s-paradox-quantified-self-edition.Rmd
Rendered version - https://www.mishabalyasin.com/2018/10/27/hitchikers-paradox/

1 Like

Have you tried adding ?config=TeX-MML-AM_CHTML to the end of your path? I don't know what that does :grin:, but I definitely used it in foot.html for one of my blogdown websites. It is in that section of the blogdown book you mentioned, so that may be what I was following at the time.

What I used (for a different theme) looks like

<script src="//yihui.name/js/math-code.js"></script>
<script async
src="//cdn.bootcss.com/mathjax/2.7.1/MathJax.js?config=TeX-MML-AM_CHTML">
</script>
6 Likes

That'll probably be important! The config parameter tells MathJax which kinds of input and output it can handle—input being ways to entering the maths into the HTML, like TeX and MathML, and output being ways it's rendered on the page, like SVG. I'm not sure what it defaults to in the absence of a configuration parameter, but there's a big page in the MathJax documentation on the common types:

http://docs.mathjax.org/en/latest/config-files.html

2 Likes

FWIW this was documented in the blogdown book: https://bookdown.org/yihui/blogdown/templates.html (search for MathJax on this page) And this page contains everything you may wish to know about the hugo-xmin theme (not many themes can be fully documented on a line-by-line basis).

4 Likes

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