diff --git a/notebook/static/notebook/js/mathjaxutils.js b/notebook/static/notebook/js/mathjaxutils.js
index cfbe266d8a..544766826c 100644
--- a/notebook/static/notebook/js/mathjaxutils.js
+++ b/notebook/static/notebook/js/mathjaxutils.js
@@ -8,10 +8,11 @@ define([
], function($, utils, dialog) {
"use strict";
- var init = function () {
+ var init = function (kernel_info_data) {
if (window.MathJax) {
// MathJax loaded
- MathJax.Hub.Config({
+ var mathjax_config = {
+ config: ['TeX-AMS_HTML-full.js', 'Safe.js'],
tex2jax: {
inlineMath: [ ['$','$'], ["\\(","\\)"] ],
displayMath: [ ['$$','$$'], ["\\[","\\]"] ],
@@ -29,7 +30,38 @@ define([
styles: {'.MathJax_Display': {"margin": 0}},
linebreaks: { automatic: true }
},
- });
+ };
+ if (kernel_info_data && kernel_info_data.content && kernel_info_data.content.mathjax) {
+ // allow Kernel to load extensions like mml2jax.js by letting
+ // MathJax's Ajax loader know the path to the MathJax files
+ MathJax.Ajax.config.root = "/static/components/MathJax";
+
+ function mergeable(x) {
+ return typeof(x) == 'object' && !Array.isArray(x);
+ }
+
+ function merge(into, from) {
+ for (var key in from) {
+ if (from.hasOwnProperty(key)) {
+ if (into.hasOwnProperty(key) &&
+ mergeable(into[key]) && mergeable(from[key])) {
+ merge(into[key], from[key]);
+ } else {
+ into[key] = from[key];
+ }
+ }
+ }
+ }
+
+ if (kernel_info_data.content.mathjax.options) { // e.g. processSectionDelay
+ merge(MathJax.Hub, kernel_info_data.content.mathjax.options);
+ }
+
+ if (kernel_info_data.content.mathjax.config) {
+ merge(mathjax_config, kernel_info_data.content.mathjax.config);
+ }
+ }
+ MathJax.Hub.Config(mathjax_config);
MathJax.Hub.Configured();
} else if (window.mathjax_url !== "") {
// Don't have MathJax, but should. Show dialog.
diff --git a/notebook/static/notebook/js/notebook.js b/notebook/static/notebook/js/notebook.js
index ab420074cb..8d2e1ffcc7 100644
--- a/notebook/static/notebook/js/notebook.js
+++ b/notebook/static/notebook/js/notebook.js
@@ -78,7 +78,12 @@ define(function (require) {
this.keyboard_manager.notebook = this;
this.save_widget.notebook = this;
- mathjaxutils.init();
+ var notebook = this;
+ this.events.on('kernel_connected.Kernel', function () {
+ notebook.kernel.kernel_info(function (data) {
+ mathjaxutils.init(data);
+ });
+ });
if (marked) {
marked.setOptions({
diff --git a/notebook/templates/notebook.html b/notebook/templates/notebook.html
index 879021291b..bdd914830d 100644
--- a/notebook/templates/notebook.html
+++ b/notebook/templates/notebook.html
@@ -3,7 +3,7 @@
{% block stylesheet %}
{% if mathjax_url %}
-
+
{% endif %}