Skip to content

Commit

Permalink
Merge pull request #459 from greole/master
Browse files Browse the repository at this point in the history
enable mathjax equation numbering by default
  • Loading branch information
minrk committed Jul 11, 2015
2 parents a68bf94 + a20d976 commit 8aee4d4
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 24 deletions.
2 changes: 2 additions & 0 deletions nbviewer/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ def main():
define("proxy_port", default="", help="The proxy port.", type=int)
define("providers", default=default_providers, help="Full dotted package(s) that provide `default_handlers`", type=str, multiple=True, group="provider")
define("provider_rewrites", default=default_rewrites, help="Full dotted package(s) that provide `uri_rewrites`", type=str, multiple=True, group="provider")
define("mathjax_url", default="https://cdn.mathjax.org/mathjax/latest/", help="URL base for mathjax package", type=str)
tornado.options.parse_command_line()

# NBConvert config
Expand Down Expand Up @@ -217,6 +218,7 @@ def main():
render_timeout=20,
localfile_path=os.path.abspath(options.localfiles),
fetch_kwargs=fetch_kwargs,
mathjax_url=options.mathjax_url,
)

# handle handlers
Expand Down
1 change: 1 addition & 0 deletions nbviewer/formats.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

from IPython.nbconvert.exporters.export import exporter_map


def default_formats():
"""
Return the currently-implemented formats.
Expand Down
8 changes: 7 additions & 1 deletion nbviewer/providers/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,10 @@ def max_cache_uris(self):
def frontpage_sections(self):
return self.settings.setdefault('frontpage_sections', {})

@property
def mathjax_url(self):
return self.settings['mathjax_url']

#---------------------------------------------------------------
# template rendering
#---------------------------------------------------------------
Expand All @@ -144,7 +148,9 @@ def render_template(self, name, **ns):

@property
def template_namespace(self):
return {}
return {
"mathjax_url": self.mathjax_url
}

def breadcrumbs(self, path, base_url):
"""Generate a list of breadcrumbs"""
Expand Down
54 changes: 31 additions & 23 deletions nbviewer/templates/notebook.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,30 +48,38 @@
<link href="/static/css/theme/{{css_theme}}.css" rel="stylesheet">
{% endif %}

<script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML" type="text/javascript">
</script>
<script type="text/javascript">
init_mathjax = function() {
if (window.MathJax) {
// MathJax loaded
MathJax.Hub.Config({
tex2jax: {
inlineMath: [ ['$','$'], ["\\(","\\)"] ],
displayMath: [ ['$$','$$'], ["\\[","\\]"] ],
processEscapes: true,
processEnvironments: true
},
displayAlign: 'center',
"HTML-CSS": {
styles: {'.MathJax_Display': {"margin": 0}},
linebreaks: { automatic: true }
}
});
MathJax.Hub.Queue(["Typeset", MathJax.Hub]);
{% block mathjax %}
<script src="{{ mathjax_url }}MathJax.js?config=TeX-AMS_HTML" type="text/javascript">
</script>
<script type="text/javascript">
init_mathjax = function() {
if (window.MathJax) {
// MathJax loaded
MathJax.Hub.Config({
TeX: {
equationNumbers: {
autoNumber: "AMS",
useLabelIds: true
}
},
tex2jax: {
inlineMath: [ ['$','$'], ["\\(","\\)"] ],
displayMath: [ ['$$','$$'], ["\\[","\\]"] ],
processEscapes: true,
processEnvironments: true
},
displayAlign: 'center',
"HTML-CSS": {
styles: {'.MathJax_Display': {"margin": 0}},
linebreaks: { automatic: true }
}
});
MathJax.Hub.Queue(["Typeset", MathJax.Hub]);
}
}
}
init_mathjax();
</script>
init_mathjax();
</script>
{% endblock mathjax %}
{% endblock extra_head %}


Expand Down

0 comments on commit 8aee4d4

Please sign in to comment.