2018-10-22 21:06:42 +02:00
|
|
|
/**
|
|
|
|
|
* A plugin which enables rendering of math equations inside
|
|
|
|
|
* of reveal.js slides. Essentially a thin wrapper for MathJax.
|
|
|
|
|
*
|
|
|
|
|
* @author Hakim El Hattab
|
|
|
|
|
*/
|
2024-11-05 11:41:56 +02:00
|
|
|
var RevealMath = window.RevealMath || (function () {
|
2018-10-22 21:06:42 +02:00
|
|
|
|
2024-11-05 11:41:56 +02:00
|
|
|
var options = Reveal.getConfig().math || {};
|
|
|
|
|
options.mathjax = options.mathjax || 'https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js';
|
|
|
|
|
options.config = options.config || 'TeX-AMS_HTML-full';
|
2018-10-22 21:06:42 +02:00
|
|
|
|
2024-11-05 11:41:56 +02:00
|
|
|
loadScript(options.mathjax + '?config=' + options.config, function () {
|
2018-10-22 21:06:42 +02:00
|
|
|
|
2024-11-05 11:41:56 +02:00
|
|
|
MathJax.Hub.Config({
|
|
|
|
|
messageStyle: 'none',
|
|
|
|
|
tex2jax: {
|
|
|
|
|
inlineMath: [['$', '$'], ['\\(', '\\)']],
|
|
|
|
|
skipTags: ['script', 'noscript', 'style', 'textarea', 'pre']
|
|
|
|
|
},
|
|
|
|
|
skipStartupTypeset: true
|
|
|
|
|
});
|
2018-10-22 21:06:42 +02:00
|
|
|
|
2024-11-05 11:41:56 +02:00
|
|
|
// Typeset followed by an immediate reveal.js layout since
|
|
|
|
|
// the typesetting process could affect slide height
|
|
|
|
|
MathJax.Hub.Queue(['Typeset', MathJax.Hub]);
|
|
|
|
|
MathJax.Hub.Queue(Reveal.layout);
|
2018-10-22 21:06:42 +02:00
|
|
|
|
2024-11-05 11:41:56 +02:00
|
|
|
// Reprocess equations in slides when they turn visible
|
|
|
|
|
Reveal.addEventListener('slidechanged', function (event) {
|
2018-10-22 21:06:42 +02:00
|
|
|
|
2024-11-05 11:41:56 +02:00
|
|
|
MathJax.Hub.Queue(['Typeset', MathJax.Hub, event.currentSlide]);
|
2018-10-22 21:06:42 +02:00
|
|
|
|
2024-11-05 11:41:56 +02:00
|
|
|
});
|
2018-10-22 21:06:42 +02:00
|
|
|
|
2024-11-05 11:41:56 +02:00
|
|
|
});
|
2018-10-22 21:06:42 +02:00
|
|
|
|
2024-11-05 11:41:56 +02:00
|
|
|
function loadScript(url, callback) {
|
2018-10-22 21:06:42 +02:00
|
|
|
|
2024-11-05 11:41:56 +02:00
|
|
|
var head = document.querySelector('head');
|
|
|
|
|
var script = document.createElement('script');
|
|
|
|
|
script.type = 'text/javascript';
|
|
|
|
|
script.src = url;
|
2018-10-22 21:06:42 +02:00
|
|
|
|
2024-11-05 11:41:56 +02:00
|
|
|
// Wrapper for callback to make sure it only fires once
|
|
|
|
|
var finish = function () {
|
|
|
|
|
if (typeof callback === 'function') {
|
|
|
|
|
callback.call();
|
|
|
|
|
callback = null;
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-10-22 21:06:42 +02:00
|
|
|
|
2024-11-05 11:41:56 +02:00
|
|
|
script.onload = finish;
|
2018-10-22 21:06:42 +02:00
|
|
|
|
2024-11-05 11:41:56 +02:00
|
|
|
// IE
|
|
|
|
|
script.onreadystatechange = function () {
|
|
|
|
|
if (this.readyState === 'loaded') {
|
|
|
|
|
finish();
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-10-22 21:06:42 +02:00
|
|
|
|
2024-11-05 11:41:56 +02:00
|
|
|
// Normal browsers
|
|
|
|
|
head.appendChild(script);
|
2018-10-22 21:06:42 +02:00
|
|
|
|
2024-11-05 11:41:56 +02:00
|
|
|
}
|
2018-10-22 21:06:42 +02:00
|
|
|
|
|
|
|
|
})();
|