Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #2045 from getnikola/katex
Add a USE_KATEX option
  • Loading branch information
ralsina committed Sep 10, 2015
2 parents 9450426 + b737378 commit acf5fb7
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 12 deletions.
1 change: 1 addition & 0 deletions CHANGES.txt
Expand Up @@ -4,6 +4,7 @@ New in master
Features
--------

* New option USE_KATEX to switch from MathJax to KaTeX (Experimental).
* Support SVG in galleries (Issue #1605)
* Allow inheriting templates with theme name (Issue #1814)
* Made TAG_PATH translatable (Issue #1914)
Expand Down
7 changes: 7 additions & 0 deletions nikola/conf.py.in
Expand Up @@ -829,6 +829,13 @@ PRETTY_URLS = ${PRETTY_URLS}
# </script>
# """

# Want to use KaTeX instead of MathJax? While KaTeX is less featureful,
# it's faster and the output looks better.
# If you set USE_KATEX to True, you also need to add an extra CSS file
# like this:
# EXTRA_HEAD_DATA = """<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/KaTeX/0.3.0/katex.min.css">"""
# USE_KATEX = False

# Do you want to customize the nbconversion of your IPython notebook?
# IPYNB_CONFIG = {}
# With the following example configuration you can use a custom jinja template
Expand Down
18 changes: 12 additions & 6 deletions nikola/data/themes/base/templates/index_helper.tmpl
Expand Up @@ -20,11 +20,17 @@

<%def name="mathjax_script(posts)">
%if any(post.is_mathjax for post in posts):
<script type="text/javascript"
src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
</script>
<script type="text/x-mathjax-config">
MathJax.Hub.Config({tex2jax: {inlineMath: [['$latex ','$'], ['\\(','\\)']]}});
</script>
%if use_katex:
<script src="//cdnjs.cloudflare.com/ajax/libs/KaTeX/0.3.0/katex.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/KaTeX/0.3.0/contrib/auto-render.min.js"></script>
<script>
renderMathInElement(document.body);
</script>
%else:
<script type="text/javascript" src="//cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"> </script>
<script type="text/x-mathjax-config">
MathJax.Hub.Config({tex2jax: {inlineMath: [['$latex ','$'], ['\\(','\\)']]}});
</script>
%endif
%endif
</%def>
18 changes: 12 additions & 6 deletions nikola/data/themes/base/templates/post_helper.tmpl
Expand Up @@ -86,11 +86,17 @@

<%def name="mathjax_script(post)">
%if post.is_mathjax:
<script type="text/javascript"
src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
</script>
<script type="text/x-mathjax-config">
MathJax.Hub.Config({tex2jax: {inlineMath: [['$latex ','$'], ['\\(','\\)']]}});
</script>
%if use_katex:
<script src="//cdnjs.cloudflare.com/ajax/libs/KaTeX/0.3.0/katex.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/KaTeX/0.3.0/contrib/auto-render.min.js"></script>
<script>
renderMathInElement(document.body);
</script>
%else:
<script type="text/javascript" src="//cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"> </script>
<script type="text/x-mathjax-config">
MathJax.Hub.Config({tex2jax: {inlineMath: [['$latex ','$'], ['\\(','\\)']]}});
</script>
%endif
%endif
</%def>
2 changes: 2 additions & 0 deletions nikola/nikola.py
Expand Up @@ -491,6 +491,7 @@ def __init__(self, **config):
'USE_CDN': False,
'USE_CDN_WARNING': True,
'USE_FILENAME_AS_TITLE': True,
'USE_KATEX': False,
'USE_OPEN_GRAPH': True,
'USE_SLUGIFY': True,
'TIMEZONE': 'UTC',
Expand Down Expand Up @@ -915,6 +916,7 @@ def _set_global_context(self):
self._GLOBAL_CONTEXT['site_has_comments'] = bool(self.config.get('COMMENT_SYSTEM'))
self._GLOBAL_CONTEXT['mathjax_config'] = self.config.get(
'MATHJAX_CONFIG')
self._GLOBAL_CONTEXT['use_katex'] = self.config.get('USE_KATEX')
self._GLOBAL_CONTEXT['subtheme'] = self.config.get('THEME_REVEAL_CONFIG_SUBTHEME')
self._GLOBAL_CONTEXT['transition'] = self.config.get('THEME_REVEAL_CONFIG_TRANSITION')
self._GLOBAL_CONTEXT['content_footer'] = self.config.get(
Expand Down

0 comments on commit acf5fb7

Please sign in to comment.