2
単純なインライン式をSVGに変換しようとすると、$が最初に出現した時点で実行が停止し、実行が停止します。インラインTeXのSVG出力を生成するMathJax-node
インライン式:
When $a \ne 0$, there are two solutions to $(ax^2 + bx + c = 0)$ and they are $$x = {-b \pm \sqrt{b^2-4ac} \over 2a}.$$
コードSVGに上記インラインTeXに変換する:
var mjAPI = require("MathJax-node/lib/mj-single.js");
var fs = require('fs');
mjAPI.config({
MathJax : {
SVG : {
scale: 120,
font : "STIX-Web",
linebreaks: { automatic: true },
tex2jax: { inlineMath: [['$','$'], ['\\(','\\)']] }
}
},
displayErrors : true,
displayMessages : false
});
mjAPI.start();
fs.readFile(process.argv[2], 'utf8', function (err, formula) {
if (err) {
return console.log(err);
}
mjAPI.typeset({
math : formula,
format : "inline-TeX",
svg : true,
width: 1,
linebreaks: true
}, function (results) {
if (!results.errors) {
console.log(results.svg)
}
});
});
出力:
ちょうどSVGでときを印刷します。 (下の彼のコメントを参照してください)ピーターKrautzbergerの助けを借りて...
を編集
は、私が仕事にSVGのエクスポートを取得することができました。ここにコードがあります。
var mjAPI = require("mathjax-node/lib/mj-page.js");
var jsdom = require("jsdom").jsdom;
var document = jsdom("When $a \\ne 0$, there are two solutions to $(ax^2 + bx + c = 0)$ and they are $x = {-b \\pm \\sqrt{b^2-4ac} \\over 2a}.$");
mjAPI.start();
mjAPI.typeset({
html: document.body.innerHTML,
renderer: "SVG",
inputs: ["TeX"]
}, function(result) {
"use strict";
document.body.innerHTML = result.html;
var HTML = document.documentElement.outerHTML.replace(/^(\n|\s)*/, "");
console.log(result.html);
});
MJ-ページは別々のモジュールに有利にmathjaxノードから削除されることに注意してください、CF https://github.com/mathjax/MathJax-node/issues/206。 –
私は少し失われています! Haven; mj-page.jsも同様に動作させることができました。 「$ a \ ne 0 $のとき、$(ax^2 + bx + c = 0)$には2つの解があり、それらは $$ x = {-b \ pm \ SVGで$ 2 "を超える。 –
Mathjax-nodeには、ドキュメント全体を1つのsvgに変換する機能はありません。方程式のsvgを作成し、より大きな文書でバッチ処理を簡素化するmjpageを使用します。 –