-
Notifications
You must be signed in to change notification settings - Fork 83
/
Copy pathtex.js
35 lines (30 loc) · 904 Bytes
/
tex.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
import {katex} from "./dependencies.js";
var raw = String.raw;
function style(href) {
return new Promise(function(resolve, reject) {
var link = document.createElement("link");
link.rel = "stylesheet";
link.href = href;
link.onerror = reject;
link.onload = resolve;
document.head.appendChild(link);
});
}
export function tex(require) {
return Promise.all([
require(katex.resolve()),
require.resolve(katex.resolve("dist/katex.min.css")).then(style)
]).then(function(values) {
var katex = values[0], tex = renderer();
function renderer(options) {
return function() {
var root = document.createElement("div");
katex.render(raw.apply(String, arguments), root, options);
return root.removeChild(root.firstChild);
};
}
tex.options = renderer;
tex.block = renderer({displayMode: true});
return tex;
});
}