Skip to content

Commit cfc0c73

Browse files
authored
Merge pull request #282 from bsdz/master
Refresh mathjax and add require package
2 parents 54a96c8 + 22465b0 commit cfc0c73

File tree

4 files changed

+626
-31
lines changed

4 files changed

+626
-31
lines changed

packages/mathjax3-extension/package.json

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@
3030
"lib/*.d.ts",
3131
"lib/*.js",
3232
"style/*.css",
33-
"style/index.js"
33+
"style/index.js",
34+
"schema/**/*.json"
3435
],
3536
"scripts": {
3637
"build": "jlpm run build:lib && jlpm run build:labextension:dev",
@@ -53,9 +54,9 @@
5354
"watch:src": "tsc -w"
5455
},
5556
"dependencies": {
56-
"@jupyterlab/application": "^3.2.8",
57-
"@jupyterlab/rendermime": "^3.2.8",
58-
"mathjax-full": "^3.1.2"
57+
"@jupyterlab/application": "^3.4.5",
58+
"@jupyterlab/rendermime": "^3.4.5",
59+
"mathjax-full": "^3.2.2"
5960
},
6061
"devDependencies": {
6162
"@jupyterlab/builder": "^3.2.8",
@@ -68,7 +69,8 @@
6869
"outputDir": "jupyterlab-mathjax3/labextension",
6970
"disabledExtensions": [
7071
"@jupyterlab/mathjax2-extension:plugin"
71-
]
72+
],
73+
"schemaDir": "schema"
7274
},
7375
"styleModule": "style/index.js"
7476
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{
2+
"title": "MathJax 3 Plugin",
3+
"description": "MathJax 3 math renderer for JupyterLab",
4+
"jupyter.lab.menus": {
5+
"context": [
6+
{
7+
"type": "separator",
8+
"selector": ".jp-Notebook .jp-Cell",
9+
"rank": 12
10+
},
11+
{
12+
"command": "mathjax:clipboard",
13+
"selector": ".MathJax",
14+
"rank": 13
15+
},
16+
{
17+
"command": "mathjax:scale",
18+
"selector": ".MathJax",
19+
"rank": 13
20+
},
21+
{
22+
"command": "mathjax:scale",
23+
"selector": ".MathJax",
24+
"rank": 13,
25+
"args": {
26+
"scale": 1.5
27+
}
28+
},
29+
{
30+
"type": "separator",
31+
"selector": ".jp-Notebook .jp-Cell",
32+
"rank": 13
33+
}
34+
]
35+
},
36+
"additionalProperties": false,
37+
"type": "object"
38+
}

packages/mathjax3-extension/src/index.ts

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
// Copyright (c) Jupyter Development Team.
22
// Distributed under the terms of the Modified BSD License.
33

4-
import { JupyterFrontEndPlugin } from '@jupyterlab/application';
4+
import {
5+
JupyterFrontEndPlugin,
6+
JupyterFrontEnd,
7+
} from '@jupyterlab/application';
58

69
import { ILatexTypesetter } from '@jupyterlab/rendermime';
710

@@ -24,6 +27,8 @@ import { HTMLHandler } from 'mathjax-full/js/handlers/html/HTMLHandler';
2427

2528
import { browserAdaptor } from 'mathjax-full/js/adaptors/browserAdaptor';
2629

30+
import 'mathjax-full/js/input/tex/require/RequireConfiguration';
31+
2732
mathjax.handlers.register(SafeHandler(new HTMLHandler(browserAdaptor())));
2833

2934
// Override dynamically generated fonts in favor
@@ -35,12 +40,12 @@ class emptyFont extends TeXFont {}
3540
* The MathJax 3 Typesetter.
3641
*/
3742
export class MathJax3Typesetter implements ILatexTypesetter {
38-
constructor() {
43+
constructor(app: JupyterFrontEnd) {
3944
const chtml = new CHTML({
4045
font: new emptyFont(),
4146
});
4247
const tex = new TeX({
43-
packages: AllPackages,
48+
packages: AllPackages.concat('require'),
4449
inlineMath: [
4550
['$', '$'],
4651
['\\(', '\\)'],
@@ -56,6 +61,29 @@ export class MathJax3Typesetter implements ILatexTypesetter {
5661
InputJax: tex,
5762
OutputJax: chtml,
5863
});
64+
65+
const mjclipboard = 'mathjax:clipboard';
66+
const mjscale = 'mathjax:scale';
67+
68+
app.commands.addCommand(mjclipboard, {
69+
execute: (args: any) => {
70+
const md = this._mathDocument;
71+
const oJax: any = md.outputJax;
72+
navigator.clipboard.writeText(oJax.math.math);
73+
},
74+
label: 'MathJax Copy Latex',
75+
});
76+
77+
app.commands.addCommand(mjscale, {
78+
execute: (args: any) => {
79+
const scale = args['scale'] || 1.0;
80+
const md = this._mathDocument;
81+
md.outputJax.options.scale = scale;
82+
md.rerender();
83+
},
84+
label: (args) =>
85+
'Mathjax Scale ' + (args['scale'] ? `x${args['scale']}` : 'Reset'),
86+
});
5987
}
6088

6189
/**
@@ -77,7 +105,7 @@ const mathJax3Plugin: JupyterFrontEndPlugin<ILatexTypesetter> = {
77105
id: '@jupyterlab/mathjax3-extension:plugin',
78106
requires: [],
79107
provides: ILatexTypesetter,
80-
activate: () => new MathJax3Typesetter(),
108+
activate: (app: JupyterFrontEnd) => new MathJax3Typesetter(app),
81109
autoStart: true,
82110
};
83111

0 commit comments

Comments
 (0)