math.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /**
  2. * A plugin which enables rendering of math equations inside
  3. * of reveal.js slides. Essentially a thin wrapper for MathJax.
  4. *
  5. * @author Hakim El Hattab
  6. */
  7. var RevealMath = window.RevealMath || (function(){
  8. var loaded = false;
  9. var config = Reveal.getConfig().math || {};
  10. config.mode = config.mode || 'TeX-AMS_HTML-full';
  11. var head = document.querySelector( 'head' );
  12. var script = document.createElement( 'script' );
  13. script.type = 'text/javascript';
  14. script.src = 'http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=' + config.mode;
  15. // Detect when the script has loaded
  16. script.onload = onScriptLoad;
  17. // IE
  18. script.onreadystatechange = function() {
  19. if ( this.readyState === 'loaded' ) {
  20. onScriptLoad.call();
  21. }
  22. }
  23. // Normal browsers
  24. head.appendChild( script );
  25. function onScriptLoad() {
  26. // Conditioned just in case both onload and readystate fire
  27. if( loaded === false ) {
  28. loaded = true;
  29. MathJax.Hub.Config({
  30. messageStyle: 'none',
  31. tex2jax: { inlineMath: [['$','$'],['\\(','\\)']] }
  32. });
  33. // Process any math inside of the current slide when navigating,
  34. // this is needed since it's not possible to typeset equations
  35. // within invisible elements (far future or past).
  36. Reveal.addEventListener( 'slidechanged', function( event ) {
  37. // This will only typeset equations that have not yet been
  38. // processed, as well as equations that have change since
  39. // last being processed.
  40. MathJax.Hub.Update( event.currentSlide );
  41. } );
  42. }
  43. }
  44. })();