-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmathjax-jsonrpc.js
executable file
·37 lines (32 loc) · 1.2 KB
/
mathjax-jsonrpc.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
#!/usr/bin/env node -r esm
// Author: Shaq Xu <[email protected]>
// Maintainer: Shaq Xu <[email protected]>
// Version: 1.0
//const mathjax = require('mathjax-full/es5/node-main.js');
// require path relative to current file not node execute directory
const mathjax = require('mathjax-full/components/src/node-main/node-main.js');
const rpc = require('vscode-jsonrpc');
mathjax.init({
loader: {
load: ['input/asciimath', 'input/tex', 'output/svg'],
source: require('mathjax-full/components/src/source.js').source
},
svg: {
scale: 2,
minScale: 1.5,
exFactor: 2
}
}).then((MathJax) => {
let connection = rpc.createMessageConnection(
new rpc.StreamMessageReader(process.stdin),
new rpc.StreamMessageWriter(process.stdout));
connection.onRequest(new rpc.RequestType('asciimath2svg'), (param) => {
let svg = MathJax.asciimath2svg(param, { display: false });
return MathJax.startup.adaptor.innerHTML(svg);
});
connection.onRequest(new rpc.RequestType('tex2svg'), (param) => {
let svg = MathJax.tex2svg(param, { display: false });
return MathJax.startup.adaptor.innerHTML(svg);
});
connection.listen();
});