From 63546f792f15e18da966cdcdce1bf7a6c465c016 Mon Sep 17 00:00:00 2001 From: Chuxin Huang Date: Fri, 5 Jun 2020 22:38:13 +1000 Subject: [PATCH] add math --- exampleSite/content/blog/markdown-syntax.md | 4 +- exampleSite/content/blog/math-typesetting.md | 48 ++++++++++++++++++++ layouts/blog/single.html | 3 ++ layouts/partials/math.html | 11 +++++ 4 files changed, 64 insertions(+), 2 deletions(-) create mode 100644 exampleSite/content/blog/math-typesetting.md create mode 100644 layouts/partials/math.html diff --git a/exampleSite/content/blog/markdown-syntax.md b/exampleSite/content/blog/markdown-syntax.md index 1b7e46c..f6672a4 100644 --- a/exampleSite/content/blog/markdown-syntax.md +++ b/exampleSite/content/blog/markdown-syntax.md @@ -84,7 +84,7 @@ html #### Code block with Hugo's internal highlight shortcode -{{< highlight html >}} +```html @@ -95,7 +95,7 @@ html

Test

-{{< /highlight >}} +``` ## List Types diff --git a/exampleSite/content/blog/math-typesetting.md b/exampleSite/content/blog/math-typesetting.md new file mode 100644 index 0000000..d8c8117 --- /dev/null +++ b/exampleSite/content/blog/math-typesetting.md @@ -0,0 +1,48 @@ +--- +title: "Math Typesetting" +date: 2020-06-05 +slug: "math-typesetting" +description: "A brief guide to setup KaTeX" +keywords: ["gohugo", "hugo", "go", "blog"] +draft: false +tags: ["math"] +stylesheet: "post.css" +math: true +--- + +Mathematical notation in a Hugo project can be enabled by using third party JavaScript libraries. + + +In this example we will be using [KaTeX](https://katex.org/) + +- Create a partial under `/layouts/partials/math.html` +- Within this partial reference the [Auto-render Extension](https://katex.org/docs/autorender.html) or host these scripts locally. +- Include the partial in your templates like so: + +``` +{{ if or .Params.math .Site.Params.math }} +{{ partial "math.html" . }} +{{ end }} +``` +- To enable KaTex globally set the parameter `math` to `true` in a project's configuration +- To enable KaTex on a per page basis include the parameter `math: true` in content files. + +**Note:** Use the online reference of [Supported TeX Functions](https://katex.org/docs/supported.html) +{{< math.inline >}} +{{ if or .Page.Params.math .Site.Params.math }} + + + + +{{ end }} +{{}} + +### Examples + +Inline math: $$ \varphi = \dfrac{1+\sqrt5}{2}= 1.6180339887… $$ + +Block math: + +$$ +\sigma(t) = \cfrac{1}{1 + e^{-t}} +$$ diff --git a/layouts/blog/single.html b/layouts/blog/single.html index 98aea1d..c06590b 100644 --- a/layouts/blog/single.html +++ b/layouts/blog/single.html @@ -13,6 +13,9 @@
{{ partial "anchored-headings.html" .Content }} + {{ if or .Params.math .Site.Params.math }} + {{ partial "math.html" . }} + {{ end }}
{{ partial "tags.html" .}} {{ partial "post-pagination.html" .}} diff --git a/layouts/partials/math.html b/layouts/partials/math.html new file mode 100644 index 0000000..0e79917 --- /dev/null +++ b/layouts/partials/math.html @@ -0,0 +1,11 @@ + + + + \ No newline at end of file