From ac170a08332e4aeeea78fc68ed6d54abc456f08e Mon Sep 17 00:00:00 2001 From: Stephan Lachnit Date: Mon, 25 Apr 2022 13:48:33 +0200 Subject: [PATCH 1/3] feature: add support for GLFM math blocks This add supports for GLFM's math blocks [1] using hugo's Markdown render hooks [2]. [1]: https://docs.gitlab.com/ee/user/markdown.html#math [2]: https://gohugo.io/templates/render-hooks/#render-hooks-for-code-blocks Signed-off-by: Stephan Lachnit --- layouts/_default/_markup/render-codeblock-math.html | 3 +++ .../en/docs/adding-content/diagrams-and-formulae/index.md | 7 +++++++ 2 files changed, 10 insertions(+) create mode 100644 layouts/_default/_markup/render-codeblock-math.html diff --git a/layouts/_default/_markup/render-codeblock-math.html b/layouts/_default/_markup/render-codeblock-math.html new file mode 100644 index 0000000000..149a1ae188 --- /dev/null +++ b/layouts/_default/_markup/render-codeblock-math.html @@ -0,0 +1,3 @@ +

$$ +{{ .Inner | safeHTML }} +$$

diff --git a/userguide/content/en/docs/adding-content/diagrams-and-formulae/index.md b/userguide/content/en/docs/adding-content/diagrams-and-formulae/index.md index 859ed7e9a0..66abf3a82e 100644 --- a/userguide/content/en/docs/adding-content/diagrams-and-formulae/index.md +++ b/userguide/content/en/docs/adding-content/diagrams-and-formulae/index.md @@ -35,6 +35,13 @@ $$\tag*{(1)} P(E) = {n \choose k} p^k (1-p)^{n-k}$$ The probability of getting \\(k\\) heads when flipping \\(n\\) coins is: $$\tag*{(1)} P(E) = {n \choose k} p^k (1-p)^{n-k}$$ +You can also use [GLFM's math blocks](https://docs.gitlab.com/ee/user/markdown.html#math) (requires hugo 0.93 or newer): +````markdown +```math +\tag*{(1)} P(E) = {n \choose k} p^k (1-p)^{n-k} +``` +```` + {{% alert title="Tip" %}} This [wiki page](https://en.wikibooks.org/wiki/LaTeX/Mathematics) provides in-depth information about typesetting mathematical formulae using the \\(\LaTeX\\) typesetting system. {{% /alert %}} From 62d5bef476b3ac938491c8e291af59b532f28c5c Mon Sep 17 00:00:00 2001 From: Stephan Lachnit Date: Fri, 30 Sep 2022 13:28:19 +0200 Subject: [PATCH 2/3] doc: put KaTeX delimiters in own line Signed-off-by: Stephan Lachnit --- .../en/docs/adding-content/diagrams-and-formulae/index.md | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/userguide/content/en/docs/adding-content/diagrams-and-formulae/index.md b/userguide/content/en/docs/adding-content/diagrams-and-formulae/index.md index 66abf3a82e..94d81b5c5d 100644 --- a/userguide/content/en/docs/adding-content/diagrams-and-formulae/index.md +++ b/userguide/content/en/docs/adding-content/diagrams-and-formulae/index.md @@ -29,11 +29,15 @@ The following code sample produces an introductory text line followed by a formu ```tex The probability of getting \\(k\\) heads when flipping \\(n\\) coins is: -$$\tag*{(1)} P(E) = {n \choose k} p^k (1-p)^{n-k}$$ +$$ +\tag*{(1)} P(E) = {n \choose k} p^k (1-p)^{n-k} +$$ ``` The probability of getting \\(k\\) heads when flipping \\(n\\) coins is: -$$\tag*{(1)} P(E) = {n \choose k} p^k (1-p)^{n-k}$$ +$$ +\tag*{(1)} P(E) = {n \choose k} p^k (1-p)^{n-k} +$$ You can also use [GLFM's math blocks](https://docs.gitlab.com/ee/user/markdown.html#math) (requires hugo 0.93 or newer): ````markdown From 20b2801d169c2f9bca6976b5264d0af684bd1d18 Mon Sep 17 00:00:00 2001 From: Stephan Lachnit Date: Sat, 8 Oct 2022 10:43:41 +0200 Subject: [PATCH 3/3] Use user-defined delimiters for GLFM math blocks Signed-off-by: Stephan Lachnit --- .../_default/_markup/render-codeblock-math.html | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/layouts/_default/_markup/render-codeblock-math.html b/layouts/_default/_markup/render-codeblock-math.html index 149a1ae188..831b9a2f6b 100644 --- a/layouts/_default/_markup/render-codeblock-math.html +++ b/layouts/_default/_markup/render-codeblock-math.html @@ -1,3 +1,16 @@ -

$$ +{{/* set default delimiters */}} +{{ $delimiter_left := "$$" }} +{{ $delimiter_right := "$$" }} + +{{/* override delimiters if set in config file */}} +{{ with $.Page.Site.Params.katex.options.delimiters }} + {{ range first 1 ( where . "display" true ) }} + {{ $delimiter_left = index . "left" }} + {{ $delimiter_right = index . "right" }} + {{ end }} +{{end}} + +{{/* output of equation */}} +

{{ $delimiter_left }} {{ .Inner | safeHTML }} -$$

+{{ $delimiter_right }}