-
Notifications
You must be signed in to change notification settings - Fork 1
/
d_mathjax_wrapper.js
60 lines (51 loc) · 1.49 KB
/
d_mathjax_wrapper.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/usr/bin/env node
const util = require('util');
const fs = require("fs");
const MJ = require("mathjax");
let mj;
const main = async () => {
mj = await MJ.init({
loader: {
load: [
'input/tex',
'[tex]/boldsymbol',
'output/svg',
'input/asciimath',
]
},
tex: {
packages: {
'[+]': ['boldsymbol']
},
},
});
const args = process.argv.slice(2);
let display;
if (args[1] === "block") {
display = true;
} else if (args[1] === "inline") {
display = false;
} else {
throw Error(`Incorrect value provided for second argument: ${args[1]}`);
}
const stdin_buffer = fs.readFileSync(0); // STDIN_FILENO = 0
const data = stdin_buffer.toString();
let svg_object_wrapped;
if (args[0] == "tex") {
// https://docs.mathjax.org/en/latest/web/typeset.html?highlight=outerhtml#conversion-options
svg_object_wrapped = mj.tex2svg(data, {
display,
});
} else if (args[0] == "amath") {
svg_object_wrapped = mj.asciimath2svg(data);
} else {
throw Error(`Incorrect value provided for first argument: ${args[0]}`);
}
const svg_object = svg_object_wrapped.children[0];
const svg_html = mj.startup.adaptor.outerHTML(svg_object);
console.log(svg_html.toString());
}
main().catch (error => {
console.error(error)
process.exit(1)
})