Skip to content

Commit 398da4e

Browse files
committed
Added Tex math typesetting using the fastest library available: Khan Academy’s KaTeX
1 parent 7c52edd commit 398da4e

File tree

7 files changed

+53
-4
lines changed

7 files changed

+53
-4
lines changed

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ Features:
2727
- Robots.txt inproves SEO by removing tag listings from search engines so your content is more prominent
2828
- Responsive, accessible menu for static pages (or anything else) that stays out of the way [NEW!]
2929
- Comments powered by Disqus, and loaded with AJAX that don’t slow down your site. [NEW!]
30-
30+
- Blazing fast
31+
- Thumbnails are resized automathically.
32+
- Non-essential scripts and styles are loaded asynchronously or deferred
33+
- Comments are only loaded when needed
34+
- Uses the fastest math rendering library, and the fastest webfont provider [citation needed]
35+
- Optional Math rendering with KaTeX
3136

3237
![Screenshot](http://api.drp.io/files/5437789e305b7.png)

assets/css/defer.css

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
* http://prismjs.com/download.html?themes=prism&languages=markup+css+clike+javascript */
1010
code[class*=language-],pre[class*=language-]{color:#000;text-shadow:0 1px #fff;font-family:Consolas,Monaco,'Andale Mono',monospace;direction:ltr;text-align:left;white-space:pre;word-spacing:normal;word-break:normal;line-height:1.5;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-hyphens:none;-moz-hyphens:none;-ms-hyphens:none;hyphens:none}code[class*=language-] ::-moz-selection,code[class*=language-]::-moz-selection,pre[class*=language-] ::-moz-selection,pre[class*=language-]::-moz-selection{text-shadow:none;background:#b3d4fc}code[class*=language-] ::selection,code[class*=language-]::selection,pre[class*=language-] ::selection,pre[class*=language-]::selection{text-shadow:none;background:#b3d4fc}@media print{code[class*=language-],pre[class*=language-]{text-shadow:none}}pre[class*=language-]{padding:1em;margin:.5em 0;overflow:auto}:not(pre)>code[class*=language-],pre[class*=language-]{background:#f5f2f0}:not(pre)>code[class*=language-]{padding:.1em;border-radius:.3em}.token.cdata,.token.comment,.token.doctype,.token.prolog{color:#708090}.token.punctuation{color:#999}.namespace{opacity:.7}.token.boolean,.token.constant,.token.number,.token.property,.token.symbol,.token.tag{color:#905}.token.attr-name,.token.builtin,.token.char,.token.selector,.token.string{color:#690}.language-css .token.string,.style .token.string,.token.entity,.token.operator,.token.url,.token.variable{color:#a67f59;background:hsla(0,0%,100%,.5)}.token.atrule,.token.attr-value,.token.keyword{color:#07a}.token.function{color:#DD4A68}.token.important,.token.regex{color:#e90}.token.important{font-weight:700}.token.entity{cursor:help}.token.deleted{color:red}.token.inserted{color:green}pre.line-numbers{position:relative;padding-left:3.8em;counter-reset:linenumber}pre.line-numbers>code{position:relative}.line-numbers .line-numbers-rows{position:absolute;pointer-events:none;top:0;font-size:100%;left:-3.8em;width:3em;letter-spacing:-1px;border-right:1px solid #999;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none}.line-numbers-rows>span{pointer-events:none;display:block;counter-increment:linenumber}.line-numbers-rows>span:before{content:counter(linenumber);color:#999;display:block;padding-right:.8em;text-align:right}
1111

12+
13+
1214
/* ==========================================================================
1315
1. Icons - Sets up the icon font and respective classes
1416
========================================================================== */

assets/css/main.css

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -875,6 +875,17 @@ aside.note:before{
875875
padding-bottom: 0;
876876
}
877877

878+
.katex-display {
879+
margin: 1em 0;
880+
text-align: center;
881+
}
882+
883+
.katex-display > span {
884+
display: inline-block;
885+
overflow: hidden;
886+
margin: 0 auto;
887+
}
888+
878889
/* Kill that stylish little circle that was on the border, too */
879890
.post-template .post:after {
880891
display: none;

default.hbs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,12 @@
5353
-->
5454
{{!>menu}}
5555

56+
<!-- This loads katex.hbs in; if a page has anything with the class math, katex.hbs loads Khan Academy’s Tex math typesetting library and runs it on the content.
57+
58+
If you don’t want to use KaTeX, comment this out.
59+
-->
60+
{{>katex}}
61+
5662
{{! Ghost outputs important scripts and data with this tag }}
5763
{{ghost_foot}}
5864

page.hbs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@
2929
<section class="post-content">
3030
{{content}}
3131
</section>
32-
3332
{{/post}}
3433
</article>
35-
3634
</main>

partials/katex.hbs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<span id="katexScript"></span>
2+
3+
<script type="text/javascript">
4+
var mathAreas = document.getElementsByClassName("math");
5+
if (mathAreas){
6+
var ss = document.createElement("link");
7+
ss.type = "text/css";
8+
ss.rel = "stylesheet";
9+
ss.href = "//cdnjs.cloudflare.com/ajax/libs/KaTeX/0.1.1/katex.min.css";
10+
document.getElementsByTagName("head")[0].appendChild(ss);
11+
12+
var script = document.createElement( 'script' );
13+
script.type = 'text/javascript';
14+
script.src = '//cdnjs.cloudflare.com/ajax/libs/KaTeX/0.1.1/katex.min.js';
15+
document.body.appendChild(script);
16+
17+
window.onload = function() {
18+
Array.prototype.forEach.call(
19+
document.getElementsByClassName("math"),
20+
function(el) {
21+
try {
22+
katex.render(el.innerHTML, el);
23+
} catch (e) { console.log(e); }
24+
}
25+
);
26+
}
27+
}
28+
</script>

post.hbs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,5 +78,4 @@
7878
<!-- If you want Disqus comments, uncomment this. Make sure to set your disqus shortname in partials/comments.hbs first! -->
7979
{{!>comments}}
8080
</article>
81-
8281
</main>

0 commit comments

Comments
 (0)