Skip to content
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

Equations not rendering on deployment #62

Open
marissabarlaz opened this issue Feb 14, 2019 · 1 comment
Open

Equations not rendering on deployment #62

marissabarlaz opened this issue Feb 14, 2019 · 1 comment

Comments

@marissabarlaz
Copy link

I'm trying to include equations in math mode in my portfolio pages, and they are not rendering properly. My portfolio pages are .Rmd files, so I was under the impression that the equations would be processed and compiled with minimal issue. Is there a setting I need to change in one of the layout files? Thank you!

@daczarne
Copy link

daczarne commented Dec 23, 2020

@marissabarlaz just a comment on the use of RBlogdown and Hugo themes. The reason why they work is that knitr produces a .md file. On normal RMarkdown, after knitr knits, R calls Pandoc who then transforms your .md file into your selected output (HTML, pdf, etc). In the case of Blogdown, Hugo gets called instead and generates the file as defined by the thems configuration. I guess what I'm trying to get at is that just because something works with Pandoc doesn't mean it's going to work with other HTML generators.

In this case, you can solve your issue by going into the hugo-creative-portfolio-theme\layouts\partials folder. Create a new file called footer_mathjax.html and paste the following into it:

{{ if and (not .Params.disable_mathjax) (or (in (string .Content) "\\") (in (string .Content) "$")) }}
<script src="{{ "/js/math-code.js" | relURL }}"></script>
<script async
    src="{{ .Site.Params.MathJaxCDN | default "//cdnjs.cloudflare.com/ajax/libs" }}/mathjax/{{ .Site.Params.MathJaxVersion | default "2.7.5" }}/MathJax.js?config=TeX-MML-AM_CHTML"></script>
{{ end }}

If you want to include TeX style declarations (like one would do in a TeX file) you can do so in the scripts.html and add new scripts. For example, I added

<!-- Math Jax-->
<script>
    MathJax = {
        tex: {
            macros: {
                E: ['\\mathbf{E}'],
                V: ['\\mathbf{Var}'],
                C: ['\\mathbf{Cov}'],
                AV: ['\\mathbf{AVar}']
            }
        }
    };
</script>
<script id="MathJax-script" async src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-chtml.js"></script>

This way if I use \E in an equation, Hugo will render it as an Expected Value operator (I use a bold E for it). Or if I use \V Hugo will render Var.

The scripts.html file is where you also need to add the paths for the JavaScript based libraries used in R (if you are using any). You can check here the ones I've added.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants