File tree Expand file tree Collapse file tree 4 files changed +63
-0
lines changed
src/jupyter_contrib_nbextensions/nbextensions/load_tex_macros Expand file tree Collapse file tree 4 files changed +63
-0
lines changed Original file line number Diff line number Diff line change
1
+ Type : Jupyter Notebook Extension
2
+ Name : Load TeX macros
3
+ Description : This extension automatically loads a set of latex commands from the file latexdefs.tex when a notebook is opened.
4
+ Link : readme.md
5
+ Icon : icon.png
6
+ Main : main.js
7
+ Compatibility : 4.x, 5.x
Original file line number Diff line number Diff line change
1
+ define ( function ( require , exports , module ) {
2
+ var Jupyter = require ( 'base/js/namespace' ) ;
3
+
4
+ function loadLatexUserDefs ( ) {
5
+ $ . get ( 'latexdefs.tex' ) . done ( function ( data ) {
6
+ data = data . replace ( / ^ / gm, '\$\$\$' ) . replace ( / $ / gm, '\$\$\$' ) ;
7
+ if ( $ ( '#latexdefs' ) . length > 0 ) $ ( '#latexdefs' ) . remove ( ) ;
8
+ $ ( 'body' ) . append ( $ ( '<div/>' ) . attr ( 'id' , 'latexdefs' ) . text ( data ) ) ;
9
+ console . log ( 'latex_envs: loaded user LaTeX definitions latexdefs.tex' ) ;
10
+ } ) . fail ( function ( ) {
11
+ console . log ( 'load_tex_macros: failed to load user LaTeX definitions latexdefs.tex' )
12
+ } ) ;
13
+ }
14
+
15
+ function rerenderMaths ( ) { // probably something like that
16
+ MathJax . Hub . Queue (
17
+ [ "resetEquationNumbers" , MathJax . InputJax . TeX ] ,
18
+ [ "PreProcess" , MathJax . Hub ] ,
19
+ [ "Reprocess" , MathJax . Hub ]
20
+ ) ;
21
+ }
22
+
23
+ function load_ipython_extension ( ) {
24
+ "use strict" ;
25
+
26
+ if ( Jupyter . notebook . _fully_loaded ) {
27
+ loadLatexUserDefs ( ) ;
28
+ rerenderMaths ( ) ;
29
+ } else {
30
+ $ ( [ Jupyter . events ] ) . on ( "notebook_loaded.Notebook" , function ( ) {
31
+ loadLatexUserDefs ( ) ;
32
+ rerenderMaths ( ) ;
33
+ } )
34
+ }
35
+ }
36
+ return {
37
+ load_ipython_extension : load_ipython_extension ,
38
+ } ;
39
+ } )
Original file line number Diff line number Diff line change
1
+
2
+ Purpose
3
+ =======
4
+ This extension loads a tex file whenever a notebook is loaded, then re-runs
5
+ mathjax. It's useful if you have several notebooks that use a common set of latex
6
+ macros, so you don't have to copy the macros to each notebook.
7
+
8
+ Usage
9
+ =====
10
+
11
+ Simply put your latex macros in a file named latexdefs.tex, in the same directory as your notebook.
12
+
13
+
14
+ Credit
15
+ ======
16
+
17
+ This is derived entirely from the nbextension ` jupyter_latex_envs ` , with help from its author @jfbercher .
You can’t perform that action at this time.
0 commit comments