mathjax.swig 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. {%- set mathjax_uri = theme.vendors.mathjax or '//cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js' %}
  2. <script>
  3. if (typeof MathJax === 'undefined') {
  4. window.MathJax = {
  5. loader: {
  6. {%- if theme.math.mathjax.mhchem %}
  7. load: ['[tex]/mhchem'],
  8. {%- endif %}
  9. source: {
  10. '[tex]/amsCd': '[tex]/amscd',
  11. '[tex]/AMScd': '[tex]/amscd'
  12. }
  13. },
  14. tex: {
  15. inlineMath: {'[+]': [['$', '$']]},
  16. {%- if theme.math.mathjax.mhchem %}
  17. packages: {'[+]': ['mhchem']},
  18. {%- endif %}
  19. tags: 'ams'
  20. },
  21. options: {
  22. renderActions: {
  23. findScript: [10, doc => {
  24. document.querySelectorAll('script[type^="math/tex"]').forEach(node => {
  25. const display = !!node.type.match(/; *mode=display/);
  26. const math = new doc.options.MathItem(node.textContent, doc.inputJax[0], display);
  27. const text = document.createTextNode('');
  28. node.parentNode.replaceChild(text, node);
  29. math.start = {node: text, delim: '', n: 0};
  30. math.end = {node: text, delim: '', n: 0};
  31. doc.math.push(math);
  32. });
  33. }, '', false],
  34. insertedScript: [200, () => {
  35. document.querySelectorAll('mjx-container').forEach(node => {
  36. let target = node.parentNode;
  37. if (target.nodeName.toLowerCase() === 'li') {
  38. target.parentNode.classList.add('has-jax');
  39. }
  40. });
  41. }, '', false]
  42. }
  43. }
  44. };
  45. (function () {
  46. var script = document.createElement('script');
  47. script.src = '{{ mathjax_uri }}';
  48. script.defer = true;
  49. document.head.appendChild(script);
  50. })();
  51. } else {
  52. MathJax.startup.document.state(0);
  53. MathJax.texReset();
  54. MathJax.typeset();
  55. }
  56. </script>