aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Shpak <alex-shpak@users.noreply.github.com>2020-04-11 20:05:43 +0200
committerAlex Shpak <alex-shpak@users.noreply.github.com>2020-04-11 20:05:43 +0200
commite4e43bd9b12a3e37f0d3c2760ea7f867ba8273a7 (patch)
tree60543b71a718f34e4d27a54c8028c6888db39f69
parentd61558462fb5f16d171ba327bc6315b82e49054b (diff)
Refactor KaTeX shortcode, remove whitespaces and fix font size
-rw-r--r--exampleSite/content/docs/shortcodes/katex.md17
-rw-r--r--layouts/shortcodes/katex.html16
2 files changed, 12 insertions, 21 deletions
diff --git a/exampleSite/content/docs/shortcodes/katex.md b/exampleSite/content/docs/shortcodes/katex.md
index fae88c5..4beeaa0 100644
--- a/exampleSite/content/docs/shortcodes/katex.md
+++ b/exampleSite/content/docs/shortcodes/katex.md
@@ -7,20 +7,14 @@ KaTeX shortcode let you render math typesetting in markdown document. See [KaTeX
```latex
{{</* katex [display] [class="text-center"] */>}}
-x = \begin{cases}
- a &\text{if } b \\
- c &\text{if } d
-\end{cases}
+f(x) = \int_{-\infty}^\infty\hat f(\xi)\,e^{2 \pi i \xi x}\,d\xi
{{</* /katex */>}}
```
<--->
-{{< katex >}}
-x = \begin{cases}
- a &\text{if } b \\
- c &\text{if } d
-\end{cases}
+{{< katex display >}}
+f(x) = \int_{-\infty}^\infty\hat f(\xi)\,e^{2 \pi i \xi x}\,d\xi
{{< /katex >}}
{{< /columns >}}
@@ -29,9 +23,6 @@ x = \begin{cases}
Here is some inline example: {{< katex >}}\pi(x){{< /katex >}}, rendered in the same line. And below is `display` example, having `display: block`
{{< katex display >}}
-x = \begin{cases}
- a &\text{if } b \\
- c &\text{if } d
-\end{cases}
+f(x) = \int_{-\infty}^\infty\hat f(\xi)\,e^{2 \pi i \xi x}\,d\xi
{{< /katex >}}
Text continues here.
diff --git a/layouts/shortcodes/katex.html b/layouts/shortcodes/katex.html
index cc98a7d..e6b7564 100644
--- a/layouts/shortcodes/katex.html
+++ b/layouts/shortcodes/katex.html
@@ -1,13 +1,13 @@
-{{ if not (.Page.Scratch.Get "katex") }}
+{{- if not (.Page.Scratch.Get "katex") -}}
<!-- Include katext only first time -->
-<link rel="stylesheet" href="{{ "katex/katex.min.css" | relURL }}">
+<link rel="stylesheet" href="{{ "katex/katex.min.css" | relURL }}" />
<script defer src="{{ "katex/katex.min.js" | relURL }}"></script>
<script defer src="{{ "katex/auto-render.min.js" | relURL }}" onload="renderMathInElement(document.body);"></script>
-{{ .Page.Scratch.Set "katex" true }}
-{{ end }}
+{{- .Page.Scratch.Set "katex" true -}}
+{{- end -}}
-<span class="katex{{ with .Get "class" }} {{ . }}{{ end }}">
- {{ if in .Params "display" }}\[{{ else }}\({{ end -}}
- {{ $.Inner }}
- {{- if in .Params "display" }}\]{{ else }}\){{ end }}
+<span {{- with .Get "class" }} class="{{ . }}"{{ end }}>
+ {{- cond (in .Params "display") "\\[" "\\(" -}}
+ {{- trim .Inner "\n" -}}
+ {{- cond (in .Params "display") "\\]" "\\)" -}}
</span>