math.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. (function(){
  8. var config = Reveal.getConfig().math || {};
  9. config.mode = config.mode || 'TeX-AMS_HTML-full';
  10. var head = document.querySelector( 'head' );
  11. var script = document.createElement( 'script' );
  12. script.type = 'text/javascript';
  13. script.src = 'http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=' + config.mode;
  14. // Detect when the script has loaded
  15. script.onload = onScriptLoad;
  16. script.onreadystatechange = function() {
  17. if ( this.readyState === 'loaded' ) {
  18. onScriptLoad.call();
  19. }
  20. }
  21. head.appendChild( script );
  22. function onScriptLoad() {
  23. MathJax.Hub.Config({
  24. messageStyle: 'none',
  25. tex2jax: { inlineMath: [['$','$'],['\\(','\\)']] }
  26. });
  27. // Process any math inside of the current slide when navigating,
  28. // this is important since it's not possible to typeset
  29. // equations within invisible elements (far future or past).
  30. Reveal.addEventListener( 'slidechanged', function( event ) {
  31. // This will only typeset equations that have not yet been
  32. // processed, as well as equations that have change since
  33. // last being processed.
  34. MathJax.Hub.Update( event.currentSlide );
  35. } );
  36. }
  37. })();