{%- if theme.math.mathjax.enable or theme.math.katex.enable %}
  {%- set enable_math = false %}

  {%- set is_index_has_math = false %}

  {# At home, check if there has `mathjax: true` post #}
  {%- if is_home() and not theme.math.every_page %}
    {%- for post in page.posts.toArray() %}
      {%- if post.mathjax and not is_index_has_math %}
        {%- set is_index_has_math = true %}
      {%- endif %}
    {%- endfor %}
  {%- endif %}

  {%- if theme.math.every_page or is_index_has_math or page.mathjax %}
    {%- set enable_math = true %}
  {%- endif %}

  {{ next_data('enableMath', enable_math) }}

  {%- if theme.math.mathjax.enable %}
    {%- include '_third-party/math/mathjax.njk' -%}
  {% elif theme.math.katex.enable %}
    {%- include '_third-party/math/katex.njk' -%}
  {%- endif %}
{%- endif %}
