add latex support; activate when latex: true is set in markdown file

This commit is contained in:
liz2020
2020-11-20 15:38:34 -05:00
parent 28dcf728cb
commit 8f4225ea8f
4 changed files with 23 additions and 2 deletions

View File

@@ -56,7 +56,7 @@ summary: "The summary content"
--- ---
``` ```
### Approch 2: use <!--more--> ### Approch 2: use `<!--more-->`
Use `<!--more-->` to seperate content that will display in the posts page as abstraction and the rest of the content. This is different from summary, as summary will not appear in the post. Use `<!--more-->` to seperate content that will display in the posts page as abstraction and the rest of the content. This is different from summary, as summary will not appear in the post.
``` ```
--- ---
@@ -69,6 +69,21 @@ abstraction show in the post page
other content other content
``` ```
## Support LaTex
In you post add `katex:true` to [front matter](https://gohugo.io/content-management/front-matter/)
```
---
katex: true
---
```
Then the [katex script](https://katex.org/docs/autorender.html) will auto render the string enclosed be delimiters.
```
# replace ... with latex formula
display inline \\( ... \\)
display block $$ ... $$
```
![latex example](images/latex_example.png)
## config.toml example ## config.toml example
```toml ```toml

BIN
images/latex_example.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

View File

@@ -23,5 +23,7 @@
<span class="f6 text-gray-light"></span> <span class="f6 text-gray-light"></span>
</div> </div>
</div> </div>
{{ if .Params.katex }}
{{ partial "katex.html" . }}
{{ end }}
{{ partial "script.html" . }} {{ partial "script.html" . }}

View File

@@ -0,0 +1,4 @@
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.12.0/dist/katex.min.css" integrity="sha384-AfEj0r4/OFrOo5t7NnNe46zW/tFgW6x/bCJG8FqQCEo3+Aro6EYUG4+cU+KJWu/X" crossorigin="anonymous">
<script defer src="https://cdn.jsdelivr.net/npm/katex@0.12.0/dist/katex.min.js" integrity="sha384-g7c+Jr9ZivxKLnZTDUhnkOnsh30B4H0rpLUpJ4jAIKs4fnJI+sEnkvrMWph2EDg4" crossorigin="anonymous"></script>
<script defer src="https://cdn.jsdelivr.net/npm/katex@0.12.0/dist/contrib/auto-render.min.js" integrity="sha384-mll67QQFJfxn0IYznZYonOWZ644AWYC+Pt2cHqMaRhXVrursRwvLnLaebdGIlYNa" crossorigin="anonymous"
onload="renderMathInElement(document.body);"></script>