Skip to content

Commit

Permalink
✨ feat: add KaTeX support
Browse files Browse the repository at this point in the history
  • Loading branch information
welpo committed Apr 15, 2023
1 parent 7a1bb1d commit f9335b3
Show file tree
Hide file tree
Showing 66 changed files with 35 additions and 5 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ A simple blog theme powered by [Zola](https://getzola.org). See a live preview [
## Features

- [X] Dark and light themes. Defaults to the OS setting, with a switcher in the navigation bar.
- [X] [KaTeX](https://katex.org/) support.
- [X] All JavaScript (theme switcher and KaTeX) can be fully disabled.
- [X] Projects page.
- [X] Archive page.
- [x] Tags.
Expand Down
9 changes: 6 additions & 3 deletions content/blog/almost-no-js.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
+++
title = "Almost no JavaScript"
date = 2023-01-06
updated = = 2023-04-15
description = "JavaScript is only used when HTML and CSS aren't enough."

[taxonomies]
tags = ["showcase"]
+++

# Javascript?
# JavaScript?

This theme has almost no JavaScript. It includes a single ~950 byte `.js` file with the logic for the light/dark mode switch.
This theme has almost no JavaScript. It includes a ~950 byte `.js` file with the logic for the light/dark mode switch which can be disabled by setting `theme_switcher = false` in the `config.toml` file.

Other than that, it's a fast site with html and css. Just the way (most of) the web should be :-)
KaTex support, which requires JavaScript, can be activated for specific posts.

Other than that, it's a fast site with HTML and CSS. Just the way (most of) the web should be :-)
21 changes: 19 additions & 2 deletions content/blog/markdown.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,31 @@
+++
title = "Markdown examples"
date = 2023-01-31
updated = 2023-03-01
updated = 2023-04-15
description = "This post showcases some examples of Markdown formatting, including a table, code blocks and tags, quotes, tables, and footnotes."

[taxonomies]
tags = ["markdown", "showcase"]

[extra]
katex = true
+++

## KaTeX

[KaTeX](https://katex.org/) is a fast and easy-to-use library that enables the rendering of mathematical notation, using LaTeX syntax.

You can use KaTeX **inline** by wrapping the expression between `$` or between `\\(` and `\\)`.

For example, `$ \sin(x) = \sum_{n=0}^{\infty} \frac{(-1)^n}{(2n + 1)!} x^{2n + 1} $` would render: $ \sin(x) = \sum_{n=0}^{\infty} \frac{(-1)^n}{(2n + 1)!} x^{2n + 1} $

To display the expression **on its own line and centered**, wrap it around `$$` or between `\\[` and `\\]`.

For example, `\\[ r = \frac{\sum_{i=1}^{n}(x_i - \bar{x})(y_i - \bar{y})}{\sqrt{\sum_{i=1}^{n}(x_i - \bar{x})^2}\sqrt{\sum_{i=1}^{n}(y_i - \bar{y})^2}} \\]` renders: \\[ r = \frac{\sum_{i=1}^{n}(x_i - \bar{x})(y_i - \bar{y})}{\sqrt{\sum_{i=1}^{n}(x_i - \bar{x})^2}\sqrt{\sum_{i=1}^{n}(y_i - \bar{y})^2}} \\]

To activate KaTeX for a post, include `katex = true` within the `[extra]` section of the post's front matter. For enhanced performance and security, the JavaScript, CSS, and fonts are hosted locally.

**Note**: After enabling KaTeX, if you want to use \$ without rendering a mathematical expression, escape it with a single backslash: `\$`.

## Table

Expand All @@ -20,7 +38,6 @@ Here's an example of a table[^1]. Its colours change depending on the current th
| Fe | Iron | 26 |
| Au | Gold | 79 |


## Code Block

```rust
Expand Down
Binary file added static/fonts/KaTeX/KaTeX_AMS-Regular.ttf
Binary file not shown.
Binary file added static/fonts/KaTeX/KaTeX_AMS-Regular.woff
Binary file not shown.
Binary file added static/fonts/KaTeX/KaTeX_AMS-Regular.woff2
Binary file not shown.
Binary file added static/fonts/KaTeX/KaTeX_Caligraphic-Bold.ttf
Binary file not shown.
Binary file added static/fonts/KaTeX/KaTeX_Caligraphic-Bold.woff
Binary file not shown.
Binary file added static/fonts/KaTeX/KaTeX_Caligraphic-Bold.woff2
Binary file not shown.
Binary file added static/fonts/KaTeX/KaTeX_Caligraphic-Regular.ttf
Binary file not shown.
Binary file added static/fonts/KaTeX/KaTeX_Caligraphic-Regular.woff
Binary file not shown.
Binary file not shown.
Binary file added static/fonts/KaTeX/KaTeX_Fraktur-Bold.ttf
Binary file not shown.
Binary file added static/fonts/KaTeX/KaTeX_Fraktur-Bold.woff
Binary file not shown.
Binary file added static/fonts/KaTeX/KaTeX_Fraktur-Bold.woff2
Binary file not shown.
Binary file added static/fonts/KaTeX/KaTeX_Fraktur-Regular.ttf
Binary file not shown.
Binary file added static/fonts/KaTeX/KaTeX_Fraktur-Regular.woff
Binary file not shown.
Binary file added static/fonts/KaTeX/KaTeX_Fraktur-Regular.woff2
Binary file not shown.
Binary file added static/fonts/KaTeX/KaTeX_Main-Bold.ttf
Binary file not shown.
Binary file added static/fonts/KaTeX/KaTeX_Main-Bold.woff
Binary file not shown.
Binary file added static/fonts/KaTeX/KaTeX_Main-Bold.woff2
Binary file not shown.
Binary file added static/fonts/KaTeX/KaTeX_Main-BoldItalic.ttf
Binary file not shown.
Binary file added static/fonts/KaTeX/KaTeX_Main-BoldItalic.woff
Binary file not shown.
Binary file added static/fonts/KaTeX/KaTeX_Main-BoldItalic.woff2
Binary file not shown.
Binary file added static/fonts/KaTeX/KaTeX_Main-Italic.ttf
Binary file not shown.
Binary file added static/fonts/KaTeX/KaTeX_Main-Italic.woff
Binary file not shown.
Binary file added static/fonts/KaTeX/KaTeX_Main-Italic.woff2
Binary file not shown.
Binary file added static/fonts/KaTeX/KaTeX_Main-Regular.ttf
Binary file not shown.
Binary file added static/fonts/KaTeX/KaTeX_Main-Regular.woff
Binary file not shown.
Binary file added static/fonts/KaTeX/KaTeX_Main-Regular.woff2
Binary file not shown.
Binary file added static/fonts/KaTeX/KaTeX_Math-BoldItalic.ttf
Binary file not shown.
Binary file added static/fonts/KaTeX/KaTeX_Math-BoldItalic.woff
Binary file not shown.
Binary file added static/fonts/KaTeX/KaTeX_Math-BoldItalic.woff2
Binary file not shown.
Binary file added static/fonts/KaTeX/KaTeX_Math-Italic.ttf
Binary file not shown.
Binary file added static/fonts/KaTeX/KaTeX_Math-Italic.woff
Binary file not shown.
Binary file added static/fonts/KaTeX/KaTeX_Math-Italic.woff2
Binary file not shown.
Binary file added static/fonts/KaTeX/KaTeX_SansSerif-Bold.ttf
Binary file not shown.
Binary file added static/fonts/KaTeX/KaTeX_SansSerif-Bold.woff
Binary file not shown.
Binary file added static/fonts/KaTeX/KaTeX_SansSerif-Bold.woff2
Binary file not shown.
Binary file added static/fonts/KaTeX/KaTeX_SansSerif-Italic.ttf
Binary file not shown.
Binary file added static/fonts/KaTeX/KaTeX_SansSerif-Italic.woff
Binary file not shown.
Binary file added static/fonts/KaTeX/KaTeX_SansSerif-Italic.woff2
Binary file not shown.
Binary file added static/fonts/KaTeX/KaTeX_SansSerif-Regular.ttf
Binary file not shown.
Binary file not shown.
Binary file added static/fonts/KaTeX/KaTeX_SansSerif-Regular.woff2
Binary file not shown.
Binary file added static/fonts/KaTeX/KaTeX_Script-Regular.ttf
Binary file not shown.
Binary file added static/fonts/KaTeX/KaTeX_Script-Regular.woff
Binary file not shown.
Binary file added static/fonts/KaTeX/KaTeX_Script-Regular.woff2
Binary file not shown.
Binary file added static/fonts/KaTeX/KaTeX_Size1-Regular.ttf
Binary file not shown.
Binary file added static/fonts/KaTeX/KaTeX_Size1-Regular.woff
Binary file not shown.
Binary file added static/fonts/KaTeX/KaTeX_Size1-Regular.woff2
Binary file not shown.
Binary file added static/fonts/KaTeX/KaTeX_Size2-Regular.ttf
Binary file not shown.
Binary file added static/fonts/KaTeX/KaTeX_Size2-Regular.woff
Binary file not shown.
Binary file added static/fonts/KaTeX/KaTeX_Size2-Regular.woff2
Binary file not shown.
Binary file added static/fonts/KaTeX/KaTeX_Size3-Regular.ttf
Binary file not shown.
Binary file added static/fonts/KaTeX/KaTeX_Size3-Regular.woff
Binary file not shown.
Binary file added static/fonts/KaTeX/KaTeX_Size3-Regular.woff2
Binary file not shown.
Binary file added static/fonts/KaTeX/KaTeX_Size4-Regular.ttf
Binary file not shown.
Binary file added static/fonts/KaTeX/KaTeX_Size4-Regular.woff
Binary file not shown.
Binary file added static/fonts/KaTeX/KaTeX_Size4-Regular.woff2
Binary file not shown.
Binary file added static/fonts/KaTeX/KaTeX_Typewriter-Regular.ttf
Binary file not shown.
Binary file added static/fonts/KaTeX/KaTeX_Typewriter-Regular.woff
Binary file not shown.
Binary file added static/fonts/KaTeX/KaTeX_Typewriter-Regular.woff2
Binary file not shown.
1 change: 1 addition & 0 deletions static/js/katex.min.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions static/katex.min.css

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@
{% endblock main_content %}
</div>
{% include "partials/footer.html" %}

{% if page.extra.katex and page.extra.katex == true %}
<link rel="stylesheet" href="{{ get_url(path='katex.min.css', trailing_slash=false) | safe }}">

<script defer src="{{ get_url(path='js/katex.min.js', trailing_slash=false) | safe }}"></script>
{% endif %}
</body>

</html>

0 comments on commit f9335b3

Please sign in to comment.