Skip to content

Commit

Permalink
Add math equations using KaTeX
Browse files Browse the repository at this point in the history
  • Loading branch information
mbacvanski committed Sep 12, 2020
1 parent 6774614 commit 4aaa8bc
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 4 deletions.
2 changes: 1 addition & 1 deletion _config.yml
@@ -1,4 +1,3 @@
# things you probably want to change
url: https://mbacvanski.github.io
title: Marc Bacvanski
description: Marc Bacvanski
Expand All @@ -16,6 +15,7 @@ kramdown:
input: GFM
hard_wrap: false
syntax_highlighter: rouge
math_engine: mathjax

defaults:
- # applies the default layout to all files in the project
Expand Down
27 changes: 24 additions & 3 deletions _includes/foot.html
@@ -1,3 +1,24 @@
</div>
</body>
</html>
</div>
</body>

<!-- Parse the Latex divs with Katex-->
<script type="text/javascript">
document.querySelectorAll('script[type=\'math/tex\']').forEach(
function (s) {
const tex = s.textContent;
const str = katex.renderToString(tex, {displayMode: false}); // inline
// s.replaceWith(str);
s.outerHTML = str;
});

document.querySelectorAll('script[type=\'math/tex; mode=display\']').forEach(
function (s) {
const tex = s.textContent;
const str = katex.renderToString(tex.replace(/%.*/g, ''), {displayMode: true}); // block
console.log('str = ' + str);
// s.innerHTML = str;
s.outerHTML = str;
});
</script>

</html>
4 changes: 4 additions & 0 deletions _includes/head.html
Expand Up @@ -12,6 +12,10 @@
<link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png">
<link rel="manifest" href="/site.webmanifest">

<!-- Load KaTeX -->
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/KaTeX/0.1.1/katex.min.css">
<script src="//cdnjs.cloudflare.com/ajax/libs/KaTeX/0.1.1/katex.min.js"></script>

<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-163967035-1"></script>
<script>
Expand Down
4 changes: 4 additions & 0 deletions _includes/smallhead.html
Expand Up @@ -7,6 +7,10 @@
<link rel="stylesheet" href="{{ '/styles/styles.css' | prepend:site.url }}">
<link rel="stylesheet" href="{{ '/styles/syntax.css' | prepend:site.url }}">

<!-- Load KaTeX -->
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/KaTeX/0.1.1/katex.min.css">
<script src="//cdnjs.cloudflare.com/ajax/libs/KaTeX/0.1.1/katex.min.js"></script>

<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-163967035-1"></script>
<script>
Expand Down

0 comments on commit 4aaa8bc

Please sign in to comment.