aboutsummaryrefslogtreecommitdiffstats
path: root/nikola/data/themes/base-jinja/templates/math_helper.tmpl
diff options
context:
space:
mode:
Diffstat (limited to 'nikola/data/themes/base-jinja/templates/math_helper.tmpl')
-rw-r--r--nikola/data/themes/base-jinja/templates/math_helper.tmpl69
1 files changed, 69 insertions, 0 deletions
diff --git a/nikola/data/themes/base-jinja/templates/math_helper.tmpl b/nikola/data/themes/base-jinja/templates/math_helper.tmpl
new file mode 100644
index 0000000..c16f9b8
--- /dev/null
+++ b/nikola/data/themes/base-jinja/templates/math_helper.tmpl
@@ -0,0 +1,69 @@
+{# Note: at present, MathJax and KaTeX do not respect the USE_CDN configuration option #}
+{% macro math_scripts() %}
+ {% if use_katex %}
+ <script src="https://cdn.jsdelivr.net/npm/katex@0.10.2/dist/katex.min.js" integrity="sha384-9Nhn55MVVN0/4OFx7EE5kpFBPsEMZxKTCnA+4fqDmg12eCTqGi6+BB2LjY8brQxJ" crossorigin="anonymous"></script>
+ <script src="https://cdn.jsdelivr.net/npm/katex@0.10.2/dist/contrib/auto-render.min.js" integrity="sha384-kWPLUVMOks5AQFrykwIup5lo0m3iMkkHrD0uJ4H5cjeGihAutqP0yW0J6dpFiVkI" crossorigin="anonymous"></script>
+ {% if katex_auto_render %}
+ <script>
+ renderMathInElement(document.body,
+ {
+ {{ katex_auto_render }}
+ }
+ );
+ </script>
+ {% else %}
+ <script>
+ renderMathInElement(document.body,
+ {
+ delimiters: [
+ {left: "$$", right: "$$", display: true},
+ {left: "\\[", right: "\\]", display: true},
+ {left: "\\begin{equation*}", right: "\\end{equation*}", display: true},
+ {left: "\\(", right: "\\)", display: false}
+ ]
+ }
+ );
+ </script>
+ {% endif %}
+ {% else %}
+{# Note: given the size of MathJax; nikola will retrieve MathJax from a CDN regardless of use_cdn configuration #}
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_HTMLorMML" integrity="sha384-3lJUsx1TJHt7BA4udB5KPnDrlkO8T6J6v/op7ui0BbCjvZ9WqV4Xm6DTP6kQ/iBH" crossorigin="anonymous"></script>
+ {% if mathjax_config %}
+ {{ mathjax_config }}
+ {% else %}
+ <script type="text/x-mathjax-config">
+ MathJax.Hub.Config({tex2jax: {inlineMath: [['$latex ','$'], ['\\(','\\)']]}});
+ </script>
+ {% endif %}
+ {% endif %}
+{% endmacro %}
+
+{% macro math_styles() %}
+ {% if use_katex %}
+ <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.10.2/dist/katex.min.css" integrity="sha384-yFRtMMDnQtDRO8rLpMIKrtPCD5jdktao2TV19YiZYWMDkUR5GQZR/NOVTdquEx1j" crossorigin="anonymous">
+ {% endif %}
+{% endmacro %}
+
+{% macro math_scripts_ifpost(post) %}
+ {% if post.has_math %}
+ {{ math_scripts() }}
+ {% endif %}
+{% endmacro %}
+
+{% macro math_scripts_ifposts(posts) %}
+ {% if posts|selectattr("has_math")|list %}
+ {{ math_scripts() }}
+ {% endif %}
+{% endmacro %}
+
+{% macro math_styles_ifpost(post) %}
+ {% if post.has_math %}
+ {{ math_styles() }}
+ {% endif %}
+{% endmacro %}
+
+{% macro math_styles_ifposts(posts) %}
+ {% if posts|selectattr("has_math")|list %}
+ {{ math_styles() }}
+ {% endif %}
+{% endmacro %}