-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathtex2svg-speech.js
More file actions
47 lines (40 loc) · 1.43 KB
/
tex2svg-speech.js
File metadata and controls
47 lines (40 loc) · 1.43 KB
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
import {mathjax} from '../mathjax3/js/mathjax.js';
import '../mathjax3/js/util/asyncLoad/node.js';
import {TeX} from '../mathjax3/js/input/tex.js';
import {MathML} from '../mathjax3/js/input/mathml.js';
import {SVG} from '../mathjax3/js/output/svg.js';
import {RegisterHTMLHandler} from '../mathjax3/js/handlers/html.js';
import {chooseAdaptor} from '../mathjax3/js/adaptors/chooseAdaptor.js';
import {STATE} from '../mathjax3/js/core/MathItem.js';
import {AllPackages} from '../mathjax3/js/input/tex/AllPackages.js';
import {EnrichHandler} from '../mathjax3/js/a11y/semantic-enrich.js';
const adaptor = chooseAdaptor();
EnrichHandler(RegisterHTMLHandler(adaptor), new MathML());
let html = mathjax.document('<html></html>', {
sre: {
speech: 'deep'
},
InputJax: new TeX({packages: ['base']}),
OutputJax: new SVG(),
renderActions: {
removeAttributes:
[
40,
(doc) => {},
(math, doc) => {
math.root.walkTree(node => {
const attributes = node.attributes.getAllAttributes();
for (const name of Object.keys(attributes)) {
if (name !== 'data-semantic-speech' && name.match(/^data-semantic-/)) {
delete attributes[name];
}
}
});
}
]
}
});
mathjax.handleRetriesFor(() => {
let math = html.convert(process.argv[2] || '', {end: STATE.ATTACHSPEECH});
console.log(adaptor.outerHTML(math));
}).catch(err => console.log(err.stack));