Skip to content

Commit f40eb5b

Browse files
authored
Merge pull request #1257 from ketch/load_tex_macros
New extension: load_tex_macros.
2 parents 949e2a6 + 2fe4ebd commit f40eb5b

File tree

4 files changed

+63
-0
lines changed

4 files changed

+63
-0
lines changed
5.6 KB
Loading
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
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
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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+
})
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
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.

0 commit comments

Comments
 (0)