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
69import { ILatexTypesetter } from '@jupyterlab/rendermime' ;
710
@@ -24,6 +27,8 @@ import { HTMLHandler } from 'mathjax-full/js/handlers/html/HTMLHandler';
2427
2528import { browserAdaptor } from 'mathjax-full/js/adaptors/browserAdaptor' ;
2629
30+ import 'mathjax-full/js/input/tex/require/RequireConfiguration' ;
31+
2732mathjax . 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 */
3742export 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