aboutsummaryrefslogtreecommitdiffstats
path: root/nikola/data/themes/base/templates/math_helper.tmpl
blob: 961b7ced20a1dbe3f233d2a4cd0b2269ea37b688 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
### Note: at present, MathJax and KaTeX do not respect the USE_CDN configuration option
<%def name="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
</%def>

<%def name="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
</%def>

<%def name="math_scripts_ifpost(post)">
    %if post.has_math:
        ${math_scripts()}
    %endif
</%def>

<%def name="math_scripts_ifposts(posts)">
    %if any(post.has_math for post in posts):
        ${math_scripts()}
    %endif
</%def>

<%def name="math_styles_ifpost(post)">
    %if post.has_math:
        ${math_styles()}
    %endif
</%def>

<%def name="math_styles_ifposts(posts)">
    %if any(post.has_math for post in posts):
        ${math_styles()}
    %endif
</%def>