diff --git a/IPython/frontend/html/notebook/static/js/cell.js b/IPython/frontend/html/notebook/static/js/cell.js index 6afc852..be63097 100644 --- a/IPython/frontend/html/notebook/static/js/cell.js +++ b/IPython/frontend/html/notebook/static/js/cell.js @@ -50,8 +50,11 @@ var IPython = (function (IPython) { }); }; - // prototype typeset method does nothing, see TextCell typeset Cell.prototype.typeset = function () { + if (window.MathJax){ + var cell_math = this.element.get(0); + MathJax.Hub.Queue(["Typeset",MathJax.Hub,cell_math]); + } }; Cell.prototype.select = function () { diff --git a/IPython/frontend/html/notebook/static/js/mathjaxutils.js b/IPython/frontend/html/notebook/static/js/mathjaxutils.js index 9102616..7c7cb1a 100644 --- a/IPython/frontend/html/notebook/static/js/mathjaxutils.js +++ b/IPython/frontend/html/notebook/static/js/mathjaxutils.js @@ -16,6 +16,18 @@ IPython.mathjaxutils = (function (IPython) { var init = function () { if (window.MathJax) { // MathJax loaded + MathJax.Hub.Config({ + tex2jax: { + inlineMath: [ ['$','$'], ["\\(","\\)"] ], + displayMath: [ ['$$','$$'], ["\\[","\\]"] ], + processEnvironments: true + }, + displayAlign: 'left', // Change this to 'center' to center equations. + "HTML-CSS": { + styles: {'.MathJax_Display': {"margin": 0}} + } + }); + MathJax.Hub.Configured(); } else if (window.mathjax_url != "") { // Don't have MathJax, but should. Show dialog. var dialog = $('
') @@ -89,12 +101,12 @@ 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 hub = MathJax.Hub; var block = blocks.slice(i, j + 1).join("").replace(/&/g, "&") // use HTML entity for & .replace(//g, ">") // use HTML entity for > ; - if (HUB.Browser.isMSIE) { + if (hub.Browser.isMSIE) { block = block.replace(/(%[^\n]*)\n/g, "$1
\n") } while (j > i) { diff --git a/IPython/frontend/html/notebook/static/js/textcell.js b/IPython/frontend/html/notebook/static/js/textcell.js index e597a91..bab05de 100644 --- a/IPython/frontend/html/notebook/static/js/textcell.js +++ b/IPython/frontend/html/notebook/static/js/textcell.js @@ -40,7 +40,6 @@ var IPython = (function (IPython) { onKeyEvent: $.proxy(this.handle_codemirror_keyevent,this) }); // 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'); cell.append(input_area).append(render_area); @@ -78,13 +77,6 @@ var IPython = (function (IPython) { return false; }; - TextCell.prototype.typeset = function () { - if (window.MathJax){ - var cell_math = this.element.get(0); - MathJax.Hub.Queue(["Typeset",MathJax.Hub,cell_math]); - } - }; - TextCell.prototype.select = function () { IPython.Cell.prototype.select.apply(this); @@ -229,35 +221,33 @@ var IPython = (function (IPython) { if (this.rendered === false) { var text = this.get_text(); if (text === "") { text = this.placeholder; } - else { - text = IPython.mathjaxutils.remove_math(text) - var html = IPython.markdown_converter.makeHtml(text); - html = IPython.mathjaxutils.replace_math(html) - try { - this.set_rendered(html); - } catch (e) { - console.log("Error running Javascript in Markdown:"); - console.log(e); - this.set_rendered($("
").addClass("js-error").html( - "Error rendering Markdown!
" + e.toString()) - ); - } - this.element.find('div.text_cell_input').hide(); - this.element.find("div.text_cell_render").show(); - var code_snippets = this.element.find("pre > code"); - code_snippets.replaceWith(function () { - var code = $(this).html(); - /* Substitute br for newlines and   for spaces - before highlighting, since prettify doesn't - preserve those on all browsers */ - code = code.replace(/(\r\n|\n|\r)/gm, "
"); - code = code.replace(/ /gm, ' '); - code = prettyPrintOne(code); - - return '' + code + ''; - }); - this.typeset() + text = IPython.mathjaxutils.remove_math(text) + var html = IPython.markdown_converter.makeHtml(text); + html = IPython.mathjaxutils.replace_math(html) + try { + this.set_rendered(html); + } catch (e) { + console.log("Error running Javascript in Markdown:"); + console.log(e); + this.set_rendered($("
").addClass("js-error").html( + "Error rendering Markdown!
" + e.toString()) + ); } + this.element.find('div.text_cell_input').hide(); + this.element.find("div.text_cell_render").show(); + var code_snippets = this.element.find("pre > code"); + code_snippets.replaceWith(function () { + var code = $(this).html(); + /* Substitute br for newlines and   for spaces + before highlighting, since prettify doesn't + preserve those on all browsers */ + code = code.replace(/(\r\n|\n|\r)/gm, "
"); + code = code.replace(/ /gm, ' '); + code = prettyPrintOne(code); + + return '' + code + ''; + }); + this.typeset() this.rendered = true; } }; diff --git a/IPython/frontend/html/notebook/templates/notebook.html b/IPython/frontend/html/notebook/templates/notebook.html index bb712c6..1868e72 100644 --- a/IPython/frontend/html/notebook/templates/notebook.html +++ b/IPython/frontend/html/notebook/templates/notebook.html @@ -2,21 +2,7 @@ {% block stylesheet %} {% if mathjax_url %} - - - + {% end %} - - + {% end %}