如何在MathJax
中启用mhchem
分机Sphinx
? MathJax从CDN
加载。
答案 0 :(得分:3)
将以下块添加到第一个文件中。或者请参阅Adding a javascript script tag some place so that it works for every file in sphinx documentation将其添加到模板中,以便全局应用。
.. raw:: html
<script type="text/javascript" >
MathJax.Hub.Config({
TeX: { extensions: ["mhchem.js"] }
});
</script>
答案 1 :(得分:0)
要解决所有rst文件的此问题,我将'mathjax'子类化了...又是,我在_static目录中制作了另一个js文件,该文件将加载mathjax,然后手动添加所需的扩展名(在我的情况下,取消)。然后,我在conf.py中为mathjax_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)
答案 2 :(得分:0)
由于Sunhwan Jo's answer不适用于我,因此我尝试解决此问题:
.. math::
\require{mhchem}
\ce{E + S <=> ES -> ES* -> E + P}
我认为它简单而优雅。此外,您无需在单个\require{mhchem}
文件中多次调用.rst
。