Skip to content
Permalink
Browse files
Fix #2715 -- add KaTeX CSS when needed
Signed-off-by: Chris Warrick <kwpolska@gmail.com>
  • Loading branch information
Kwpolska committed Apr 12, 2017
1 parent da60e7a commit 129c08c96d25f219651828cfa1f8f82943d043a7
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 11 deletions.
@@ -1,10 +1,22 @@
New in master
=============

Math support changes
--------------------

* If you edited templates related to indexes and posts (``index.tmpl``,
``post.tmpl``, ``index_helper.tmpl``, ``post_helper.tmpl``) in your
templates, you should adjust them to use ``math_helper.tmpl``.
* If you are using KaTeX, you should remove the CSS snippet from your
configuration (templates), as that is now handled by Nikola.

Features
--------

* Add ``{post_title}`` tag for Read More links (Issue #2709)
* Include KaTeX CSS automatically (Issue #2715)
* Split out math code into new ``math_helper.tmpl`` template (Issue
#2715)

Bugfixes
--------
@@ -972,9 +972,6 @@ PRETTY_URLS = ${PRETTY_URLS}

# 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: (make sure to match the version Nikola uses -- check it in HTML output)
# EXTRA_HEAD_DATA = """<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.7.1/katex.min.css" integrity="sha384-wITovz90syo1dJWVh32uuETPVEtGigN07tkttEqPv+uR2SE/mbQcG7ATL28aI9H0" crossorigin="anonymous">"""
# USE_KATEX = False

# If you want to use the old (buggy) inline math $.$ with KaTeX, then
@@ -1,5 +1,6 @@
## -*- coding: utf-8 -*-
<%namespace name="helper" file="index_helper.tmpl"/>
<%namespace name="math" file="math_helper.tmpl"/>
<%namespace name="comments" file="comments_helper.tmpl"/>
<%namespace name="pagination" file="pagination_helper.tmpl"/>
<%inherit file="base.tmpl"/>
@@ -9,6 +10,7 @@
% if posts and (permalink == '/' or permalink == '/' + index_file):
<link rel="prefetch" href="${posts[0].permalink()}" type="text/html">
% endif
${math.math_styles_ifposts(posts)}
</%block>

<%block name="content">
@@ -51,5 +53,5 @@
</div>
${helper.html_pager()}
${comments.comment_link_script()}
${helper.mathjax_script(posts)}
${math.math_scripts_ifposts(posts)}
</%block>
@@ -20,7 +20,5 @@
</%def>

<%def name="mathjax_script(posts)">
%if any(post.is_mathjax for post in posts):
${math.math_script()}
%endif
${math.math_scripts_ifposts(posts)}
</%def>
@@ -26,3 +26,31 @@
% endif
%endif
</%def>

<%def name="math_styles()">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.7.1/katex.min.css" integrity="sha384-wITovz90syo1dJWVh32uuETPVEtGigN07tkttEqPv+uR2SE/mbQcG7ATL28aI9H0" crossorigin="anonymous">
</%def>

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

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

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

<%def name="math_styles_ifposts(posts)">
%if any(post.is_mathjax for post in posts):
${math.math_styles()}
%endif
</%def>
@@ -2,6 +2,7 @@
<%namespace name="helper" file="post_helper.tmpl"/>
<%namespace name="pheader" file="post_header.tmpl"/>
<%namespace name="comments" file="comments_helper.tmpl"/>
<%namespace name="math" file="math_helper.tmpl"/>
<%inherit file="base.tmpl"/>

<%block name="extra_head">
@@ -22,6 +23,7 @@
${helper.open_graph_metadata(post)}
${helper.twitter_card_information(post)}
${helper.meta_translations(post)}
${math.math_styles_ifpost(post)}
</%block>

<%block name="content">
@@ -42,7 +44,7 @@
${comments.comment_form(post.permalink(absolute=True), post.title(), post._base_path)}
</section>
% endif
${helper.mathjax_script(post)}
${math.math_styles_ifpost(post)}
</article>
${comments.comment_link_script()}
</%block>
@@ -86,7 +86,5 @@
</%def>

<%def name="mathjax_script(post)">
%if post.is_mathjax:
${math.math_script()}
%endif
${math.math_scripts_ifpost(post)}
</%def>

0 comments on commit 129c08c

Please sign in to comment.