forked from jupyterlab/jupyter-renderers
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
68 lines (55 loc) · 1.55 KB
/
index.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// Copyright (c) Jupyter Development Team.
// Distributed under the terms of the Modified BSD License.
import {
JupyterLab, JupyterLabPlugin
} from '@jupyterlab/application';
import {
IRenderMime
} from '@jupyterlab/rendermime-interfaces';
import '../style/index.css';
// the MathJax core
import {MathJax} from "mathjax3/mathjax3/mathjax.js";
// TeX input
import {TeX} from 'mathjax3/mathjax3/input/tex.js';
// HTML output
import {CHTML} from "mathjax3/mathjax3/output/chtml.js";
// handler for HTML documents
import {HTMLHandler} from "mathjax3/mathjax3/handlers/html/HTMLHandler.js";
MathJax.handlers.register(new HTMLHandler());
/**
* The MathJax 3 Typesetter.
*/
export
class MathJax3Typesetter implements IRenderMime.ILatexTypesetter {
constructor() {
// initialize mathjax with with a DOM document (e.g., browser, jsdom); other documents are possible
this._html = MathJax.document(window.document, {
InputJax: new TeX({inlineMath: [['$', '$'], ['\\(', '\\)'] ]}),
OutputJax: new CHTML()
});
}
/**
* Typeset the math in a node.
*/
typeset(node: HTMLElement): void {
this._html.findMath()
.compile()
.getMetrics()
.typeset()
.updateDocument();
}
private _html: any;
}
/**
* The MathJax 3 extension.
*/
const mathJax3Plugin: JupyterLabPlugin<void> = {
id: 'jupyter.extensions.mathjax3',
requires: [],
activate: (app: JupyterLab) => {
const typesetter = new MathJax3Typesetter();
app.rendermime.latexTypesetter = typesetter;
},
autoStart: true
}
export default mathJax3Plugin;