mirror of
https://github.com/jupyter/notebook.git
synced 2024-12-15 04:00:34 +08:00
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:
parent
eba9044f2e
commit
12c661f761
@ -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;
|
||||||
|
@ -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]
|
||||||
);
|
);
|
||||||
|
@ -221,37 +221,36 @@ 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)
|
||||||
|
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($("<div/>").addClass("js-error").html(
|
||||||
|
"Error rendering Markdown!<br/>" + 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, "<br/>");
|
||||||
|
code = code.replace(/ /gm, ' ');
|
||||||
|
code = prettyPrintOne(code);
|
||||||
|
|
||||||
text = IPython.mathjaxutils.remove_math(text)
|
return '<code class="prettyprint">' + code + '</code>';
|
||||||
var html = IPython.markdown_converter.makeHtml(text);
|
});
|
||||||
html = IPython.mathjaxutils.replace_math(html)
|
|
||||||
|
|
||||||
try {
|
IPython.mathjaxutils.queue_render()
|
||||||
this.set_rendered(html);
|
|
||||||
} catch (e) {
|
|
||||||
console.log("Error running Javascript in Markdown:");
|
|
||||||
console.log(e);
|
|
||||||
this.set_rendered($("<div/>").addClass("js-error").html(
|
|
||||||
"Error rendering Markdown!<br/>" + e.toString())
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
this.typeset()
|
|
||||||
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, "<br/>");
|
|
||||||
code = code.replace(/ /gm, ' ');
|
|
||||||
code = prettyPrintOne(code);
|
|
||||||
|
|
||||||
return '<code class="prettyprint">' + code + '</code>';
|
|
||||||
});
|
|
||||||
|
|
||||||
IPython.mathjaxutils.queue_render()
|
|
||||||
this.rendered = true;
|
this.rendered = true;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -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">
|
||||||
|
@ -331,14 +331,6 @@
|
|||||||
"x=4\n",
|
"x=4\n",
|
||||||
"$$"
|
"$$"
|
||||||
]
|
]
|
||||||
},
|
|
||||||
{
|
|
||||||
"cell_type": "code",
|
|
||||||
"collapsed": false,
|
|
||||||
"input": [],
|
|
||||||
"language": "python",
|
|
||||||
"metadata": {},
|
|
||||||
"outputs": []
|
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"metadata": {}
|
"metadata": {}
|
||||||
|
Loading…
Reference in New Issue
Block a user