Comments (6)
I got it to work. Here's my solution.
In template file.
- Add script tag to helmet
<Helmet
htmlAttributes={{ lang: 'en' }}
meta={[{ name: 'description', content: siteDescription }]}
title={`${post.frontmatter.title} | ${siteTitle}`}
>
<script
type="text/javascript"
src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_HTMLorMML"
async
/>
</Helmet>
- Create hacky on script load function. I grabbed this from an issue on the react helmet page.
function waitForGlobal(name, timeout = 300) {
return new Promise((resolve, reject) => {
let waited = 0
function wait(interval) {
setTimeout(() => {
waited += interval
// some logic to check if script is loaded
// usually it something global in window object
if (window[name] !== undefined) {
return resolve()
}
if (waited >= timeout * 1000) {
return reject({ message: 'Timeout' })
}
wait(interval * 2)
}, interval)
}
wait(30)
})
}
- Add to componentDidMount of the template.
componentDidMount() {
waitForGlobal('MathJax').then(() => {
top.MathJax.Hub.Config({
tex2jax: {
inlineMath: [['$', '$'], ['\\(', '\\)']],
displayMath: [['$$', '$$'], ['[', ']']],
processEscapes: true,
processEnvironments: true,
skipTags: ['script', 'noscript', 'style', 'textarea', 'pre'],
TeX: {
equationNumbers: { autoNumber: 'AMS' },
extensions: ['AMSmath.js', 'AMSsymbols.js'],
},
},
})
})
if (top.MathJax != null) {
top.MathJax.Hub.Queue(['Typeset', top.MathJax.Hub])
}
}
- Add to componentDidUpdate of the template
componentDidUpdate() {
if (top.MathJax != null) {
top.MathJax.Hub.Queue(['Typeset', top.MathJax.Hub])
}
}
from gatsby-remark-mathjax.
Thanks. Unfortunately that didn't work for me (I put it into my site layout page).
I wondered, did you consider trying mathjax-node, to do server-side rendering, which could be integrated into the plug-in?
from gatsby-remark-mathjax.
Hi I have had the same problem. Could you give some suggestions about good ways to "include Mathjax in your template"? I guess I could work it out by a long read of mathjax.org, but if you have anything ready to hand it would save time :-). Thanks!
from gatsby-remark-mathjax.
This is the desired result. This plugin is used for keeping mathjax equations as raw after markdown transform.
from gatsby-remark-mathjax.
https://www.mathjax.org/#gettingstarted
add this to html:
<script src='https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-MML-AM_CHTML' async></script>
from gatsby-remark-mathjax.
I can't get it to work either. After adding the gatsby-remark-mathjax
plugin to the options:{plugins:[...
section of my gatsby-transformer-remark
entry in gatsby-config
, and adding the MathJax script tag in my template file:
<Helmet
htmlAttributes={{ lang: 'en' }}
meta={[{ name: 'description', content: siteDescription }]}
title={`${post.frontmatter.title} | ${siteTitle}`}
>
<script
type="text/javascript"
src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS-MML_HTMLorMML"
/>
</Helmet>
I have no luck with $a^2 + b^2 = c^2$
in an md
file.
I have a jekyll site that uses MathJax. I had to insert this in its html files:
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
tex2jax: {
inlineMath: [['$','$'], ['\\(','\\)']],
displayMath: [['$$','$$'], ['\[','\]']],
processEscapes: true,
processEnvironments: true,
skipTags: ['script', 'noscript', 'style', 'textarea', 'pre'],
TeX: { equationNumbers: { autoNumber: "AMS" },
extensions: ["AMSmath.js", "AMSsymbols.js"] }
}
});
</script>
However, I can't figure out how to do that in gatsby. Could this be what I'm missing or is there an easier way?
from gatsby-remark-mathjax.
Related Issues (2)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gatsby-remark-mathjax.