Improved MathJax, missing callback workaround

MathJax.InputJax.TeX.resetEquationNumbers is supposed to be available,
but isn't consistently loaded before the notebook fires off its first
re-render request.  The code edits in mathjaxutils.js fix this issue.

Additionally, there was some init code in mathjaxutils.js that has been
properly excised to the html templates.

Removed some orphan rendering code so that all typesetting now goes
through mathjaxutils.js

Finally, removed an extra cell in the demo notebook.
This commit is contained in:
Aron Ahmadia 2012-10-25 21:21:24 +01:00
parent eba9044f2e
commit 12c661f761
5 changed files with 49 additions and 57 deletions

View File

@ -51,14 +51,6 @@ var IPython = (function (IPython) {
}; };
// typeset with MathJax if MathJax is available
Cell.prototype.typeset = function () {
if (window.MathJax){
MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
}
};
Cell.prototype.select = function () { Cell.prototype.select = function () {
this.element.addClass('ui-widget-content ui-corner-all'); this.element.addClass('ui-widget-content ui-corner-all');
this.selected = true; this.selected = true;

View File

@ -16,18 +16,6 @@ IPython.mathjaxutils = (function (IPython) {
var init = function () { var init = function () {
if (window.MathJax) { if (window.MathJax) {
// MathJax loaded // MathJax loaded
MathJax.Hub.Config({
TeX: { equationNumbers: { autoNumber: "AMS", useLabelIds: true } },
tex2jax: {
inlineMath: [ ['$','$'], ["\\(","\\)"] ],
displayMath: [ ['$$','$$'], ["\\[","\\]"] ],
processEnvironments: true
},
displayAlign: 'left', // Change this to 'center' to center equations.
"HTML-CSS": {
styles: {'.MathJax_Display': {"margin": 0}}
}
});
} else if (window.mathjax_url != "") { } else if (window.mathjax_url != "") {
// Don't have MathJax, but should. Show dialog. // Don't have MathJax, but should. Show dialog.
var dialog = $('<div></div>') var dialog = $('<div></div>')
@ -225,8 +213,14 @@ IPython.mathjaxutils = (function (IPython) {
var queue_render = function () { var queue_render = function () {
// see https://groups.google.com/forum/?fromgroups=#!topic/mathjax-users/cpwy5eCH1ZQ // see https://groups.google.com/forum/?fromgroups=#!topic/mathjax-users/cpwy5eCH1ZQ
var jax = MathJax.Hub.getAllJax();
MathJax.Hub.Queue( MathJax.Hub.Queue(
["resetEquationNumbers",MathJax.InputJax.TeX], function () {
if (MathJax.InputJax.TeX.resetEquationNumbers) {
MathJax.InputJax.TeX.resetEquationNumbers();
}
},
["PreProcess",MathJax.Hub], ["PreProcess",MathJax.Hub],
["Reprocess",MathJax.Hub] ["Reprocess",MathJax.Hub]
); );

View File

@ -221,11 +221,10 @@ var IPython = (function (IPython) {
if (this.rendered === false) { if (this.rendered === false) {
var text = this.get_text(); var text = this.get_text();
if (text === "") { text = this.placeholder; } if (text === "") { text = this.placeholder; }
else {
text = IPython.mathjaxutils.remove_math(text) text = IPython.mathjaxutils.remove_math(text)
var html = IPython.markdown_converter.makeHtml(text); var html = IPython.markdown_converter.makeHtml(text);
html = IPython.mathjaxutils.replace_math(html) html = IPython.mathjaxutils.replace_math(html)
try { try {
this.set_rendered(html); this.set_rendered(html);
} catch (e) { } catch (e) {
@ -235,7 +234,6 @@ var IPython = (function (IPython) {
"Error rendering Markdown!<br/>" + e.toString()) "Error rendering Markdown!<br/>" + e.toString())
); );
} }
this.typeset()
this.element.find('div.text_cell_input').hide(); this.element.find('div.text_cell_input').hide();
this.element.find("div.text_cell_render").show(); this.element.find("div.text_cell_render").show();
var code_snippets = this.element.find("pre > code"); var code_snippets = this.element.find("pre > code");
@ -252,6 +250,7 @@ var IPython = (function (IPython) {
}); });
IPython.mathjaxutils.queue_render() IPython.mathjaxutils.queue_render()
}
this.rendered = true; this.rendered = true;
} }
}; };

View File

@ -2,6 +2,21 @@
{% block stylesheet %} {% block stylesheet %}
{% if mathjax_url %} {% if mathjax_url %}
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
TeX: { equationNumbers: { autoNumber: "AMS", useLabelIds: true } },
tex2jax: {
inlineMath: [ ['$','$'], ["\\(","\\)"] ],
displayMath: [ ['$$','$$'], ["\\[","\\]"] ],
processEnvironments: true
},
displayAlign: 'left', // Change this to 'center' to center equations.
"HTML-CSS": {
styles: {'.MathJax_Display': {"margin": 0}}
}
});
</script>
<script type="text/javascript" src="{{mathjax_url}}?config=TeX-AMS_HTML" charset="utf-8"></script> <script type="text/javascript" src="{{mathjax_url}}?config=TeX-AMS_HTML" charset="utf-8"></script>
{% end %} {% end %}
<script type="text/javascript"> <script type="text/javascript">

View File

@ -331,14 +331,6 @@
"x=4\n", "x=4\n",
"$$" "$$"
] ]
},
{
"cell_type": "code",
"collapsed": false,
"input": [],
"language": "python",
"metadata": {},
"outputs": []
} }
], ],
"metadata": {} "metadata": {}