diff --git a/IPython/frontend/html/notebook/handlers.py b/IPython/frontend/html/notebook/handlers.py index 02357112edb..242d47beccf 100644 --- a/IPython/frontend/html/notebook/handlers.py +++ b/IPython/frontend/html/notebook/handlers.py @@ -219,7 +219,7 @@ def get(self): base_project_url=u'/', base_kernel_url=u'/', kill_kernel=False, read_only=False, - enable_mathjax=self.application.ipython_app.enable_mathjax, + mathjax_url=self.application.ipython_app.mathjax_url, ) @@ -238,7 +238,7 @@ def get(self, notebook_id): base_project_url=u'/', base_kernel_url=u'/', kill_kernel=False, read_only=self.read_only, - enable_mathjax=self.application.ipython_app.enable_mathjax, + mathjax_url=self.application.ipython_app.mathjax_url, ) diff --git a/IPython/frontend/html/notebook/notebookapp.py b/IPython/frontend/html/notebook/notebookapp.py index f7851963235..d2bdcf6d0cb 100644 --- a/IPython/frontend/html/notebook/notebookapp.py +++ b/IPython/frontend/html/notebook/notebookapp.py @@ -252,6 +252,31 @@ def _ip_changed(self, name, old, new): When disabled, equations etc. will appear as their untransformed TeX source. """ ) + def _enable_mathjax_changed(self, name, old, new): + """set mathjax url to empty if mathjax is disabled""" + if not new: + self.mathjax_url = u'' + + mathjax_url = Unicode("", config=True, + help="""The url for MathJax.js.""" + ) + def _mathjax_url_default(self): + if not self.enable_mathjax: + return u'' + static_path = os.path.join(os.path.dirname(__file__), "static") + if os.path.exists(os.path.join(static_path, 'mathjax', "MathJax.js")): + self.log.info("Using local MathJax") + return u"static/mathjax/MathJax.js" + else: + self.log.info("Using MathJax from CDN") + return u"http://cdn.mathjax.org/mathjax/latest/MathJax.js" + + def _mathjax_url_changed(self, name, old, new): + if new and not self.enable_mathjax: + # enable_mathjax=False overrides mathjax_url + self.mathjax_url = u'' + else: + self.log.info("Using MathJax: %s", new) def parse_command_line(self, argv=None): super(NotebookApp, self).parse_command_line(argv) diff --git a/IPython/frontend/html/notebook/static/js/notebookmain.js b/IPython/frontend/html/notebook/static/js/notebookmain.js index 7d1f49bf466..1d9d041c88f 100644 --- a/IPython/frontend/html/notebook/static/js/notebookmain.js +++ b/IPython/frontend/html/notebook/static/js/notebookmain.js @@ -11,48 +11,8 @@ $(document).ready(function () { - - 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:"+ - "

"+ - "
"+
-            "$ sudo python -c 'from IPython.external import mathjax; mathjax.install_mathjax()'"+
-            "
"+ - "

"+ - "Or you can instruct the notebook server to start without MathJax support, with:"+ - "

"+
-            "

"+ - "$ ipython notebook --no-mathjax"+ - "
"+ - "

"+ - "in which case, equations will not be rendered."+ - "

" - ).dialog({ - title: 'MathJax disabled', - width: "70%", - modal: true, - }) - }else if (window.MathJax){ + if (window.MathJax){ + // MathJax loaded MathJax.Hub.Config({ tex2jax: { inlineMath: [ ['$','$'], ["\\(","\\)"] ], @@ -63,9 +23,49 @@ $(document).ready(function () { styles: {'.MathJax_Display': {"margin": 0}} } }); + }else if (window.mathjax_url != ""){ + // Don't have MathJax, but should. Show dialog. + var dialog = $('
') + .append( + $("

").addClass('dialog').html( + "Math/LaTeX equation rendering will be disabled." + ) + ).append( + $("

").addClass('dialog').html( + "With a working internet connection, you can install a local copy" + + " of MathJax for offline use with the following command at a Python" + + " or IPython prompt:" + ) + ).append( + $("
").addClass('dialog').html(
+                    ">>> from IPython.external import mathjax; mathjax.install_mathjax()"
+                )
+            ).append(
+                $("

").addClass('dialog').html( + "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, via 'sudo'." + ) + ).append( + $("

").addClass('dialog').html( + "Or you can instruct the notebook server to disable MathJax support altogether:" + ) + ).append( + $("
").addClass('dialog').html(
+                    "$ ipython notebook --no-mathjax"
+                )
+            ).append(
+                $("

").addClass('dialog').html( + "which will prevent this dialog from appearing." + ) + ).dialog({ + title: "Failed to retrieve MathJax from '" + window.mathjax_url + "'", + width: "70%", + modal: true, + }) }else{ - // window.MathJax == null - // --no-mathjax mode + // No MathJax, but none expected. No dialog. } IPython.markdown_converter = new Markdown.Converter(); diff --git a/IPython/frontend/html/notebook/templates/notebook.html b/IPython/frontend/html/notebook/templates/notebook.html index 95e4de49552..7049b5c9bca 100644 --- a/IPython/frontend/html/notebook/templates/notebook.html +++ b/IPython/frontend/html/notebook/templates/notebook.html @@ -6,24 +6,14 @@ IPython Notebook - {% if enable_mathjax %} - - - - {% else %} + {% if mathjax_url %} + + {% end %} - {% end %}