首页 > 解决方案 > 阻止 mathjax 自行运行

问题描述

我正在使用mathjax3.1.2标签。但是,我发现它在文档加载时自动运行并搞砸了我的页面,因为我有等待首先呈现的纯文本。asyncscriptmarked.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>and<code>标签中。但是当 MathJax 在它之前运行时,它被搞砸了:

equation_app.addEventListener('click', e=&gt;{
  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>′&lt;/mo></msup><msup><mo>,</mo><mo>′&lt;/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年前的这篇文章:如何触发MathJax?

我寻求一种方法:

标签: javascriptmathjax

解决方案


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

{
     startup: {
         typeset: false
     }
 }

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


推荐阅读