mirror of https://github.com/luizdepra/hugo-coder.git

d-dandrew
02.14.2019 81666ed54bb438f4af01fd4a111df8bd7d423120
Add KaTeX support (#164)

* Add render-latex-using-katex.md to Demonstarate how to use the katex

* Update math.html add katex scripts and css
1 files added
1 files modified
50 ■■■■■ changed files
exampleSite/content/posts/render-latex-using-katex.md 36 ●●●●● patch | view | raw | blame | history
layouts/partials/posts/math.html 14 ●●●●● patch | view | raw | blame | history
exampleSite/content/posts/render-latex-using-katex.md
New file
@@ -0,0 +1,36 @@
+++
date = "2019-03-20"
title = "Render LaTeX using KaTeX"
description = "Katex support demo"
katex = "true"
series = ["Theme", "Hugo"]
+++
Enable katex by adding `katex = "true"` to the [front matter](https://gohugo.io/content-management/front-matter/)
```toml
+++
katex = "true"
+++
```
It's almost a dropin alternative to the mathjax solution,you should just choose one of them.
Inline math looks like this
```tex
This is text with inline math $\sum_{n=1}^{\infty} 2^{-n} = 1$
```
This is text with inline math $\sum_{n=1}^{\infty} 2^{-n} = 1$
and with math blocks:
```tex
$$
\sum_{n=1}^{\infty} 2^{-n} = 1
$$
```
$$
\sum_{n=1}^{\infty} 2^{-n} = 1
$$
layouts/partials/posts/math.html
@@ -22,3 +22,17 @@
    });
  </script>
{{- end -}}
{{- if .Params.katex -}}
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.10.1/dist/katex.min.css" integrity="sha384-dbVIfZGuN1Yq7/1Ocstc1lUEm+AT+/rCkibIcC/OmWo5f0EA48Vf8CytHzGrSwbQ" crossorigin="anonymous">
  <script defer src="https://cdn.jsdelivr.net/npm/katex@0.10.1/dist/katex.min.js" integrity="sha384-2BKqo+exmr9su6dir+qCw08N2ZKRucY4PrGQPPWU1A7FtlCGjmEGFqXCv5nyM5Ij" crossorigin="anonymous"></script>
  <script defer src="https://cdn.jsdelivr.net/npm/katex@0.10.1/dist/contrib/auto-render.min.js" integrity="sha384-kWPLUVMOks5AQFrykwIup5lo0m3iMkkHrD0uJ4H5cjeGihAutqP0yW0J6dpFiVkI" crossorigin="anonymous"
    onload="renderMathInElement(document.body,
      {
        delimiters: [
          {left: '$$', right: '$$', display:true},
          {left: '$', right: '$', display:false},
        ]
      }
    );">
  </script>
{{- end -}}