MathJax.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. // 用于标识是否配置
  2. let isMathjaxConfig = false
  3. const initMathjaxConfig = () => {
  4. if (!window.MathJax) {
  5. return
  6. }
  7. window.MathJax.Hub.Config({
  8. // 关闭js加载过程信息
  9. showProcessingMessages: false,
  10. // 不显示信息
  11. messageStyle: 'none',
  12. jax: ['input/TeX', 'output/HTML-CSS'],
  13. tex2jax: {
  14. // 行内公式选择符
  15. inlineMath: [
  16. ['$', '$'],
  17. ['\\(', '\\)']
  18. ],
  19. // 段内公式选择符
  20. displayMath: [
  21. ['$$', '$$'],
  22. ['\\[', '\\]']
  23. ],
  24. // 避开某些标签
  25. skipTags: ['script', 'noscript', 'style', 'textarea', 'pre', 'code', 'a']
  26. },
  27. 'HTML-CSS': {
  28. // 可选字体
  29. availableFonts: ['STIX', 'TeX'],
  30. // 关闭右击菜单显示
  31. showMathMenu: false
  32. }
  33. })
  34. // 配置完成,改为true
  35. isMathjaxConfig = true
  36. }
  37. const MathQueue = function (elementId) {
  38. if (!window.MathJax) {
  39. return
  40. }
  41. window.MathJax.Hub.Queue(['Typeset', window.MathJax.Hub, document.getElementById(elementId)])
  42. }
  43. export default {
  44. isMathjaxConfig,
  45. initMathjaxConfig,
  46. MathQueue
  47. }