# How to use Latex expressions in blogdown? #36

Closed
opened this Issue Jan 16, 2017 · 8 comments

Projects
None yet
6 participants

### gresch commented Jan 16, 2017

 If I use $$SE = \sqrt{\frac{s_{1}^{2}}{n_{1}}+\frac{s_{2}^{2}}{n_{2}}}$$ in the document the resulting HTML page shows this result [SE = \sqrt{\frac{s_{1}^{2}}{n_{1}}+\frac{s_{2}^{2}}{n_{2}}}] Can anybody help out?

### Lauler commented Jan 16, 2017 • edited

 I ran into this. You have to load mathjax javascript library to display mathematical notation on your pages. The easiest way to do this is to insert the following snippet:   into one of the partials files which you're sure will be loaded on each of your posts. You can find these in layout/partials. In my case I put the code above in the sidebar.html file because the sidebar is guaranteed to load on all my posts. For you it depends on which theme you have installed. Usually sidebar.html/header.html/footer.html are good bets. This is something which ought to be covered blogdown's documentation.

Member

### yihui commented Jan 19, 2017

 We will document this in the near future. The approach @Lauler mentioned has a potential problem, but I don't have the time to explain it in detail. You can see what I did in the default template of blogdown: https://github.com/yihui/hugo-lithium-theme/blob/7d436d803df90c873cdaecf24aeeff827696d77c/layouts/partials/footer.html#L21-L30

### riversdark commented Apr 29, 2017 • edited

 @yihui Hi is there a list of tested themes known to render equations properly? The default them hugo-lithium-blogdown looks a bit too simplistic.. The hugo-future-imperfect looks nice but does not render the equations. I tried simply copying the footer file you mentioned to the layouts folder but it messes some other things up. I know absolutely nothing about html.

### timtrice added a commit to timtrice/web that referenced this issue May 15, 2017

 Add MathJax support to theme footer 
Previous setup was not rendering MathJax correctly. Per blogdown issue
36, added JS code to theme footer.

rstudio/blogdown#36 (comment)
 30e81b9 

### pzhaonet commented May 18, 2017

 I don't understand why people have been talking about the Load mathjax codes. In my case, I simply set the option 'math = true' in config.toml and all the equations went perfectly the right way. My website is built by blogdown, hugo-academic theme. But my story went another way as follows. At the beginning, the LaTeX equations were not displayed correctly on my website. I set the option 'math = true' in config.toml, and run 'blogdown::serve_site()'. Equations were still not correctly displayed in RStudio Viewer. After trying many times, I clicked accidentally the Show in new window button at the topleft corner of RStudio Viewer, and surprisingly found that the equations were displayed correctly in Firefox! For both the newest version 1.0.143 and the preview version 1.1.233 of RStudio. So it is a problem of RStudio Viewer? Curiously. My sessioninfo: R version 3.3.3 (2017-03-06) Platform: x86_64-w64-mingw32/x64 (64-bit) Running under: Windows 7 x64 (build 7601) Service Pack 1 
Member

### yihui commented May 18, 2017

 @pzhaonet You can use math = true only because your theme supports it (thanks to the author of the hugo-academic theme). Hugo does not support MathJax out of the box. There are known issues with RStudio Viewer on Windows. In particular, https resources are unlikely to work, which means (1) you have to use protocol-relative URLs for https resources, i.e. // instead of the hardcoded https://; (2) we must have access to the resources via http://, which depends on the server settings. If you don't understand what these mean, your best choice is to pop out the web page from RStudio Viewer into your real web browser.

### pzhaonet commented May 18, 2017 • edited

 Thanks for explanation. Lucky and proud to use hugo-academic theme!
Member

### yihui commented Jun 23, 2017

 Finally I have documented how to make MathJax work properly: https://bookdown.org/yihui/blogdown/templates.html This section is quite long but you will understand the nuts and bolts of Hugo much better.

### sillasgonzaga commented Apr 15, 2018

 Does anyone know how to do this in blackburn theme?