diff --git a/IPython/html/static/base/js/utils.js b/IPython/html/static/base/js/utils.js
index ce4ed4b..10dfdd7 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 b122c2a..9c1daa8 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 bb9b218..4275d02 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 6b966de..84d8bef 100644
--- a/IPython/html/static/widgets/js/widget.js
+++ b/IPython/html/static/widgets/js/widget.js
@@ -577,19 +577,7 @@ define(["widgets/js/manager",
},
typeset: function(element, text){
- // after (optionally) updating a node(list) or jQuery selection's
- // text, check if MathJax is available and typeset it
- var $el = element.jquery ? element : $(element);
-
- if(arguments.length > 1){
- $el.text(text);
- }
- if(!window.MathJax){
- return;
- }
- return $el.map(function(){
- return MathJax.Hub.Queue(["Typeset", MathJax.Hub, this]);
- });
+ utils.typeset.apply(null, arguments);
},
});