【问题标题】:Cannot achieve the same result with mathjax-node as with MathJax on the browser使用 mathjax-node 无法获得与浏览器上的 MathJax 相同的结果
【发布时间】:2021-12-19 21:16:58
【问题描述】:

我想用 mathjax-node 渲染一些公式,但用户也应该能够用光标单独选择在它们下划线的每个元素。例如,如果出现求和,他可以选择极值、内部公式的元素、迭代变量等。当元素呈现为 对象时是可能的,例如,可以使用 MathJax 2.7.7 直接从 URL 完成。

在浏览器上使用 MathJax 时,我有一个这样配置的页面:

<!DOCTYPE html>
<html>
    <head>
        ...
        <script type="text/x-mathjax-config">
            MathJax.Hub.Config({
                extensions: ["tex2jax.js","[Contrib]/forminput/forminput.js"],
                jax: ["input/TeX","output/HTML-CSS"],
                tex2jax: {
                    inlineMath: [ ['$','$'], ["\\(","\\)"] ],
                    displayMath: [ ['$$','$$'], ["\\[","\\]"] ],
                    processEscapes: true,
                    processEnvironments: true,
                },
                TeX: {extensions: ["AMSmath.js","AMSsymbols.js"]},
                displayAlign: 'center',

                "HTML-CSS": {
                    styles: {'.MathJax_Display': {"margin": 0}},
                    linebreaks: { automatic: true }
                }
            });
        </script>
        <script 
            type="text/javascript"
            src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.7/latest.js?config=TeX-MML-AM_CHTML"
        />

在这种情况下,如果我有这个公式 $\sum_{i=0}^ni>2$,结果是:

但现在我正在使用从https://github.com/mathjax/MathJax-node/tarball/master 下载的 mathjax-node。根据https://www.npmjs.com/package/mathjax-node的文档我不得不说:

var mjAPI = require("mathjax-node");
mjAPI.config({
    MathJax: {
        // traditional MathJax configuration
    }
});
mjAPI.start();

(在配置部分,不再识别行:"extensions: ["tex2jax.js","[Contrib]/forminput/forminput.js"]")。

用排版函数得到带有结果的对象:

var yourMath = '\sum_{i=0}^ni>2';

let result = mjAPI.typeset({
    math: yourMath,
    format: "TeX", // or "inline-TeX", "MathML"
    mml:true,      // or svg:true, or html:true
},

然后用“result.mml”、“result.svg”或“result.html”调用应该渲染的部分。

我只设法使用“html:true”选项渲染为 对象。但它看起来与我在网络上使用 MathJax 时不同。例如,如果输入“格式:'inline-TeX'”,我会得到:

这里有人问过类似的问题:mathjax-node: different output when formatted on webpage than in node project,解决方案是在排版中添加“css:true”选项,但我试过了,看起来还是一样。我想我还是应该称它为“result.html”。

【问题讨论】:

    标签: javascript html node.js mathjax


    【解决方案1】:

    我正在回答我自己的问题。如果“result”是返回的对象,我不明白应该如何使用“result.css”属性。唯一要做的就是将它包含在显示网页样式的配置中。例如,网页可能是:

    <html>
        <head>
            <style>
                result.css
            </style>
        </head>
        <body>
            result.html
        </body>
    </html>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-06-12
      • 1970-01-01
      • 1970-01-01
      • 2020-07-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多