math.mjs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. const M = () => {
  2. let n, s = {
  3. version: "latest",
  4. delimiters: [
  5. { left: "$$", right: "$$", display: !0 },
  6. // Note: $$ has to come before $
  7. { left: "$", right: "$", display: !1 },
  8. { left: "\\(", right: "\\)", display: !1 },
  9. { left: "\\[", right: "\\]", display: !0 }
  10. ],
  11. ignoredTags: ["script", "noscript", "style", "textarea", "pre"]
  12. };
  13. const r = (t) => {
  14. let e = document.createElement("link");
  15. e.rel = "stylesheet", e.href = t, document.head.appendChild(e);
  16. }, l = (t) => new Promise((e, i) => {
  17. const o = document.createElement("script");
  18. o.type = "text/javascript", o.onload = e, o.onerror = i, o.src = t, document.head.append(o);
  19. });
  20. async function a(t) {
  21. for (const e of t)
  22. await l(e);
  23. }
  24. return {
  25. id: "katex",
  26. init: function(t) {
  27. n = t;
  28. let e = n.getConfig().katex || {}, i = { ...s, ...e };
  29. const { local: o, version: u, extensions: k, ...m } = i;
  30. let c = i.local || "https://cdn.jsdelivr.net/npm/katex", d = i.local ? "" : "@" + i.version, f = c + d + "/dist/katex.min.css", y = c + d + "/dist/katex.min.js", g = c + d + "/dist/contrib/mhchem.min.js", j = c + d + "/dist/contrib/auto-render.min.js", p = [y];
  31. i.extensions && i.extensions.includes("mhchem") && p.push(g), p.push(j);
  32. const h = () => {
  33. renderMathInElement(t.getSlidesElement(), m), n.layout();
  34. };
  35. r(f), a(p).then(() => {
  36. n.isReady() ? h() : n.on("ready", h.bind(this));
  37. });
  38. }
  39. };
  40. }, x = () => {
  41. let n, s = {
  42. messageStyle: "none",
  43. tex2jax: {
  44. inlineMath: [["$", "$"], ["\\(", "\\)"]],
  45. skipTags: ["script", "noscript", "style", "textarea", "pre"]
  46. },
  47. skipStartupTypeset: !0
  48. };
  49. function r(l, a) {
  50. let t = document.querySelector("head"), e = document.createElement("script");
  51. e.type = "text/javascript", e.src = l;
  52. let i = () => {
  53. typeof a == "function" && (a.call(), a = null);
  54. };
  55. e.onload = i, e.onreadystatechange = () => {
  56. this.readyState === "loaded" && i();
  57. }, t.appendChild(e);
  58. }
  59. return {
  60. id: "mathjax2",
  61. init: function(l) {
  62. n = l;
  63. let a = n.getConfig().mathjax2 || n.getConfig().math || {}, t = { ...s, ...a }, e = t.mathjax || "https://cdn.jsdelivr.net/npm/mathjax@2/MathJax.js", i = t.config || "TeX-AMS_HTML-full", o = e + "?config=" + i;
  64. t.tex2jax = { ...s.tex2jax, ...a.tex2jax }, t.mathjax = t.config = null, r(o, function() {
  65. MathJax.Hub.Config(t), MathJax.Hub.Queue(["Typeset", MathJax.Hub, n.getRevealElement()]), MathJax.Hub.Queue(n.layout), n.on("slidechanged", function(u) {
  66. MathJax.Hub.Queue(["Typeset", MathJax.Hub, u.currentSlide]);
  67. });
  68. });
  69. }
  70. };
  71. }, v = () => {
  72. let n, s = {
  73. tex: {
  74. inlineMath: [["$", "$"], ["\\(", "\\)"]]
  75. },
  76. options: {
  77. skipHtmlTags: ["script", "noscript", "style", "textarea", "pre"]
  78. },
  79. startup: {
  80. ready: () => {
  81. MathJax.startup.defaultReady(), MathJax.startup.promise.then(() => {
  82. n.layout();
  83. });
  84. }
  85. }
  86. };
  87. function r(l, a) {
  88. let t = document.createElement("script");
  89. t.type = "text/javascript", t.id = "MathJax-script", t.src = l, t.async = !0, t.onload = () => {
  90. typeof a == "function" && (a.call(), a = null);
  91. }, document.head.appendChild(t);
  92. }
  93. return {
  94. id: "mathjax3",
  95. init: function(l) {
  96. n = l;
  97. let a = n.getConfig().mathjax3 || {}, t = { ...s, ...a };
  98. t.tex = { ...s.tex, ...a.tex }, t.options = { ...s.options, ...a.options }, t.startup = { ...s.startup, ...a.startup };
  99. let e = t.mathjax || "https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js";
  100. t.mathjax = null, window.MathJax = t, r(e, function() {
  101. n.addEventListener("slidechanged", function(i) {
  102. MathJax.typeset();
  103. });
  104. });
  105. }
  106. };
  107. }, J = x;
  108. /*!
  109. * This plugin is a wrapper for the MathJax2,
  110. * MathJax3 and KaTeX typesetter plugins.
  111. */
  112. const S = Plugin = Object.assign(J(), {
  113. KaTeX: M,
  114. MathJax2: x,
  115. MathJax3: v
  116. });
  117. export {
  118. S as default
  119. };