Python sphinx 斯芬克斯中的MathJax延拓mhchem

Python sphinx 斯芬克斯中的MathJax延拓mhchem,python-sphinx,mathjax,Python Sphinx,Mathjax,如何在Sphinx中启用MathJax扩展mhchem?MathJax是从CDN加载的,请将以下块添加到rst文件中。或者请参见将其添加到模板中,以便可以全局应用 .. raw:: html <script type="text/javascript" > MathJax.Hub.Config({ TeX: { extensions: ["mhchem.js"] } }); </script> 。。原始::html Ma

如何在
Sphinx
中启用
MathJax
扩展
mhchem
?MathJax是从
CDN

加载的,请将以下块添加到rst文件中。或者请参见将其添加到模板中,以便可以全局应用

.. raw:: html

    <script type="text/javascript" >
    MathJax.Hub.Config({
        TeX: { extensions: ["mhchem.js"] }
    });
    </script>
。。原始::html
MathJax.Hub.Config({
TeX:{extensions:[“mhchem.js”]}
});

为了解决所有rst文件的此问题,我将mathjax“子类化”。。。AKA,我在我的_静态目录中创建了另一个js文件,该文件将加载mathjax,然后手动添加所需的扩展名(在我的例子中是取消)。然后我在conf.py中为
mathjax\u path
选项指定了该路径。mathjax_config.js的内容包括:

// Dynamically load script then call helper when script has loaded.
function dynamicallyLoadScript(url, helper) {
    var script = document.createElement("script"); // Make a script DOM node
    script.src = url; // Set it's src to the provided URL

    document.head.appendChild(script); // Add it to the end of the head section of the page (could change 'head' to 'body' to add it to the end of the body section instead)
    script.onreadystatechange= function () {
      if (this.readyState == 'complete') helper();
     }
     script.onload= helper;
}

// Configure MathJax
function mathjax_config() {
  MathJax.Hub.Register.StartupHook("TeX Jax Ready",function () {
  MathJax.Hub.Insert(MathJax.InputJax.TeX.Definitions.macros,{
    cancel: ["Extension","cancel"],
    bcancel: ["Extension","cancel"],
    xcancel: ["Extension","cancel"],
    cancelto: ["Extension","cancel"]
    });
  });
}
var mathjax_url = "https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS-MML_HTMLorMML"
dynamicallyLoadScript(mathjax_url, mathjax_config)
由于没有为我工作,以下是我试图解决的问题:

.. math::

   \require{mhchem}
   \ce{E + S <=> ES -> ES* -> E + P}
。。数学::
\需要{mhchem}
\ce{E+S ES->ES*->E+P}

我认为它既简单又优雅。此外,您不需要在单个
.rst
文件中多次调用
\require{mhchem}

当我直接添加此文件时,会得到
未捕获的引用错误:未定义MathJax
。所以,看起来Sphinx在默认情况下并没有定义MathJax,即使我可以使用它。更具体地说,不能保证在运行原始html之前加载MathJax脚本。