Skip to content

Commit 1ee4bc8

Browse files
committed
New extension: load_tex_macros.
1 parent 949e2a6 commit 1ee4bc8

File tree

4 files changed

+49
-0
lines changed

4 files changed

+49
-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: IPython 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
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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+
onMarkdownCellRendering();
11+
}).fail(function() {
12+
console.log('load_tex_macros: failed to load user LaTeX definitions latexdefs.tex')
13+
});
14+
}
15+
16+
function rerenderMaths() { // probably something like that
17+
MathJax.Hub.Queue(
18+
["PreProcess", MathJax.Hub], ["Reprocess", MathJax.Hub]
19+
);
20+
}
21+
22+
function load_ipython_extension() {
23+
"use strict";
24+
25+
if (Jupyter.notebook._fully_loaded) {
26+
loadLatexUserDefs();
27+
rerenderMaths();
28+
} else {
29+
$([Jupyter.events]).on("notebook_loaded.Notebook", function() {
30+
loadLatexUserDefs();
31+
rerenderMaths();
32+
})
33+
}
34+
}
35+
return {
36+
load_ipython_extension: load_ipython_extension,
37+
};
38+
})
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Usage
2+
=====
3+
4+
Simply put your latex macros in a file named latexdefs.tex, in the same directory as your notebook.

0 commit comments

Comments
 (0)