Path: blob/main/src/resources/formats/revealjs/reveal/plugin/math/mathjax3.js
12923 views
/**1* A plugin which enables rendering of math equations inside2* of reveal.js slides. Essentially a thin wrapper for MathJax 33*4* @author Hakim El Hattab5* @author Gerhard Burger6*/7export const MathJax3 = () => {89// The reveal.js instance this plugin is attached to10let deck;1112let defaultOptions = {13tex: {14inlineMath: [ [ '$', '$' ], [ '\\(', '\\)' ] ]15},16options: {17skipHtmlTags: [ 'script', 'noscript', 'style', 'textarea', 'pre' ]18},19startup: {20ready: () => {21MathJax.startup.defaultReady();22MathJax.startup.promise.then(() => {23deck.layout();24});25}26}27};2829function loadScript( url, callback ) {3031let script = document.createElement( 'script' );32script.type = "text/javascript"33script.id = "MathJax-script"34script.src = url;35script.async = true3637// Wrapper for callback to make sure it only fires once38script.onload = () => {39if (typeof callback === 'function') {40callback.call();41callback = null;42}43};4445document.head.appendChild( script );4647}4849return {50id: 'mathjax3',51init: function(reveal) {5253deck = reveal;5455let revealOptions = deck.getConfig().mathjax3 || {};56let options = {...defaultOptions, ...revealOptions};57options.tex = {...defaultOptions.tex, ...revealOptions.tex}58options.options = {...defaultOptions.options, ...revealOptions.options}59options.startup = {...defaultOptions.startup, ...revealOptions.startup}6061let url = options.mathjax || 'https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js';62options.mathjax = null;6364window.MathJax = options;6566loadScript( url, function() {67// Reprocess equations in slides when they turn visible68deck.addEventListener( 'slidechanged', function( event ) {69MathJax.typeset();70} );71} );7273}74}7576};777879