Skip to content

MathJax does not render when using a local copy #1283

Closed

Description

@pat-s

yihui/xaringan#119

Maybe related: mathjax/MathJax#1934

MathJax.js: https://cdn.bootcss.com/mathjax/2.7.1/MathJax.js?config=TeX-MML-AM_CHTML

Reprex:

---
title: "Untitled"
output: 
  html_document:
    toc: true
    mathjax: "<path>/MathJax.js"
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```

## R Markdown

```
$$\bar{X}=\frac{1}{n}\sum_{i=1}^nX_i$$
```

$$\bar{X}=\frac{1}{n}\sum_{i=1}^nX_i$$

When using xaringan it additionally shows the following JS errors:

libs/extensions/MathMenu.js?V=2.7.1 Failed to load resource: the server responded with a status of 404 (Not Found)
libs/extensions/MathZoom.js?V=2.7.1 Failed to load resource: the server responded with a status of 404 (Not Found)

However, solving these has no effect.

Activity

  1. added
    bug
    on Mar 12, 2018
  2. self-assigned this
    on Apr 11, 2018
  3. rich-iannone commented on Apr 12, 2018

    @rich-iannone
    Member

    @pat-s Thanks for this. Is there any reason why you would want to use a local copy of MathJax?

  4. N0rbert commented on Apr 15, 2018

    @N0rbert

    This problem is very actual. bookdown::html_document2 or simple html_document or xaringan::moon_reader may be shown on device without internet (completely offline), so self_contained or something is needed for MathJax.

  5. pat-s commented on Apr 16, 2018

    @pat-s
    Author

    @pat-s Thanks for this. Is there any reason why you would want to use a local copy of MathJax?

    People need it for self-contained offline presentations using xaringan.

    I do not know why its so difficult to link to a local copy of Mathjax whereas linking to other JS libraries is usually not a big deal. Could you share some details here?

  6. jjallaire commented on Apr 16, 2018

    @jjallaire
    Member
  7. yihui commented on Apr 16, 2018

    @yihui
    Collaborator

    @pat-s Note that mathjax='local' is not implemented in xaringan. Feel free to study the source code of rmarkdown and implement it in xaringan.

  8. rich-iannone commented on May 15, 2018

    @rich-iannone
    Member

    @jjallaire I just tried using the local option with self_contained: false. The equations don't appear to render in the preview doc but they do appear in the final HTML file.

    This is the .Rmd:

    ---
    title: "Habits"
    output:
      html_document:
        mathjax: local
        self_contained: false
    ---
    
    We can use inline equations such as $y_i = \alpha + \beta x_i + e_i$
    
    $$3^2+4^2=5^2$$
    

    This is the preview:

    rmd_mathjax_local_preview

    The rendered HTML document gives:

    rmd_mathjax_local_final_html

    So, the preview here is problematic. I feel like this is a separate issue. Should I file it as such?

  9. N0rbert commented on May 15, 2018

    @N0rbert

    @rich-iannone - see my comment on related Xaringan issue. You can try something similar with regular RMarkdown.

  10. jjallaire commented on May 15, 2018

    @jjallaire
    Member

    I would take a look at the JS debugging tools to see if you can get to the bottom of what's going on.

  11. rich-iannone commented on May 16, 2018

    @rich-iannone
    Member

    @jjallaire will do.

  12. 2 remaining items

  13. bonedog32 commented on Aug 4, 2020

    @bonedog32

    I am having a similar problem on my blog (using theme gohugo-theme-ananke). In the near past the math rendered fine, but now earlier posts I have made no longer show correctly rendered equations. Not sure exactly when this happened, but tried a new post yesterday and discovered the issue. What I see is this: 'blogdown::build_dir("./content/post/")' renders the math. However, when I then run 'blogdown::serve_site()' the correctly rendered math now does not render and comes out as $$formula$$ or [formula]. Anyone have an idea why the rendering would suddenly just stop working? Also, now, the uploaded files to github and then netlify are also not rendering. I don't know if this may be related to Hugo or not. Don't have much hair, so not pulling it out.
    EDIT: After some more searching, I have found a fix (for my situation) with this script:

    <script src='https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML'>;</script>;

    I placed it in my 'layout/partials/site-footer.html' file, and that seems to fix the rendering issue.

  14. py9mrg commented on Oct 29, 2020

    @py9mrg

    Why not add support for KaTeX? It's been mentioned already as a feature request for Bookdown and seems like it would solve a lot of the issues of trying to use MathJax in offline and/or self contained documents? I realise it's not as feature complete as MathJax (and implementation might not be trivial) but it seems like a route to solve these sorts of issues.

  15. atusy commented on Oct 31, 2020

    @atusy
    Collaborator

    I opened PR #1940 to solve this.

  16. moved this from Backlog to Todo in R Markdown Team Projectson Jan 12, 2022
  17. Repository owner moved this from Todo to Done in R Markdown Team Projectson Jan 31, 2022
  18. cderv commented on Jan 31, 2022

    @cderv
    Collaborator

    We have now included broader support for HTML math methods as supported by Pandoc (https://pandoc.org/MANUAL.html#math-rendering-in-html).

    This include better support for other engine that does not load a JS library (like webtex) which can help when local is prefered.

    Also #2215 will bring support for using the katex R package which will allow to have server side rendering of maths, which will be best when local is required.

  19. github-actions commented on Aug 2, 2022

    @github-actions

    This old thread has been automatically locked. If you think you have found something related to this, please open a new issue by following the issue guide (https://yihui.org/issue/), and link to this old issue if necessary.

  20. locked as resolved and limited conversation to collaborators on Aug 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugtheme: math support

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions