New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use Latex expressions in blogdown? #36

Closed
gresch opened this Issue Jan 16, 2017 · 8 comments

Comments

Projects
None yet
6 participants
@gresch

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

This comment has been minimized.

Lauler commented Jan 16, 2017

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:

<!-- Loading mathjax macro -->
<!-- Load mathjax -->
    <script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"></script>
    <!-- MathJax configuration -->
    <script type="text/x-mathjax-config">
    MathJax.Hub.Config({
        tex2jax: {
            inlineMath: [ ['$','$'], ["\\(","\\)"] ],
            displayMath: [ ['$$','$$'], ["\\[","\\]"] ],
            processEscapes: true,
            processEnvironments: true
        },
        // Center justify equations in code and markdown cells. Elsewhere
        // we use CSS to left justify single line equations in code cells.
        displayAlign: 'center',
        "HTML-CSS": {
            styles: {'.MathJax_Display': {"margin": 0}},
            linebreaks: { automatic: true }
        }
    });
    </script>
    <!-- End of mathjax configuration -->

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.

@gresch gresch closed this Jan 17, 2017

@yihui yihui reopened this Jan 19, 2017

@yihui

This comment has been minimized.

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

This comment has been minimized.

riversdark commented Apr 29, 2017

@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)
@pzhaonet

This comment has been minimized.

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.

  1. At the beginning, the LaTeX equations were not displayed correctly on my website.

  2. I set the option 'math = true' in config.toml, and run 'blogdown::serve_site()'. Equations were still not correctly displayed in RStudio Viewer.

  3. 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
@yihui

This comment has been minimized.

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

This comment has been minimized.

pzhaonet commented May 18, 2017

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

@yihui

This comment has been minimized.

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.

@yihui yihui closed this Jun 23, 2017

@sillasgonzaga

This comment has been minimized.

sillasgonzaga commented Apr 15, 2018

Does anyone know how to do this in blackburn theme?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment