You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
MathJax does not render when using a local copy #1283
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)
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.
@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?
Note that rmarkdown supports local versions of mathjax via mathjax =
"local". Note also the RStudio automatically uses a local version when
previewing MathJax (otherwise you couldn't do R Markdown authoring with
MathJax offline).
@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:
The rendered HTML document gives:
So, the preview here is problematic. I feel like this is a separate issue. Should I file it as such?
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:
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.
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.
Activity
rich-iannone commentedon Apr 12, 2018
@pat-s Thanks for this. Is there any reason why you would want to use a local copy of MathJax?
N0rbert commentedon Apr 15, 2018
This problem is very actual.
bookdown::html_document2or simplehtml_documentorxaringan::moon_readermay be shown on device without internet (completely offline), so self_contained or something is needed for MathJax.pat-s commentedon Apr 16, 2018
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?
jjallaire commentedon Apr 16, 2018
yihui commentedon Apr 16, 2018
@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.rich-iannone commentedon May 15, 2018
@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:
This is the preview:
The rendered HTML document gives:
So, the preview here is problematic. I feel like this is a separate issue. Should I file it as such?
N0rbert commentedon May 15, 2018
@rich-iannone - see my comment on related Xaringan issue. You can try something similar with regular RMarkdown.
jjallaire commentedon May 15, 2018
I would take a look at the JS debugging tools to see if you can get to the bottom of what's going on.
rich-iannone commentedon May 16, 2018
@jjallaire will do.
2 remaining items
bonedog32 commentedon Aug 4, 2020
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.
<script src='https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML'>;</script>;EDIT: After some more searching, I have found a fix (for my situation) with this script:
I placed it in my 'layout/partials/site-footer.html' file, and that seems to fix the rendering issue.
py9mrg commentedon Oct 29, 2020
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.
atusy commentedon Oct 31, 2020
I opened PR #1940 to solve this.
cderv commentedon Jan 31, 2022
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.
github-actions commentedon Aug 2, 2022
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.