From 0f2bd0c0a61042166a81badec1c00fd1cfda4261 Mon Sep 17 00:00:00 2001
From: Vlad Ionescu <Vlaaaaaaad@users.noreply.github.com>
Date: Tue, 01 May 2018 18:48:49 +0000
Subject: [PATCH] Math (#14)

---
 layouts/partials/post.html              |   25 +++++++++++++++++++++++++
 exampleSite/content/posts/theme-demo.md |    7 +++++++
 2 files changed, 32 insertions(+), 0 deletions(-)

diff --git a/exampleSite/content/posts/theme-demo.md b/exampleSite/content/posts/theme-demo.md
index f11b5b7..39c8c69 100644
--- a/exampleSite/content/posts/theme-demo.md
+++ b/exampleSite/content/posts/theme-demo.md
@@ -1,6 +1,7 @@
 +++
 date = "2017-01-08"
 title = "Theme Demo"
+math = "true"
 
 +++
 
@@ -26,6 +27,12 @@
 
 ~~Deleted text~~
 
+This is text with inline math $\sum_{n=1}^{\infty} 2^{-n} = 1$ and with math blocks:
+
+$$
+\sum_{n=1}^{\infty} 2^{-n} = 1
+$$
+
 | Heading | Another heading |
 | :----:  | :-------------: |
 |  text   |      text       |
diff --git a/layouts/partials/post.html b/layouts/partials/post.html
index 5e8e4dd..b32ccd9 100644
--- a/layouts/partials/post.html
+++ b/layouts/partials/post.html
@@ -3,6 +3,31 @@
     <header>
       <h1 class="title">{{ .Title }}</h1>
       <h2 class="date">{{ .Date.Format "January 2, 2006" }}</h2>
+
+      {{ if eq .Params.math "true" }}
+        <script type="text/javascript" async
+          src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.4/MathJax.js?config=TeX-AMS-MML_HTMLorMML-full">
+          MathJax.Hub.Config({
+            tex2jax: {
+              inlineMath: [['$','$']],
+              displayMath: [['$$','$$']],
+              processEscapes: true,
+              processEnvironments: true,
+              skipTags: ['script', 'noscript', 'style', 'textarea', 'pre'],
+              TeX: { extensions: ["AMSmath.js", "AMSsymbols.js"] }
+            }
+          });
+          MathJax.Hub.Queue(function() {
+            // Fix <code> tags after MathJax finishes running. This is a
+            // hack to overcome a shortcoming of Markdown. Discussion at
+            // https://github.com/mojombo/jekyll/issues/199
+            var all = MathJax.Hub.getAllJax(), i;
+            for(i = 0; i < all.length; i += 1) {
+                all[i].SourceElement().parentNode.className += ' has-jax';
+            }
+          });
+          </script>
+      {{ end }}
     </header>
 
     {{ .Content }}

--
Gitblit v1.10.0