2 * A plugin which enables rendering of math equations inside
3 * of reveal.js slides. Essentially a thin wrapper for MathJax.
5 * @author Hakim El Hattab
7 var RevealMath = window.RevealMath || (function(){
9 var options = Reveal.getConfig().math || {};
10 options.mathjax = options.mathjax || 'https://cdn.mathjax.org/mathjax/latest/MathJax.js';
11 options.config = options.config || 'TeX-AMS_HTML-full';
13 loadScript( options.mathjax + '?config=' + options.config, function() {
18 inlineMath: [['$','$'],['\\(','\\)']] ,
19 skipTags: ['script','noscript','style','textarea','pre']
21 skipStartupTypeset: true
24 // Typeset followed by an immediate reveal.js layout since
25 // the typesetting process could affect slide height
26 MathJax.Hub.Queue( [ 'Typeset', MathJax.Hub ] );
27 MathJax.Hub.Queue( Reveal.layout );
29 // Reprocess equations in slides when they turn visible
30 Reveal.addEventListener( 'slidechanged', function( event ) {
32 MathJax.Hub.Queue( [ 'Typeset', MathJax.Hub, event.currentSlide ] );
38 function loadScript( url, callback ) {
40 var head = document.querySelector( 'head' );
41 var script = document.createElement( 'script' );
42 script.type = 'text/javascript';
45 // Wrapper for callback to make sure it only fires once
46 var finish = function() {
47 if( typeof callback === 'function' ) {
53 script.onload = finish;
56 script.onreadystatechange = function() {
57 if ( this.readyState === 'loaded' ) {
63 head.appendChild( script );