简体   繁体   English

如何配置 MathJax 以在 HTML 中呈现化学方程式?

[英]How to configure MathJax to render chemical equations in HTML?

I am trying to render mathematical equations using MathJax in HTML.我正在尝试在 HTML 中使用 MathJax 呈现数学方程。 So far, here's what I have:到目前为止,这就是我所拥有的:

<script type="text/x-mathjax-config">
    MathJax.Hub.Config({
        tex2jax:
        {
            inlineMath: [['$','$'], ['\\(','\\)']],
            ignoreClass: "math-editor", // put this here
        }
  });
</script>

<script type="text/javascript" async
  src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-MML-AM_CHTML">
</script>

However, I am also trying to get MathJax to recognize chemical equations such as $\\ce{Hg^2+ ->[I-] HgI2 ->[I-] [Hg^{II}I4]^2-}$ but so far I have no success.但是,我也试图让 MathJax 识别化学方程式,例如$\\ce{Hg^2+ ->[I-] HgI2 ->[I-] [Hg^{II}I4]^2-}$但是到目前为止,我还没有成功。 What would be a simple and straightforward way to modify MathJax so that it recognizes chemical equation scripts as well?修改 MathJax 以便它也识别化学方程式脚本的简单而直接的方法是什么?

I am using Django for my web application.我正在将 Django 用于我的 Web 应用程序。

You need to include你需要包括

  TeX: {
    extensions: ['mhchem.js']
  },

in your MathJax configuration.在您的 MathJax 配置中。 So you should use所以你应该使用

    MathJax.Hub.Config({
        TeX: {
          extensions: ['mhchem.js']
        },
        tex2jax:
        {
            inlineMath: [['$','$'], ['\\(','\\)']],
            ignoreClass: "math-editor", // put this here
        }
  });

instead.反而。 If you aren't using MathML or AsciiMath input formats, you would also do better to load the TeX-AMS_CHTML config file rather than the larger (and so slower) TeX-MML-AM_CHTML file.如果您不使用 MathML 或 AsciiMath 输入格式,您最好加载TeX-AMS_CHTML配置文件,而不是更大(也更慢)的TeX-MML-AM_CHTML文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM