如何使用 mathjax 在同一页面上呈现 asciimath 和 TeX

How to render on the same page both asciimath and TeX using mathjax

我的使用场景是将asciimath作为主要的公式引擎。但是,在某些情况下,我可能需要更强大的功能,而这些功能只能使用 TeX 才能找到。

有没有一种方法可以使用不同的 open/close 子句,一个用于常规 ascii 数学(例如 ` ),另一个用于 TeX 使用,例如 $( 和 )$ ?

所以我想在同一页上混合使用 ascii 数学和 TeX 公式。

当然,您可以同时使用两者!

首先简单地配置两者(假设 MathJax 3):

<script>
  MathJax = {
    loader: { load: ["input/asciimath", "[tex]/html"] },
    tex: {
      packages: { "[+]": ["html"] },
      inlineMath: [
        ["$", "$"],
        ["\(", "\)"]
      ],
      displayMath: [
        ["$$", "$$"],
        ["\[", "\]"]
      ]
    },
    asciimath: {
      delimiters: [["`", "`"]]
    }
  };
</script>

如果你想要 AsciiMath 或 Latex,则使用分隔符向 MathJax 发出信号:

<div>
  $$\sum_{n = 100}^{1000}\left(\frac{10\sqrt{n}}{n}\right)$$
</div>
<div>
  `sum_(n = 100)^(1000)(frac(10sqrt(n))(n))`
</div>

请记住,AsciiMath 要求您通过设置 displaystyle: false / true 来确定是否要为整个文档设置显示样式,您不能同时拥有两者,因为您可以用于乳胶:

asciimath: {
  displaystyle: true
}

代码沙箱:https://codesandbox.io/s/mathjax-3-0ve5d