Remove Equation References/Numbering, Fix Bugs

Equation References and Numbering are not going to be trivial to add,
so the code has been removed for now.  Important fixes include
no-MathJax support (previously, the code was failing), and the
generation of unique ids for the rendering content in each cell,
tremendously speeding up MathJax rendering.

I am still not rendering placeholder text.
pull/37/head
Aron Ahmadia 14 years ago
parent 12c661f761
commit 4620ce8348

@ -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');

@ -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, "&lt;") // use HTML entity for <
.replace(/>/g, "&gt;") // 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));

@ -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 = $('<div/>').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 class="prettyprint">' + code + '</code>';
});
IPython.mathjaxutils.queue_render()
this.typeset()
}
this.rendered = true;
}

@ -4,7 +4,6 @@
{% if mathjax_url %}
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
TeX: { equationNumbers: { autoNumber: "AMS", useLabelIds: true } },
tex2jax: {
inlineMath: [ ['$','$'], ["\\(","\\)"] ],
displayMath: [ ['$$','$$'], ["\\[","\\]"] ],
@ -17,7 +16,7 @@
});
</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-full" charset="utf-8"></script>
{% end %}
<script type="text/javascript">
// MathJax disabled, set as null to distingish from *missing* MathJax,

@ -162,87 +162,7 @@
"\n",
"---\n",
"\n",
"These equation reference examples are adapted from an [example page in the MathJax documentation](http://cdn.mathjax.org/mathjax/latest/test/sample-eqrefs.html). Note that it's okay to reference equations across cells. Click inside this cell to see the source.\n",
"\n",
"## Labeled equations and references\n",
"\n",
"Here is a labeled equation:\n",
"\\begin{equation}\n",
"x+1\\over\\sqrt{1-x^2}\\label{ref1}\n",
"\\end{equation}\n",
"\n",
"with a reference to ref1: \\ref{ref1},\n",
"and another numbered one with no label:\n",
"\\begin{equation}\n",
"x+1\\over\\sqrt{1-x^2}\n",
"\\end{equation}"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## \\nonumber and equation*\n",
"\n",
"This one uses \\nonumber:\n",
"\\begin{equation}\n",
"x+1\\over\\sqrt{1-x^2}\\nonumber\n",
"\\end{equation}\n",
"\n",
"Here's one with the equation* environment:\n",
"\\begin{equation*}\n",
"x+1\\over\\sqrt{1-x^2}\n",
"\\end{equation*}"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Forward references\n",
"\n",
"This is a forward reference [\\ref{ref2}] and another \\eqref{ref2} for the \n",
"following equation:\n",
"\n",
"\\begin{equation}\n",
"x+1\\over\\sqrt{1-x^2}\\label{ref2}\n",
"\\end{equation}\n",
"\n",
"More math:\n",
"\\begin{equation}\n",
"x+1\\over\\sqrt{1-x^2}\n",
"\\end{equation}"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### References inline and in environments\n",
"\n",
"Here is a ref inside math: $\\ref{ref2}+1$ and text after it.\n",
"\n",
"\\begin{align} \n",
"x& = y_1-y_2+y_3-y_5+y_8-\\dots \n",
"&& \\text{by \\eqref{ref1}}\\\\ \n",
"& = y'\\circ y^* && \\text{(by \\eqref{ref3})}\\\\ \n",
"& = y(0) y' && \\text {by Axiom 1.} \n",
"\\end{align} \n",
"\n",
"### Missing references\n",
"Here's a bad ref [\\ref{ref4}] to a nonexistent label.\n",
"\n",
"### Numbering align environments\n",
"An alignment:\n",
"\\begin{align}\n",
"a&=b\\label{ref3}\\cr\n",
"&=c+d\n",
"\\end{align}\n",
"and a starred one:\n",
"\\begin{align*}\n",
"a&=b\\cr\n",
"&=c+d\n",
"\\end{align*}"
"Equation numbering and referencing will be available in a future version of IPython."
]
},
{

Loading…
Cancel
Save