Skip to content

Commit

Permalink
adjust missing mathjax handling per review
Browse files Browse the repository at this point in the history
* use jQuery syntax to construct dialog
* server determines where MathJax comes from via mathjax_url configurable (default local/CDN priority unchanged)
  • Loading branch information
minrk committed Dec 1, 2011
1 parent ef48cc0 commit e211da8
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 60 deletions.
4 changes: 2 additions & 2 deletions IPython/frontend/html/notebook/handlers.py
Expand Up @@ -219,7 +219,7 @@ def get(self):
base_project_url=u'/', base_kernel_url=u'/', base_project_url=u'/', base_kernel_url=u'/',
kill_kernel=False, kill_kernel=False,
read_only=False, read_only=False,
enable_mathjax=self.application.ipython_app.enable_mathjax, mathjax_url=self.application.ipython_app.mathjax_url,
) )




Expand All @@ -238,7 +238,7 @@ def get(self, notebook_id):
base_project_url=u'/', base_kernel_url=u'/', base_project_url=u'/', base_kernel_url=u'/',
kill_kernel=False, kill_kernel=False,
read_only=self.read_only, read_only=self.read_only,
enable_mathjax=self.application.ipython_app.enable_mathjax, mathjax_url=self.application.ipython_app.mathjax_url,
) )




Expand Down
25 changes: 25 additions & 0 deletions IPython/frontend/html/notebook/notebookapp.py
Expand Up @@ -252,6 +252,31 @@ def _ip_changed(self, name, old, new):
When disabled, equations etc. will appear as their untransformed TeX source. 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): def parse_command_line(self, argv=None):
super(NotebookApp, self).parse_command_line(argv) super(NotebookApp, self).parse_command_line(argv)
Expand Down
88 changes: 44 additions & 44 deletions IPython/frontend/html/notebook/static/js/notebookmain.js
Expand Up @@ -11,48 +11,8 @@




$(document).ready(function () { $(document).ready(function () {

if (window.MathJax){
if (window.MathJax == undefined){ // MathJax loaded
// MathJax undefined, but expected. Draw warning.
window.MathJax = null;
var dialog = $('<div></div>').html(
"<p class='dialog'>"+
"We were unable to retrieve MathJax. Math/LaTeX rendering will be disabled."+
"</p>"+
"<p class='dialog'>"+
"With a working internet connection, you can run the following at a Python"+
" or IPython prompt, which will install a local copy of MathJax:"+
"</p>"+
"<pre class='dialog'>"+
">>> from IPython.external import mathjax; mathjax.install_mathjax()"+
"</pre>"+
"<p class='dialog'>"+
"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."+
"</p>"+
"<p class='dialog'>"+
"On OSX/Linux/Unix, this can be done at the command-line via:"+
"</p>"+
"<pre class='dialog'>"+
"$ sudo python -c 'from IPython.external import mathjax; mathjax.install_mathjax()'"+
"</pre>"+
"<p class='dialog'>"+
"Or you can instruct the notebook server to start without MathJax support, with:"+
"<pre class='dialog'>"+
"</p>"+
"$ ipython notebook --no-mathjax"+
"</pre>"+
"<p class='dialog'>"+
"in which case, equations will not be rendered."+
"</p>"
).dialog({
title: 'MathJax disabled',
width: "70%",
modal: true,
})
}else if (window.MathJax){
MathJax.Hub.Config({ MathJax.Hub.Config({
tex2jax: { tex2jax: {
inlineMath: [ ['$','$'], ["\\(","\\)"] ], inlineMath: [ ['$','$'], ["\\(","\\)"] ],
Expand All @@ -63,9 +23,49 @@ $(document).ready(function () {
styles: {'.MathJax_Display': {"margin": 0}} styles: {'.MathJax_Display': {"margin": 0}}
} }
}); });
}else if (window.mathjax_url != ""){
// Don't have MathJax, but should. Show dialog.
var dialog = $('<div></div>')
.append(
$("<p></p>").addClass('dialog').html(
"Math/LaTeX equation rendering will be disabled."
)
).append(
$("<p></p>").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(
$("<pre></pre>").addClass('dialog').html(
">>> from IPython.external import mathjax; mathjax.install_mathjax()"
)
).append(
$("<p></p>").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(
$("<p></p>").addClass('dialog').html(
"Or you can instruct the notebook server to disable MathJax support altogether:"
)
).append(
$("<pre></pre>").addClass('dialog').html(
"$ ipython notebook --no-mathjax"
)
).append(
$("<p></p>").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{ }else{
// window.MathJax == null // No MathJax, but none expected. No dialog.
// --no-mathjax mode
} }


IPython.markdown_converter = new Markdown.Converter(); IPython.markdown_converter = new Markdown.Converter();
Expand Down
18 changes: 4 additions & 14 deletions IPython/frontend/html/notebook/templates/notebook.html
Expand Up @@ -6,24 +6,14 @@


<title>IPython Notebook</title> <title>IPython Notebook</title>


{% if enable_mathjax %} {% if mathjax_url %}
<!-- <script type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML" charset="utf-8"></script> --> <script type="text/javascript" src="{{mathjax_url}}?config=TeX-AMS_HTML" charset="utf-8"></script>
<script type='text/javascript' src='static/mathjax/MathJax.js?config=TeX-AMS_HTML' charset='utf-8'></script> {% end %}
<script type="text/javascript">
if (typeof(MathJax) == 'undefined') {
console.log("No local MathJax, loading from CDN");
document.write(unescape("%3Cscript type='text/javascript' src='http://cdn.mathjax.org/mathjax/latest/MathJax.js%3Fconfig=TeX-AMS_HTML' charset='utf-8'%3E%3C/script%3E"));
}else{
console.log("Using local MathJax");
}
</script>
{% else %}
<script type="text/javascript"> <script type="text/javascript">
// MathJax disabled, set as null to distingish from *missing* MathJax, // MathJax disabled, set as null to distingish from *missing* MathJax,
// where it will be undefined, and should prompt a dialog later. // where it will be undefined, and should prompt a dialog later.
window.MathJax = null; window.mathjax_url = "{{mathjax_url}}";
</script> </script>
{% end %}


<link rel="stylesheet" href="static/jquery/css/themes/aristo/jquery-wijmo.css" type="text/css" /> <link rel="stylesheet" href="static/jquery/css/themes/aristo/jquery-wijmo.css" type="text/css" />
<link rel="stylesheet" href="static/codemirror/lib/codemirror.css"> <link rel="stylesheet" href="static/codemirror/lib/codemirror.css">
Expand Down

0 comments on commit e211da8

Please sign in to comment.