From ef48cc07cfb8ee707c6ddba14e66391d481275bc 2011-12-01 04:11:37
From: MinRK
Date: 2011-12-01 04:11:37
Subject: [PATCH] allow the notebook to run without MathJax
* add `--no-mathjax` flag for disabling mathjax in the notebook server
* A jQuery dialog with our 'no mathjax' message will appear if mathjax is unavailable, but the notebook will be fully functional after dismissal.
* Various calls to MathJax.Hub.typeset moved to Cell.typeset, which checks for MathJax existence and is a no-op without it.
closes #1071
---
diff --git a/IPython/frontend/html/notebook/handlers.py b/IPython/frontend/html/notebook/handlers.py
index ca92d59..0235711 100644
--- a/IPython/frontend/html/notebook/handlers.py
+++ b/IPython/frontend/html/notebook/handlers.py
@@ -219,6 +219,7 @@ class NewHandler(AuthenticatedHandler):
base_project_url=u'/', base_kernel_url=u'/',
kill_kernel=False,
read_only=False,
+ enable_mathjax=self.application.ipython_app.enable_mathjax,
)
@@ -237,6 +238,7 @@ class NamedNotebookHandler(AuthenticatedHandler):
base_project_url=u'/', base_kernel_url=u'/',
kill_kernel=False,
read_only=self.read_only,
+ enable_mathjax=self.application.ipython_app.enable_mathjax,
)
diff --git a/IPython/frontend/html/notebook/notebookapp.py b/IPython/frontend/html/notebook/notebookapp.py
index 1d17959..f785196 100644
--- a/IPython/frontend/html/notebook/notebookapp.py
+++ b/IPython/frontend/html/notebook/notebookapp.py
@@ -128,6 +128,17 @@ flags['no-browser']=(
{'NotebookApp' : {'open_browser' : False}},
"Don't open the notebook in a browser after startup."
)
+flags['no-mathjax']=(
+ {'NotebookApp' : {'enable_mathjax' : False}},
+ """Disable MathJax
+
+ MathJax is the javascript library IPython uses to render math/LaTeX. It is
+ very large, so you may want to disable it if you have a slow internet
+ connection, or for offline use of the notebook.
+
+ When disabled, equations etc. will appear as their untransformed TeX source.
+ """
+)
flags['read-only'] = (
{'NotebookApp' : {'read_only' : True}},
"""Allow read-only access to notebooks.
@@ -144,7 +155,7 @@ flags['read-only'] = (
# the flags that are specific to the frontend
# these must be scrubbed before being passed to the kernel,
# or it will raise an error on unrecognized flags
-notebook_flags = ['no-browser', 'read-only']
+notebook_flags = ['no-browser', 'no-mathjax', 'read-only']
aliases = dict(ipkernel_aliases)
@@ -230,6 +241,17 @@ class NotebookApp(BaseIPythonApplication):
read_only = Bool(False, config=True,
help="Whether to prevent editing/execution of notebooks."
)
+
+ enable_mathjax = Bool(True, config=True,
+ help="""Whether to enable MathJax for typesetting math/TeX
+
+ MathJax is the javascript library IPython uses to render math/LaTeX. It is
+ very large, so you may want to disable it if you have a slow internet
+ connection, or for offline use of the notebook.
+
+ When disabled, equations etc. will appear as their untransformed TeX source.
+ """
+ )
def parse_command_line(self, argv=None):
super(NotebookApp, self).parse_command_line(argv)
diff --git a/IPython/frontend/html/notebook/static/css/notebook.css b/IPython/frontend/html/notebook/static/css/notebook.css
index 01d376c..2e894cc 100644
--- a/IPython/frontend/html/notebook/static/css/notebook.css
+++ b/IPython/frontend/html/notebook/static/css/notebook.css
@@ -415,6 +415,18 @@ div.text_cell_render {
font-family: monospace;
}
+pre.dialog {
+ background-color: #f7f7f7;
+ border: 1px solid #ddd;
+ border-radius: 3px;
+ padding: 0.4em;
+ padding-left: 2em;
+}
+
+p.dialog{
+ padding : 0.2em;
+}
+
@media print {
body { overflow: visible !important; }
.ui-widget-content { border: 0px; }
diff --git a/IPython/frontend/html/notebook/static/js/cell.js b/IPython/frontend/html/notebook/static/js/cell.js
index 6806dd3..2667ec0 100644
--- a/IPython/frontend/html/notebook/static/js/cell.js
+++ b/IPython/frontend/html/notebook/static/js/cell.js
@@ -88,6 +88,13 @@ var IPython = (function (IPython) {
// Subclasses must implement create_element.
Cell.prototype.create_element = function () {};
+ // typeset with MathJax if MathJax is available
+ Cell.prototype.typeset = function () {
+ if (window.MathJax){
+ MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
+ }
+ };
+
IPython.Cell = Cell;
return IPython;
diff --git a/IPython/frontend/html/notebook/static/js/codecell.js b/IPython/frontend/html/notebook/static/js/codecell.js
index d17bd61..2d6b296 100644
--- a/IPython/frontend/html/notebook/static/js/codecell.js
+++ b/IPython/frontend/html/notebook/static/js/codecell.js
@@ -520,7 +520,7 @@ var IPython = (function (IPython) {
this.element.find('div.output').append(toinsert);
// If we just output latex, typeset it.
if ((json.latex !== undefined) || (json.html !== undefined)) {
- MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
+ this.typeset();
};
};
@@ -572,7 +572,7 @@ var IPython = (function (IPython) {
this.element.find('div.output').append(toinsert);
// If we just output latex, typeset it.
if ( (json.latex !== undefined) || (json.html !== undefined) ) {
- MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
+ this.typeset();
};
};
diff --git a/IPython/frontend/html/notebook/static/js/notebookmain.js b/IPython/frontend/html/notebook/static/js/notebookmain.js
index c3cb70a..7d1f49b 100644
--- a/IPython/frontend/html/notebook/static/js/notebookmain.js
+++ b/IPython/frontend/html/notebook/static/js/notebookmain.js
@@ -12,16 +12,62 @@
$(document).ready(function () {
- MathJax.Hub.Config({
- tex2jax: {
- inlineMath: [ ['$','$'], ["\\(","\\)"] ],
- displayMath: [ ['$$','$$'], ["\\[","\\]"] ]
- },
- displayAlign: 'left', // Change this to 'center' to center equations.
- "HTML-CSS": {
- styles: {'.MathJax_Display': {"margin": 0}}
- }
- });
+ if (window.MathJax == undefined){
+ // MathJax undefined, but expected. Draw warning.
+ window.MathJax = null;
+ var dialog = $('').html(
+ "
"+
+ "We were unable to retrieve MathJax. Math/LaTeX rendering will be disabled."+
+ "
"+
+ "
"+
+ "With a working internet connection, you can run the following at a Python"+
+ " or IPython prompt, which will install a local copy of MathJax:"+
+ "
"+
+ "
"+
+ ">>> from IPython.external import mathjax; mathjax.install_mathjax()"+
+ "
"+
+ "
"+
+ "This will try to install MathJax into the directory where you installed"+
+ " IPython. If you installed IPython to a location that requires"+
+ " administrative privileges to write, you will need to make this call as"+
+ " an administrator."+
+ "
"+
+ "
"+
+ "On OSX/Linux/Unix, this can be done at the command-line via:"+
+ "
There was an issue trying to fetch MathJax.js
- from the internet.
-
-
With a working internet connection, you can run
- the following at a Python or IPython prompt, which will install a local
- copy of MathJax:
-
-
- from IPython.external import mathjax; mathjax.install_mathjax()
-
- This will try to install MathJax into the directory where you installed
- IPython. If you installed IPython to a location that requires
- administrative privileges to write, you will need to make this call as
- an administrator. On OSX/Linux/Unix, this can be done at the
- command-line via:
-