gpt4 book ai didi

mathjax - 为什么 MathJax.js 生成的 svg 与 MathJax-node 生成的 svg 不同

转载 作者:行者123 更新时间:2023-12-01 12:12:35 30 4
gpt4 key购买 nike

我正在编写一个将 html 保存到 onenote 的网络应用程序。为了保存数学公式,我打算用MathJax.js把数学公式转成svg,然后再把svg转成png,因为onenote api支持的html/css有限。

但似乎 MathJax.js 在浏览器中生成的 svg 不是有效的 svg。我用一个简单的数学公式对其进行了测试:$$a^2 + b^2 = c^2$$ ( demo code ) 并将 svg 复制到 jsfiddle它什么也不显示。

然后我试着写了一个MathJax-node 演示并将svg 复制到jsfiddle再次,它看起来不错。这是我的演示代码,它和 GitHub repo demo 几乎一样:

// a simple TeX-input example
const fs = require('fs')
var mjAPI = require("mathjax-node");
mjAPI.config({
MathJax: {
// traditional MathJax configuration
}
});
mjAPI.start();

var yourMath = String.raw`a^2 + b^2 = c^2`

mjAPI.typeset({
math: yourMath,
format: "TeX", // or "inline-TeX", "MathML"
svg: true, // or svg:true, or html:true
}, function (data) {
if (!data.errors) {console.log(data.svg)}
// will produce:
// <math xmlns="http://www.w3.org/1998/Math/MathML" display="block">
// <mi>E</mi>
// <mo>=</mo>
// <mi>m</mi>
// <msup>
// <mi>c</mi>
// <mn>2</mn>
// </msup>
// </math>

fs.writeFile('math.txt', data.svg, (error) => {
console.log(error)
})
});

我还用 cloudconvert 测试了两个 svg ,结果一样。为什么两个 svg 不同?我错过了什么吗?

最佳答案

差异是由于特定设置:useGlobalCache
默认情况下,MathJax ( docs ) 将其设置为 true而 mathjax-node ( docs ) 将其设置为 false .

在服务器上,MathJax 节点没有任何文档上下文并生成自包含的 SVG。在客户端,MathJax 有一个完整的文档上下文,因此可以跨方程重用 SVG 路径。

关于mathjax - 为什么 MathJax.js 生成的 svg 与 MathJax-node 生成的 svg 不同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50674806/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com