From d5830170808353f64038c0b3cb3c931c39c74d9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Christian=20Gr=C3=BCnhage?= Date: Mon, 31 Aug 2020 21:33:36 +0200 Subject: [PATCH] feat: add katex support --- README.md | 28 ++++++++++++++++++++++++++++ templates/index.html | 15 +++++++++++++++ templates/shortcodes/katex.html | 1 + 3 files changed, 44 insertions(+) create mode 100644 templates/shortcodes/katex.html diff --git a/README.md b/README.md index 0c43d93..183dd6b 100644 --- a/README.md +++ b/README.md @@ -83,5 +83,33 @@ date = 1970-01-01 author = "John Smith" ``` +### KaTeX math formula support + +This theme contains math formula support using [KaTeX](https://katex.org/), +which can be enabled by setting `katex_enable = true` in the `extra` section +of `config.toml`: + +```toml +[extra] +katex_enable = true +``` + +After enabling this extension, the `katex` short code can be used in documents: +* `{{ katex(body="\KaTeX") }}` to typeset a math formula inlined into a text, + similar to `$...$` in LaTeX +* `{% katex(block=true) %}\KaTeX{% end %}` to typeset a block of math formulas, + similar to `$$...$$` in LaTeX + +#### Automatic rendering without short codes + +Optionally, `\\( \KaTeX \\)` inline and `\\[ \KaTeX \\]` / `$$ \KaTeX $$` +block-style automatic rendering is also supported, if enabled in the config: + +```toml +[extra] +katex_enable = true +katex_auto_render = true +``` + ## Original This template is based on the Hugo template https://git.habd.as/comfusion/after-dark diff --git a/templates/index.html b/templates/index.html index 7d16008..ce78415 100644 --- a/templates/index.html +++ b/templates/index.html @@ -17,8 +17,23 @@ {% block css %} + {% if config.extra.katex_enable %} + + {% endif %} {% endblock css %} + {% block js %} + {% if config.extra.katex_enable %} + + + {% if config.extra.katex_auto_render %} + + {% endif %} + {% endif %} + + {% endblock js %} + {% block extra_head %} {% endblock extra_head %} diff --git a/templates/shortcodes/katex.html b/templates/shortcodes/katex.html new file mode 100644 index 0000000..1d13c0a --- /dev/null +++ b/templates/shortcodes/katex.html @@ -0,0 +1 @@ +