forked from wei2912/obsidian-latex
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.ts
39 lines (31 loc) · 1013 Bytes
/
main.ts
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
import { loadMathJax, Plugin } from 'obsidian';
const DEFAULT_PREAMBLE_PATH = "preamble.sty";
export default class JaxPlugin extends Plugin {
async read_preamble () {
return await this.app.vault.adapter.read(DEFAULT_PREAMBLE_PATH);
}
async onload() {
// Load MathJax so that we can modify it
// Otherwise, it would not be loaded when this plugin is loaded
await loadMathJax();
if (!MathJax) {
console.warn("MathJax was not defined despite loading it.");
return;
}
// Read the preamble out from the file
let preamble = await this.read_preamble();
if (MathJax.tex2chtml == undefined) {
MathJax.startup.ready = () => {
MathJax.startup.defaultReady();
MathJax.tex2chtml(preamble);
};
} else {
MathJax.tex2chtml(preamble);
}
// TODO: Refresh view?
}
onunload() {
// TODO: Is it possible to remove our definitions?
console.log('Unloading Extended MathJax');
}
}