Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/474.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在Mathjax节点的SVG输出中更改字体样式和字体大小?_Javascript_Node.js_Svg_Mathjax - Fatal编程技术网

Javascript 如何在Mathjax节点的SVG输出中更改字体样式和字体大小?

Javascript 如何在Mathjax节点的SVG输出中更改字体样式和字体大小?,javascript,node.js,svg,mathjax,Javascript,Node.js,Svg,Mathjax,我想在SVG输出中设置不同的字体样式和字体大小,我正在使用MathJax节点来实现这一点,我目前正在本地进行此操作,没有任何服务器,我可以从MathML创建SVG输出作为输入,但无法设置字体侧(抱歉,我是MathJax新手)另外,如果知道如何缩放SVG输出也不起作用,那就太好了 输入为: <math style="font-family: Arial;" xmlns="http://www.w3.org/1998/Math/MathML" alttext="math equation" d

我想在SVG输出中设置不同的字体样式和字体大小,我正在使用MathJax节点来实现这一点,我目前正在本地进行此操作,没有任何服务器,我可以从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>
⤹+∑MA=0;(900磅)(2吨)−(FBDsin30°)10英尺=0
我的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);
  });
});
const fs=require(“fs”),
mjAPI=require(“mathjax节点”),
svgexport=require('svgexport');
var yourMath;
mjAPI.config({
MathJax:{
SVG:{
比例:120,
字体:“STIX Web”,
未定义的家族:“'Arial Unicode MS',衬线”,
addMMLclasses:true
}
},
显示错误:正确,
显示消息:false
});
mjAPI.start();
你的数学⤹+∑MA=0;(900磅)(2吨)−(FBDsin30°)10英尺=0';
mjAPI.字体({
数学:你的数学,
格式:“MathML”,
svg:是的,
},函数(数据){
如果(!data.errors){
fs.writeFile(“test.svg”、data.svg、function(err){
如果(错误){
返回console.log(err);
}
log('File saved!');
});
}
var mJSON=[{“输入”:[“test.svg”],“输出”:[“123.png”],“质量”:[“100%”};
render(mJSON,函数(err){
控制台日志(err);
});
});
所以我需要的是:

<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>
  • 需要更改SVG输出中的字体样式
  • 需要更改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>
    

    这是输出SVG(注意:即使在MathML中设置了字体样式,字体也没有变化)


    谢谢

    我也需要这样做(如果你解决了,请让我知道)不清楚你在追求什么。该示例按预期工作。你想完成什么?(尽管字体样式和字体大小应该在MathML源代码中处理,SVG不需要缩放。)嗨,Peter,谢谢!但是我已经在上面添加了我的输出供您参考,请检查我是否没有得到字体更改(如果错误,请纠正我),即使在此链接中在MathML中设置字体样式,数学字体更改仍然有效,但在SVG中不起作用,很抱歉问这个问题,如果您的代码表明您想要更改字体系列,即。,那张脸。这是一个完全不同的问题。MathJax(因此MathJax节点)只支持少数支持数学的字体,感谢您的详细回答,Peter,现在明白了