MathJax 未处理的包含外部文件

Included external file not processed by MathJax

我想在 html 文件中包含一个外部文件,其中包含应由 MathJax 处理的数学内容。我尝试了几种方法来做到这一点,当外部文件被包含在 html 文件中时,其中的数学内容没有被处理。一个证明这一点的最小例子:

tst.html:

<!DOCTYPE html>
<html>
  <head>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
    <script type="text/javascript" src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-chtml.js"></script>
  </head>
  <body>
    This displays correctly: \(\phi\). 
    <inc></inc>
    <script>
     fetch("./tst.txt")
       .then(response => {
         return response.text()
       })
       .then(data => {
         document.querySelector("inc").innerHTML = data;
       });
    </script>
    <div id="abc"></div>
    <div id="def">
      <script>$("#def").load("tst.txt");</script>
    </div>
    <script>
     $(function(){
       $('#abc').load('tst.txt');
     });
    </script>
  </body>
</html>

tst.txt:

\(\phi = 0\)

在浏览器中,html 文件中的数学内容显示正确,但包含文件中的文本显示不正确。有没有办法正确处理外部文件中的数学内容?

也许问题在于,只有在 MathJax 呈现 Maths.js 文件后,文件才会被拉入页面。因此,您需要 'ask' MathJax 在页面中搜索更多数学并呈现新数学。

来自 MathJax 文档:

If you are writing a dynamic web page where content containing mathematics may appear after MathJax has already typeset the rest of the page, then you will need to tell MathJax to look for mathematics in the page again when that new content is produced. To do that, you need to use the MathJax.typeset() method. This will cause MathJax to look for unprocessed mathematics on the page and typeset it, leaving unchanged any math that has already been typeset.