Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 35 additions & 3 deletions notebook/static/notebook/js/mathjaxutils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: [ ['$$','$$'], ["\\[","\\]"] ],
Expand All @@ -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.
Expand Down
7 changes: 6 additions & 1 deletion notebook/static/notebook/js/notebook.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
2 changes: 1 addition & 1 deletion notebook/templates/notebook.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{% block stylesheet %}

{% if mathjax_url %}
<script type="text/javascript" src="{{mathjax_url}}?config=TeX-AMS_HTML-full,Safe&delayStartupUntil=configured" charset="utf-8"></script>
<script type="text/javascript" src="{{mathjax_url}}?delayStartupUntil=configured" charset="utf-8"></script>
{% endif %}
<script type="text/javascript">
// MathJax disabled, set as null to distingish from *missing* MathJax,
Expand Down
2 changes: 2 additions & 0 deletions setupbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ def find_package_data():
static_data.extend([
mj('MathJax.js'),
mj('config', 'TeX-AMS_HTML-full.js'),
mj('config', 'MML_HTMLorMML-full.js'),
mj('config', 'Safe.js'),
])

Expand All @@ -176,6 +177,7 @@ def find_package_data():
mj('fonts', 'HTML-CSS', 'STIX-Web', 'woff'),
mj('extensions'),
mj('jax', 'input', 'TeX'),
mj('jax', 'input', 'MathML'),
mj('jax', 'output', 'HTML-CSS', 'fonts', 'STIX-Web'),
mj('jax', 'output', 'SVG', 'fonts', 'STIX-Web'),
]:
Expand Down