我想在SVG输出中设置不同的字体样式和不同的字体大小,我正在使用MathJax-Node,我目前在没有任何服务器的情况下在本地执行此操作,我可以创建MathML的SVG输出作为输入但无法设置字体方面(对不起,我是MathJax的新手)也很高兴知道如何扩展SVG输出,因为它不起作用
输入为:
<math style="font-family: Arial;" xmlns="http://www.w3.org/1998/Math/MathML" alttext="math equation" display="inline" altimg-width="467" altimg-height="25" altimg="../images/altmath_5579.png"><mo>⤹</mo><mo>+</mo><mo>Σ</mo><msub><mi>M</mi><mrow><mi>A</mi></mrow></msub><mo>=</mo><mn>0</mn><mo>;</mo><mspace width="10pt"/><mo>(</mo><mn>900</mn><mspace width="0.33em"/><mi mathvariant="normal">l</mi><mi mathvariant="normal">b</mi><mo>)</mo><mo>(</mo><mn>2</mn><mspace width="0.33em"/><mi mathvariant="normal">f</mi><mi mathvariant="normal">t</mi><mo>)</mo><mo>−</mo><mo>(</mo><msub><mi>F</mi><mrow><mi>B</mi><mi>D</mi></mrow></msub><mspace width="0.33em"/><mi mathvariant="normal">s</mi><mi mathvariant="normal">i</mi><mi mathvariant="normal">n</mi><mspace width="0.33em"/><mn>30</mn><mo>°</mo><mo>)</mo><mspace width="0.33em"/><mn>10</mn><mspace width="0.33em"/><mi mathvariant="normal">f</mi><mi mathvariant="normal">t</mi><mo mathvariant="normal">=</mo><mn>0</mn></math>
我的JS文件是:
const fs = require("fs"),
mjAPI = require("mathjax-node"),
svgexport = require('svgexport');
var yourMath;
mjAPI.config ({
MathJax : {
SVG : {
scale: 120,
font : "STIX-Web",
undefinedFamily:"'Arial Unicode MS',serif",
addMMLclasses: true
}
},
displayErrors : true,
displayMessages : false
});
mjAPI.start();
yourMath = '<math style="font-family: Arial;" xmlns="http://www.w3.org/1998/Math/MathML" alttext="math equation" display="inline" altimg-width="467" altimg-height="25" altimg="../images/altmath_5579.png"><mo>⤹</mo><mo>+</mo><mo>Σ</mo><msub><mi>M</mi><mrow><mi>A</mi></mrow></msub><mo>=</mo><mn>0</mn><mo>;</mo><mspace width="10pt"/><mo>(</mo><mn>900</mn><mspace width="0.33em"/><mi mathvariant="normal">l</mi><mi mathvariant="normal">b</mi><mo>)</mo><mo>(</mo><mn>2</mn><mspace width="0.33em"/><mi mathvariant="normal">f</mi><mi mathvariant="normal">t</mi><mo>)</mo><mo>−</mo><mo>(</mo><msub><mi>F</mi><mrow><mi>B</mi><mi>D</mi></mrow></msub><mspace width="0.33em"/><mi mathvariant="normal">s</mi><mi mathvariant="normal">i</mi><mi mathvariant="normal">n</mi><mspace width="0.33em"/><mn>30</mn><mo>°</mo><mo>)</mo><mspace width="0.33em"/><mn>10</mn><mspace width="0.33em"/><mi mathvariant="normal">f</mi><mi mathvariant="normal">t</mi><mo mathvariant="normal">=</mo><mn>0</mn></math>';
mjAPI.typeset({
math: yourMath,
format: "MathML",
svg:true,
}, function (data) {
if (!data.errors) {
fs.writeFile("test.svg", data.svg, function(err){
if(err){
return console.log(err);
}
console.log('File saved !');
});
}
var mJSON = [{"input":["test.svg"],"output":["123.png"],"quality":["100%"]}];
svgexport.render(mJSON, function(err){
console.log(err);
});
});
所以我需要的是: