diff --git a/IPython/frontend/html/notebook/static/js/cell.js b/IPython/frontend/html/notebook/static/js/cell.js index ade8f9d..6afc852 100644 --- a/IPython/frontend/html/notebook/static/js/cell.js +++ b/IPython/frontend/html/notebook/static/js/cell.js @@ -50,6 +50,9 @@ var IPython = (function (IPython) { }); }; + // prototype typeset method does nothing, see TextCell typeset + Cell.prototype.typeset = function () { + }; Cell.prototype.select = function () { this.element.addClass('ui-widget-content ui-corner-all'); diff --git a/IPython/frontend/html/notebook/static/js/mathjaxutils.js b/IPython/frontend/html/notebook/static/js/mathjaxutils.js index b8df58a..9102616 100644 --- a/IPython/frontend/html/notebook/static/js/mathjaxutils.js +++ b/IPython/frontend/html/notebook/static/js/mathjaxutils.js @@ -14,7 +14,7 @@ IPython.namespace('IPython.mathjaxutils'); IPython.mathjaxutils = (function (IPython) { var init = function () { - if (window.MathJax) { + if (window.MathJax) { // MathJax loaded } else if (window.mathjax_url != "") { // Don't have MathJax, but should. Show dialog. @@ -76,7 +76,6 @@ IPython.mathjaxutils = (function (IPython) { var inline = "$"; // the inline math delimiter var blocks, start, end, last, braces; // used in searching for math var math; // stores math until pagedown (Markdown parser) is done - var HUB = MathJax.Hub; // MATHSPLIT contains the pattern for math delimiters and special symbols // needed for searching for math in the text input. @@ -90,6 +89,7 @@ IPython.mathjaxutils = (function (IPython) { // math, then push the math string onto the storage array. // The preProcess function is called on all blocks if it has been passed in var process_math = function (i, j, pre_process) { + var HUB = MathJax.Hub; var block = blocks.slice(i, j + 1).join("").replace(/&/g, "&") // use HTML entity for & .replace(//g, ">") // use HTML entity for > @@ -115,6 +115,10 @@ IPython.mathjaxutils = (function (IPython) { // (which will be a paragraph). // var remove_math = function (text) { + if (!window.MathJax) { + return text; + } + start = end = last = null; // for tracking math delimiters math = []; // stores math strings for later @@ -204,6 +208,10 @@ IPython.mathjaxutils = (function (IPython) { // and clear the math array (no need to keep it around). // var replace_math = function (text) { + if (!window.MathJax) { + return text; + } + text = text.replace(/@@(\d+)@@/g, function (match, n) { return math[n] }); @@ -211,27 +219,11 @@ IPython.mathjaxutils = (function (IPython) { return text; } - var queue_render = function () { - // see https://groups.google.com/forum/?fromgroups=#!topic/mathjax-users/cpwy5eCH1ZQ - var jax = MathJax.Hub.getAllJax(); - - MathJax.Hub.Queue( - function () { - if (MathJax.InputJax.TeX.resetEquationNumbers) { - MathJax.InputJax.TeX.resetEquationNumbers(); - } - }, - ["PreProcess",MathJax.Hub], - ["Reprocess",MathJax.Hub] - ); - } - return { init : init, process_math : process_math, remove_math : remove_math, - replace_math : replace_math, - queue_render : queue_render + replace_math : replace_math }; }(IPython)); \ No newline at end of file diff --git a/IPython/frontend/html/notebook/static/js/textcell.js b/IPython/frontend/html/notebook/static/js/textcell.js index 809776b..a64480b 100644 --- a/IPython/frontend/html/notebook/static/js/textcell.js +++ b/IPython/frontend/html/notebook/static/js/textcell.js @@ -39,9 +39,11 @@ var IPython = (function (IPython) { extraKeys: {"Tab": "indentMore","Shift-Tab" : "indentLess"}, onKeyEvent: $.proxy(this.handle_codemirror_keyevent,this) }); + this.cell_id = IPython.utils.uuid(); // The tabindex=-1 makes this div focusable. + // id is a unique cell_id necessary for updating MathJax intelligently var render_area = $('
').addClass('text_cell_render border-box-sizing'). - addClass('rendered_html').attr('tabindex','-1'); + addClass('rendered_html').attr('tabindex','-1').attr('id',this.cell_id); cell.append(input_area).append(render_area); this.element = cell; }; @@ -77,6 +79,13 @@ var IPython = (function (IPython) { return false; }; + TextCell.prototype.typeset = function () { + if (window.MathJax){ + var cell_math = document.getElementById(this.cell_id); + MathJax.Hub.Queue(["Typeset",MathJax.Hub,cell_math]); + } + }; + TextCell.prototype.select = function () { IPython.Cell.prototype.select.apply(this); @@ -248,8 +257,7 @@ var IPython = (function (IPython) { return '' + code + ''; }); - - IPython.mathjaxutils.queue_render() + this.typeset() } this.rendered = true; } diff --git a/IPython/frontend/html/notebook/templates/notebook.html b/IPython/frontend/html/notebook/templates/notebook.html index 865e439..bb712c6 100644 --- a/IPython/frontend/html/notebook/templates/notebook.html +++ b/IPython/frontend/html/notebook/templates/notebook.html @@ -4,7 +4,6 @@ {% if mathjax_url %} - + {% end %} - + {% end %}