如何在 html 文件中使用 MathJax 或 LaTex?

How can I use MathJax or LaTex in an html file?

我无法让它工作,我不确定我做错了什么。

我已经下载了 MathJax.js,创建了一个 html 文件并将其 link 适当地编辑到 js 文件。我什至从这里以前回答过的问题中复制并粘贴,只是将 link 从 vpn(vpn 也不起作用,但问题和响应已超过三年)更改为我的 js 文件机.

这是我 html 中的内容:

<html>
   <head>
    <title>MathJax</title>
    <script type="text/x-mathjax-config">
    MathJax.Hub.Config({"HTML-CSS": { preferredFont: "TeX", availableFonts: ["STIX","TeX"] },
        tex2jax: { inlineMath: [ ["$", "$"], ["\\(","\\)"] ], displayMath: [ ["$$","$$"], ["\[", "\]"] ], processEscapes: true, ignoreClass: "tex2jax_ignore|dno" },
        TeX: { noUndefined: { attributes: { mathcolor: "red", mathbackground: "#FFEEEE", mathsize: "90%" } } },
        messageStyle: "none"
    });
    </script>    
    <script type="text/javascript" src="MathJax.js"></script>
    <script type="text/javascript" src="latest.js"></script>

  </head>
  <body>
     The definition of the Euler-Mascheroni constant is
     \gamma=\lim_{n\to\infty}\left(\sum_{k=1}^n\frac1k-ln(n)\right) 
  </body>
</html>

如有任何帮助,我将不胜感激。

有一些问题。

  • 如果您不指定所谓的combined configuration file,您需要自己指定所有必要的组件。特别是输入、输出,在您的情况下,TeX 预处理器在页面中查找 TeX 标记
  • 如果您使用 TeX 输入,则需要将输入用您选择的分隔符包裹起来。

例如

    <script type="text/x-mathjax-config">
    MathJax.Hub.Config({
      jax: ["input/TeX", "output/HTML-CSS"],
      extensions: ["tex2jax.js"],
      "HTML-CSS": { preferredFont: "TeX", availableFonts: ["STIX","TeX"] },
      tex2jax: { inlineMath: [ ["$", "$"], ["\(","\)"] ], displayMath: [ ["$$","$$"], ["\[", "\]"] ], processEscapes: true, ignoreClass: "tex2jax_ignore|dno" },
      TeX: { noUndefined: { attributes: { mathcolor: "red", mathbackground: "#FFEEEE", mathsize: "90%" } } },
      messageStyle: "none"
    });
    </script>    
    <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js"></script>

     The definition of the Euler-Mascheroni constant is
     $\gamma=\lim_{n\to\infty}\left(\sum_{k=1}^n\frac1k-ln(n)\right) $

警告。我不知道 latest.js 应该做什么,你似乎正在使用本地安装,所以一定要检查文档,http://docs.mathjax.org/en/latest/installation.html

这是我根据文档示例构建的文件

<html>
  <head>
    <!-- See http://docs.mathjax.org/en/latest/web/start.html#using-mathjax-from-a-content-delivery-network-cdn -->
    <script type="text/javascript" id="MathJax-script" async
        src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js">
    </script>
  </head>
<body>
<p>
  From the <a href="https://www.w3.org/Math/MJ/Overview.html">overview docs</a>, in MathML: Let's consider <math><mi>a</mi><mo>≠</mo><mn>0</mn></math>.
</p>
<p>
  With <a href="http://docs.mathjax.org/en/latest/basic/mathematics.html">\(\LaTeX\) input</a>:
  When \(a \ne 0\), there are two solutions to \(ax^2 + bx + c = 0\) and they are
  $$x = {-b \pm \sqrt{b^2-4ac} \over 2a}.$$
</p>
</body>
</html>