adjust missing mathjax handling per review

* use jQuery syntax to construct dialog
* server determines where MathJax comes from via mathjax_url configurable (default local/CDN priority unchanged)
This commit is contained in:
MinRK 2011-12-01 15:59:02 -08:00
parent 36024bcf83
commit 72fb49b7c7
4 changed files with 75 additions and 60 deletions

View File

@ -219,7 +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,
mathjax_url=self.application.ipython_app.mathjax_url,
)
@ -238,7 +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,
mathjax_url=self.application.ipython_app.mathjax_url,
)

View File

@ -252,6 +252,31 @@ class NotebookApp(BaseIPythonApplication):
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)

View File

@ -11,48 +11,8 @@
$(document).ready(function () {
if (window.MathJax == undefined){
// 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){
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 = $('<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{
// window.MathJax == null
// --no-mathjax mode
// No MathJax, but none expected. No dialog.
}
IPython.markdown_converter = new Markdown.Converter();

View File

@ -6,24 +6,14 @@
<title>IPython Notebook</title>
{% if enable_mathjax %}
<!-- <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='static/mathjax/MathJax.js?config=TeX-AMS_HTML' charset='utf-8'></script>
<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 %}
{% if mathjax_url %}
<script type="text/javascript" src="{{mathjax_url}}?config=TeX-AMS_HTML" charset="utf-8"></script>
{% end %}
<script type="text/javascript">
// MathJax disabled, set as null to distingish from *missing* MathJax,
// where it will be undefined, and should prompt a dialog later.
window.MathJax = null;
window.mathjax_url = "{{mathjax_url}}";
</script>
{% end %}
<link rel="stylesheet" href="static/jquery/css/themes/aristo/jquery-wijmo.css" type="text/css" />
<link rel="stylesheet" href="static/codemirror/lib/codemirror.css">