mathjax problems on material-theme theme

13 views
Skip to first unread message

Drini Pedro

unread,
Sep 18, 2016, 1:31:14 AM9/18/16
to nikola-discuss
I found out that material-theme has problems with matjax.

Mathjax renders fine on the main page:



but, when I enter to the actual post, mathjax stops working.


and it happens only with the material-theme theme


Now, I did a quick poke


templates/post.tmpl calls {{ helper.mathjax_script(post) }}  from   post_helper.tmpl

and there the math-related part is


{% macro mathjax_script(post) %}

    {% if post.is_mathjax %}

        <script type="text/x-mathjax-config">

        MathJax.Hub.Config({tex2jax: {inlineMath: [['$latex ','$'], ['\\(','\\)']]}});</script>

        <script src="/assets/js/mathjax.js"></script>

    {% endif %}

{% endmacro %}


while
templates/index.tmpl calls {{ helper.mathjax_script(posts) }} from... a non existing helper_index.tmpl ???
( top says 
{% import 'index_helper.tmpl' as helper with context %}
but there is no index_htlper.tmpl)


yet index renders mathjax and posts not...



for comparison, zen-jinja (which renders find mathjax on index and post pages) 
has
{% import 'arusahni_helper.tmpl' as arusahni with context %}
{% import 'post_helper.tmpl' as helper with context %}
(....)
 {{ helper.mathjax_script(post) }}
but post_helper.tmpl does not exist! yet arusahni_helper defines

{{ mathjax_config }}
    {% if use_cdn %}
        <!--[if lt IE 9]><script src="//html5shim.googlecode.com/svn/trunk/html5.js"></script><![endif]-->
    {% else %}
        <!--[if lt IE 9]><script src="/assets/js/html5.js"></script><![endif]-->
    {% endif %}



So I'm confused.

1) why on material-theme  mathjax does not work on posts
2) why mathjax works when it is not defined and not the other way
(and less pressing but still intriguing)
3) why can zen-jinja can all a function from the wrong file?

thank you

Chris Warrick

unread,
Sep 18, 2016, 7:40:30 AM9/18/16
to Nikola—Discuss
On 18 September 2016 at 07:31, Drini Pedro <drini...@gmail.com> wrote:
>
> I found out that material-theme has problems with matjax.
>
> [snip]
>
> templates/post.tmpl calls {{ helper.mathjax_script(post) }} from post_helper.tmpl
> and there the math-related part is
>
> {% macro mathjax_script(post) %}
> {% if post.is_mathjax %}
> <script type="text/x-mathjax-config">
> MathJax.Hub.Config({tex2jax: {inlineMath: [['$latex ','$'], ['\\(','\\)']]}});</script>
> <script src="/assets/js/mathjax.js"></script>
> {% endif %}
> {% endmacro %}

This snippet is outdated. I fixed it.

> but there is no index_htlper.tmpl)
> but post_helper.tmpl does not exist! yet arusahni_helper defines

You see, there is an inheritance chain. Every theme in Nikola inherits
from another theme. And some of the most basic services are provided
by the `base` and `base-jinja` themes. So for example, material-theme
inherits from bootstrap3-jinja, which in turn inherits from
base-jinja. If a template file does not exist in material-theme,
Nikola will then try looking for it in bootstrap3-jinja and
base-jinja. This allows for simple customization of themes and not
copy-pasting the same files around. (For example, our comments
templates are only in base/base-jinja, and yet every theme uses them)

So, when material-theme asks for index_helper.tmpl, it doesn’t exist
in material-theme, so we dig further. We check bootstrap3-jinja, but
it doesn’t have it too. We then resort to base-jinja, which has this
template, and all works well.

(mathjax_config is a configuration variable available to all
templates, not a function)

I updated material-theme with a newer version of the mathjax snippet.
Run `nikola theme -i material-theme` to install the new version of
this theme.

--
Chris Warrick <https://chriswarrick.com/>
PGP: 5EAAEA16
Reply all
Reply to author
Forward
0 new messages