Browse Source

added toggleable client side katex with configurable delims

master
Alexander William Wong 7 months ago
parent
commit
43c48640d3
Signed by: alex <alex@udia.ca> GPG Key ID: E90E5D6448C2C663
3 changed files with 29 additions and 0 deletions
  1. +17
    -0
      README.md
  2. +1
    -0
      layouts/_default/baseof.html
  3. +11
    -0
      layouts/partials/client-katex.html

+ 17
- 0
README.md View File

@@ -10,6 +10,23 @@ cd hugo
go install --tags extended
```

## Site Parameters

Defined in `config.[yaml|toml|json]`, these parameters are used by the Candor theme. The defaults are provided below.

```toml
[params]
author = "Alexander Wong" # str
license = "WTFPL" # str
licenseLink = ""http://www.wtfpl.net/about/"" # str

# Math typesetting
disableKatexJS = false # bool (useful to disable if server rendering math)
# str: left delim, str: right delim, str: math type (display/inline)
katexDelimiters = [["$$", "$$", "display"], ["\\(", "\\)", "inline"]]
```


## License

[MIT](LICENSE)


+ 1
- 0
layouts/_default/baseof.html View File

@@ -9,6 +9,7 @@
{{ with .Site.Params.author }}<meta name="author" content="{{ . }}">{{ end }}
{{ if .Description }}<meta name="description" content="{{.Description}}" />{{ end }}
{{ hugo.Generator }}
{{ if not .Site.Params.disableKatexJS }}{{ partial "client-katex" . }}{{ end }}
{{ $scssOpts := (dict "outputStyle" "compressed") }}
{{ with resources.Get "sass/main.scss" | resources.ToCSS $scssOpts }}<style>{{ .Content | safeCSS }}</style>{{ end }}



+ 11
- 0
layouts/partials/client-katex.html View File

@@ -0,0 +1,11 @@
{{ with resources.Get "js/katex.js" | minify | fingerprint }}<script type="text/javascript" src="{{ .RelPermalink }}" integrity="{{ .Data.Integrity }}" defer></script>{{ end }}
{{ $autoJs := resources.Get "js/katex-auto-render.js" }}{{ $copyJs := resources.Get "js/katex-copy-tex.js" }}
{{ $rawDelims := slice }}
{{ range $delim_val := .Site.Params.katexDelimiters }}
{{ $ld := index $delim_val 0 | replaceRE "([\\\\])(.*)" "\\\\${2}" }}{{ $rd := index $delim_val 1 | replaceRE "([\\\\])(.*)" "\\\\${2}" }}{{ $delim_p_str := "" }}
{{ if eq "display" (index $delim_val 2) }}{{ $delim_p_str = printf "{left:'%s',right:'%s',display:%s}" $ld $rd "true" }}{{ else }}{{ $delim_p_str = printf "{left:'%s',right:'%s',display:%s}" $ld $rd "false" }}{{ end }}
{{ $rawDelims = $rawDelims | append $delim_p_str}}
{{ else }}
{{ $rawDelims = slice "{left:'$$',right:'$$',display:true}" "{left:'\\\\(',right:'\\\\)',display:false}" }}
{{ end }}
{{ with slice $autoJs $copyJs | resources.Concat "js/tex-contrib.js" | minify | fingerprint }}<script type="text/javascript" src="{{ .RelPermalink }}" integrity="{{ .Data.Integrity }}" defer onload="renderMathInElement(document.getElementById('markdownBody'),{delimiters:[{{ delimit $rawDelims "," | safeJS }}]});"></script>{{ end }}

Loading…
Cancel
Save