From 39019040579208b87f620567eb722d70e310bc8f Mon Sep 17 00:00:00 2001 From: Hakim El Hattab Date: Mon, 12 Aug 2013 23:01:35 -0400 Subject: [PATCH] comments and failesafes for #531 --- examples/math.html | 5 +++++ plugin/math/math.js | 38 ++++++++++++++++++++++++-------------- 2 files changed, 29 insertions(+), 14 deletions(-) diff --git a/examples/math.html b/examples/math.html index 67fa546..d282f8a 100644 --- a/examples/math.html +++ b/examples/math.html @@ -38,6 +38,7 @@

The Lorenz Equations

+ \[\begin{aligned} \dot{x} & = \sigma(y-x) \\ \dot{y} & = \rho x - y - xz \\ @@ -104,6 +105,10 @@ Reveal.initialize({ transition: 'linear', + math: { + mode: 'TeX-AMS_HTML-full' + }, + dependencies: [ { src: '../lib/js/classList.js', condition: function() { return !document.body.classList; } }, { src: '../plugin/markdown/marked.js', condition: function() { return !!document.querySelector( '[data-markdown]' ); } }, diff --git a/plugin/math/math.js b/plugin/math/math.js index 8ab74fa..b6bd82f 100755 --- a/plugin/math/math.js +++ b/plugin/math/math.js @@ -4,7 +4,9 @@ * * @author Hakim El Hattab */ -(function(){ +var RevealMath = window.RevealMath || (function(){ + + var loaded = false; var config = Reveal.getConfig().math || {}; config.mode = config.mode || 'TeX-AMS_HTML-full'; @@ -16,32 +18,40 @@ // Detect when the script has loaded script.onload = onScriptLoad; + + // IE script.onreadystatechange = function() { if ( this.readyState === 'loaded' ) { onScriptLoad.call(); } } + // Normal browsers head.appendChild( script ); function onScriptLoad() { - MathJax.Hub.Config({ - messageStyle: 'none', - tex2jax: { inlineMath: [['$','$'],['\\(','\\)']] } - }); + // Conditioned just in case both onload and readystate fire + if( loaded === false ) { + loaded = true; - // Process any math inside of the current slide when navigating, - // this is important since it's not possible to typeset - // equations within invisible elements (far future or past). - Reveal.addEventListener( 'slidechanged', function( event ) { + MathJax.Hub.Config({ + messageStyle: 'none', + tex2jax: { inlineMath: [['$','$'],['\\(','\\)']] } + }); - // This will only typeset equations that have not yet been - // processed, as well as equations that have change since - // last being processed. - MathJax.Hub.Update( event.currentSlide ); + // Process any math inside of the current slide when navigating, + // this is needed since it's not possible to typeset equations + // within invisible elements (far future or past). + Reveal.addEventListener( 'slidechanged', function( event ) { - } ); + // This will only typeset equations that have not yet been + // processed, as well as equations that have change since + // last being processed. + MathJax.Hub.Update( event.currentSlide ); + + } ); + } }