~rep/anglegrinding

d9f03fd2be5d5d8e2ccf488b2e9ebcc3265e6627 — rep 7 months ago 1ee5a12
Override KaTeX shortcode to fix whitespace issues

There is spurious whitespace inserted after math by the shortcode
expansion, resulting in an extra space when the math is inside
parentheses or otherwise not followed by natural whitespace in the file.
This is fixable by adding a whitespace-chomping template at the end of
the file.
1 files changed, 14 insertions(+), 0 deletions(-)

A layouts/shortcodes/katex.html
A layouts/shortcodes/katex.html => layouts/shortcodes/katex.html +14 -0
@@ 0,0 1,14 @@
{{- if not (.Page.Scratch.Get "katex") -}}
<!-- Include katext only first time -->
<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 -}}

<span {{- with .Get "class" }} class="{{ . }}"{{ end }}>
  {{- cond (in .Params "display") "\\[" "\\(" -}}
  {{- trim .Inner "\n" -}}
  {{- cond (in .Params "display") "\\]" "\\)" -}}
</span>
{{- "" -}}