【问题标题】:stop mathjax from running itself阻止 mathjax 自行运行
【发布时间】:2021-12-04 19:24:59
【问题描述】:

我在script 标签上使用mathjax3.1.2async。但是,我发现它会在文档加载时自动运行并搞砸我的页面,因为我有纯文本等待 marked.js 首先呈现。

这是html内容:

equation_app.addEventListener('click', e=>{
  autofocus(e);
  let start = editor.selectionStart;
  let end = editor.selectionEnd;
  tagging('$', '$');
  editor.focus();
  if(editor.selectionStart === editor.selectionEnd)editor.selectionStart = editor.selectionEnd = start + 1;
  refresh();
});

在标记渲染后,它将被包装到<pre><code> 标记中。但是因为 MathJax 在它之前运行,它被搞砸了:

equation_app.addEventListener('click', e=>{
  autofocus(e);
  let start = editor.selectionStart;
  let end = editor.selectionEnd;
  tagging('<mjx-container class="MathJax CtxtMenu_Attached_0" jax="CHTML" role="presentation" tabindex="0" ctxtmenu_counter="0" style="font-size: 101.6%; position: relative;"><mjx-math class="MJX-TEX" aria-hidden="true"><mjx-msup><mjx-mi class="mjx-n"></mjx-mi><mjx-script style="vertical-align: 0.363em;"><mjx-mo class="mjx-n" size="s"><mjx-c class="mjx-c2032"></mjx-c></mjx-mo></mjx-script></mjx-msup><mjx-msup><mjx-mo class="mjx-n"><mjx-c class="mjx-c2C"></mjx-c></mjx-mo><mjx-script style="vertical-align: 0.363em;"><mjx-mo class="mjx-n" size="s"><mjx-c class="mjx-c2032"></mjx-c></mjx-mo></mjx-script></mjx-msup></mjx-math><mjx-assistive-mml role="presentation" unselectable="on" display="inline"><math xmlns="http://www.w3.org/1998/Math/MathML"><msup><mi></mi><mo>′</mo></msup><msup><mo>,</mo><mo>′</mo></msup></math></mjx-assistive-mml></mjx-container>');
  editor.focus();
  if(editor.selectionStart === editor.selectionEnd)editor.selectionStart = editor.selectionEnd = start + 1;
  refresh();
});

我做了很多研究,似乎在版本 2 中 skipStartupTypeset 配置解决了问题,但在版本 3 中删除了。

参考这篇4年前的帖子:How to trigger MathJax?

我在寻找方法:

  • 禁止 mathjax 在加载时自行运行

【问题讨论】:

    标签: javascript mathjax


    【解决方案1】:

    通过在配置中设置以下内容,只需将 Mathjax 3 配置为在启动时不进行排版:

    {
         startup: {
             typeset: false
         }
     }
    

    文档:https://docs.mathjax.org/en/latest/options/startup/startup.html#the-configuration-block

    【讨论】:

      猜你喜欢
      • 2018-11-24
      • 1970-01-01
      • 2021-12-10
      • 2011-01-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-02-20
      相关资源
      最近更新 更多