MCPcopy
hub / github.com/hakimel/reveal.js / MathJax2

Function MathJax2

plugin/math/mathjax2.js:7–89  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

5 * @author Hakim El Hattab
6 */
7export const MathJax2 = () => {
8
9 // The reveal.js instance this plugin is attached to
10 let deck;
11
12 let defaultOptions = {
13 messageStyle: 'none',
14 tex2jax: {
15 inlineMath: [ [ '$', '$' ], [ '\\(', '\\)' ] ],
16 skipTags: [ 'script', 'noscript', 'style', 'textarea', 'pre', 'code' ]
17 },
18 skipStartupTypeset: true
19 };
20
21 function loadScript( url, callback ) {
22
23 let head = document.querySelector( 'head' );
24 let script = document.createElement( 'script' );
25 script.type = 'text/javascript';
26 script.src = url;
27
28 // Wrapper for callback to make sure it only fires once
29 let finish = () => {
30 if( typeof callback === 'function' ) {
31 callback.call();
32 callback = null;
33 }
34 }
35
36 script.onload = finish;
37
38 // IE
39 script.onreadystatechange = () => {
40 if ( this.readyState === 'loaded' ) {
41 finish();
42 }
43 }
44
45 // Normal browsers
46 head.appendChild( script );
47
48 }
49
50 return {
51 id: 'mathjax2',
52
53 init: function( reveal ) {
54
55 deck = reveal;
56
57 let revealOptions = deck.getConfig().mathjax2 || deck.getConfig().math || {};
58
59 let options = { ...defaultOptions, ...revealOptions };
60 let mathjax = options.mathjax || 'https://cdn.jsdelivr.net/npm/mathjax@2/MathJax.js';
61 let config = options.config || 'TeX-AMS_HTML-full';
62 let url = mathjax + '?config=' + config;
63
64 options.tex2jax = { ...defaultOptions.tex2jax, ...revealOptions.tex2jax };

Callers

nothing calls this directly

Calls 4

getConfigMethod · 0.80
getRevealElementMethod · 0.80
onMethod · 0.80
loadScriptFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…