diff --git a/IPython/html/static/base/js/utils.js b/IPython/html/static/base/js/utils.js
index ce4ed4b6e..10dfdd7ae 100644
--- a/IPython/html/static/base/js/utils.js
+++ b/IPython/html/static/base/js/utils.js
@@ -766,6 +766,33 @@ define([
};
};
+ var typeset = function(element, text) {
+ /**
+ * Apply MathJax rendering to an element, and optionally set its text
+ *
+ * If MathJax is not available, make no changes.
+ *
+ * Returns the output any number of typeset elements, or undefined if
+ * MathJax was not available.
+ *
+ * Parameters
+ * ----------
+ * element: Node, NodeList, or jQuery selection
+ * text: option string
+ */
+ if(!window.MathJax){
+ return;
+ }
+ var $el = element.jquery ? element : $(element);
+ if(arguments.length > 1){
+ $el.text(text);
+ }
+ return $el.map(function(){
+ // MathJax takes a DOM node: $.map makes `this` the context
+ return MathJax.Hub.Queue(["Typeset", MathJax.Hub, this]);
+ });
+ };
+
var utils = {
regex_split : regex_split,
uuid : uuid,
@@ -799,6 +826,7 @@ define([
load_class: load_class,
resolve_promises_dict: resolve_promises_dict,
reject: reject,
+ typeset: typeset,
};
// Backwards compatability.
diff --git a/IPython/html/static/notebook/js/cell.js b/IPython/html/static/notebook/js/cell.js
index b122c2aa3..9c1daa8d2 100644
--- a/IPython/html/static/notebook/js/cell.js
+++ b/IPython/html/static/notebook/js/cell.js
@@ -220,10 +220,7 @@ define([
* @method typeset
*/
Cell.prototype.typeset = function () {
- if (window.MathJax) {
- var cell_math = this.element.get(0);
- MathJax.Hub.Queue(["Typeset", MathJax.Hub, cell_math]);
- }
+ utils.typeset(this.element);
};
/**
diff --git a/IPython/html/static/notebook/js/outputarea.js b/IPython/html/static/notebook/js/outputarea.js
index bb9b21808..4275d0245 100644
--- a/IPython/html/static/notebook/js/outputarea.js
+++ b/IPython/html/static/notebook/js/outputarea.js
@@ -199,9 +199,7 @@ define([
// typeset with MathJax if MathJax is available
OutputArea.prototype.typeset = function () {
- if (window.MathJax){
- MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
- }
+ utils.typeset(this.element);
};
diff --git a/IPython/html/static/widgets/js/widget.js b/IPython/html/static/widgets/js/widget.js
index 243134823..fb3f150cf 100644
--- a/IPython/html/static/widgets/js/widget.js
+++ b/IPython/html/static/widgets/js/widget.js
@@ -387,7 +387,7 @@ define(["widgets/js/manager",
} else {
this.on('displayed', callback, context);
}
- },
+ }
});
@@ -574,6 +574,10 @@ define(["widgets/js/manager",
}
return elements;
},
+
+ typeset: function(element, text){
+ utils.typeset.apply(null, arguments);
+ },
});
diff --git a/IPython/html/static/widgets/js/widget_bool.js b/IPython/html/static/widgets/js/widget_bool.js
index 6fea2cdc7..9b8411814 100644
--- a/IPython/html/static/widgets/js/widget_bool.js
+++ b/IPython/html/static/widgets/js/widget_bool.js
@@ -62,8 +62,7 @@ define([
if (description.trim().length === 0) {
this.$label.hide();
} else {
- this.$label.text(description);
- MathJax.Hub.Queue(["Typeset",MathJax.Hub,this.$label.get(0)]);
+ this.typeset(this.$label, description);
this.$label.show();
}
}
diff --git a/IPython/html/static/widgets/js/widget_box.js b/IPython/html/static/widgets/js/widget_box.js
index 317bea425..e7850ce20 100644
--- a/IPython/html/static/widgets/js/widget_box.js
+++ b/IPython/html/static/widgets/js/widget_box.js
@@ -319,8 +319,7 @@ define([
if (description.trim().length === 0) {
this.$title.html(" "); // Preserve title height
} else {
- this.$title.text(description);
- MathJax.Hub.Queue(["Typeset",MathJax.Hub,this.$title.get(0)]);
+ this.typeset(this.$title, description);
}
var button_text = this.model.get('button_text');
diff --git a/IPython/html/static/widgets/js/widget_int.js b/IPython/html/static/widgets/js/widget_int.js
index 1c08f26d2..4b1070593 100644
--- a/IPython/html/static/widgets/js/widget_int.js
+++ b/IPython/html/static/widgets/js/widget_int.js
@@ -155,8 +155,7 @@ define([
if (description.length === 0) {
this.$label.hide();
} else {
- this.$label.text(description);
- MathJax.Hub.Queue(["Typeset",MathJax.Hub,this.$label.get(0)]);
+ this.typeset(this.$label, description);
this.$label.show();
}
@@ -323,8 +322,7 @@ define([
if (description.length === 0) {
this.$label.hide();
} else {
- this.$label.text(description);
- MathJax.Hub.Queue(["Typeset",MathJax.Hub,this.$label.get(0)]);
+ this.typeset(this.$label, description);
this.$label.show();
}
}
@@ -443,8 +441,7 @@ define([
if (description.length === 0) {
this.$label.hide();
} else {
- this.$label.text(description);
- MathJax.Hub.Queue(["Typeset",MathJax.Hub,this.$label.get(0)]);
+ this.typeset(this.$label, description);
this.$label.show();
}
return ProgressView.__super__.update.apply(this);
diff --git a/IPython/html/static/widgets/js/widget_selection.js b/IPython/html/static/widgets/js/widget_selection.js
index b33e2eb93..52742ae00 100644
--- a/IPython/html/static/widgets/js/widget_selection.js
+++ b/IPython/html/static/widgets/js/widget_selection.js
@@ -97,8 +97,7 @@ define([
if (description.length === 0) {
this.$label.hide();
} else {
- this.$label.text(description);
- MathJax.Hub.Queue(["Typeset",MathJax.Hub,this.$label.get(0)]);
+ this.typeset(this.$label, description);
this.$label.show();
}
}
@@ -231,7 +230,7 @@ define([
this.$label.hide();
} else {
this.$label.text(description);
- MathJax.Hub.Queue(["Typeset",MathJax.Hub,this.$label.get(0)]);
+ this.typeset(this.$label, description);
this.$label.show();
}
}
@@ -345,8 +344,8 @@ define([
if (description.length === 0) {
this.$label.hide();
} else {
- this.$label.text(description);
- MathJax.Hub.Queue(["Typeset",MathJax.Hub,this.$label.get(0)]);
+ this.$label.text();
+ this.typeset(this.$label, description);
this.$label.show();
}
}
@@ -468,8 +467,7 @@ define([
if (description.length === 0) {
this.$label.hide();
} else {
- this.$label.text(description);
- MathJax.Hub.Queue(["Typeset",MathJax.Hub,this.$label.get(0)]);
+ this.typeset(this.$label, description);
this.$label.show();
}
}
diff --git a/IPython/html/static/widgets/js/widget_string.js b/IPython/html/static/widgets/js/widget_string.js
index bd896a95b..eb1d783fb 100644
--- a/IPython/html/static/widgets/js/widget_string.js
+++ b/IPython/html/static/widgets/js/widget_string.js
@@ -43,9 +43,7 @@ define([
* Called when the model is changed. The model may have been
* changed by another view or by a state update from the back-end.
*/
- this.$el.text(this.model.get('value'));
- MathJax.Hub.Queue(["Typeset",MathJax.Hub,this.$el.get(0)]);
-
+ this.typeset(this.$el, this.model.get('value'));
return LatexView.__super__.update.apply(this);
},
});
@@ -116,8 +114,7 @@ define([
if (description.length === 0) {
this.$label.hide();
} else {
- this.$label.text(description);
- MathJax.Hub.Queue(["Typeset",MathJax.Hub,this.$label.get(0)]);
+ this.typeset(this.$label, description);
this.$label.show();
}
}
@@ -200,8 +197,7 @@ define([
if (description.length === 0) {
this.$label.hide();
} else {
- this.$label.text(description);
- MathJax.Hub.Queue(["Typeset",MathJax.Hub,this.$label.get(0)]);
+ this.typeset(this.$label, description);
this.$label.show();
}
}