#61, Add katex shortcode
This commit is contained in:
parent
c98b510fe0
commit
185e52d2f6
7 changed files with 54 additions and 4 deletions
13
README.md
13
README.md
|
@ -260,6 +260,19 @@ sequenceDiagram
|
|||
{{< /mermaid >}}
|
||||
```
|
||||
|
||||
### KaTeX Syntax
|
||||
|
||||
Render math formulas with [KaTeX](https://katex.org/)
|
||||
|
||||
```
|
||||
{{< katex >}}
|
||||
$$ x = \begin{cases}
|
||||
a &\text{if } b \\
|
||||
c &\text{if } d
|
||||
\end{cases} $$
|
||||
{{< /katex >}}
|
||||
```
|
||||
|
||||
## Contributing
|
||||
|
||||
### [Extra credits to contributors](https://github.com/alex-shpak/hugo-book/graphs/contributors)
|
||||
|
|
|
@ -166,3 +166,28 @@ sequenceDiagram
|
|||
{{< /mermaid >}}
|
||||
|
||||
{{< /columns >}}
|
||||
|
||||
|
||||
## KaTeX
|
||||
|
||||
{{< columns >}}
|
||||
|
||||
```
|
||||
$$ x = \begin{cases}
|
||||
a &\text{if } b \\
|
||||
c &\text{if } d
|
||||
\end{cases} $$
|
||||
```
|
||||
|
||||
<--->
|
||||
|
||||
{{< katex >}}
|
||||
$$ x = \begin{cases}
|
||||
a &\text{if } b \\
|
||||
c &\text{if } d
|
||||
\end{cases} $$
|
||||
{{< /katex >}}
|
||||
|
||||
{{< /columns >}}
|
||||
|
||||
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -1 +1 @@
|
|||
{"Target":"search-data.min.613ed83747ddaa2f75aeac976f9f2a6612611b9c9d57468f57147a9a5233a14a.js","MediaType":"application/javascript","Data":{"Integrity":"sha256-YT7YN0fdqi91rqyXb58qZhJhG5ydV0aPVxR6mlIzoUo="}}
|
||||
{"Target":"search-data.min.8e65fc357463e492a0a63bbf1f8879c1d3e651b9b8ab524fd1782b843af7bf9c.js","MediaType":"application/javascript","Data":{"Integrity":"sha256-jmX8NXRj5JKgpju/H4h5wdPmUbm4q1JP0XgrhDr3v5w="}}
|
|
@ -1,4 +1,4 @@
|
|||
(function(){const input=document.querySelector("#book-search-input");const results=document.querySelector("#book-search-results");input.addEventListener("focus",init);input.addEventListener("keyup",search);function init(){input.removeEventListener("focus",init);input.required=true;loadScript("/example/lunr.min.js");loadScript("/example/search-data.min.613ed83747ddaa2f75aeac976f9f2a6612611b9c9d57468f57147a9a5233a14a.js",function(){input.readOnly=false;input.required=false;search();});}
|
||||
(function(){const input=document.querySelector("#book-search-input");const results=document.querySelector("#book-search-results");input.addEventListener("focus",init);input.addEventListener("keyup",search);function init(){input.removeEventListener("focus",init);input.required=true;loadScript("/example/lunr.min.js");loadScript("/example/search-data.min.8e65fc357463e492a0a63bbf1f8879c1d3e651b9b8ab524fd1782b843af7bf9c.js",function(){input.readOnly=false;input.required=false;search();});}
|
||||
function search(){while(results.firstChild){results.removeChild(results.firstChild);}
|
||||
if(!input.value){return;}
|
||||
const terms=lunr.tokenizer(input.value);const searchHits=window.bookSearch.idx.query(function(query){query.term(terms,{boost:100});query.term(terms,{boost:10,wildcard:lunr.Query.wildcard.LEADING|lunr.Query.wildcard.TRAILING});query.term(terms,{editDistance:2});});searchHits.slice(0,10).forEach(function(hit){const page=window.bookSearch.pages[hit.ref];const li=document.createElement("li"),a=li.appendChild(document.createElement("a"));a.href=page.href;a.textContent=page.title;results.appendChild(li);});}
|
||||
|
|
|
@ -1 +1 @@
|
|||
{"Target":"search.min.0447761fc68ec7ed1cdd2551765f48f51d0a1c93a5cd3775b1785b1a9fae79bc.js","MediaType":"application/javascript","Data":{"Integrity":"sha256-BEd2H8aOx+0c3SVRdl9I9R0KHJOlzTd1sXhbGp+uebw="}}
|
||||
{"Target":"search.min.cb8117f621a52d2616303b084f897f1d82fac83fc82d1fb628f29d9b705e798a.js","MediaType":"application/javascript","Data":{"Integrity":"sha256-y4EX9iGlLSYWMDsIT4l/HYL6yD/ILR+2KPKdm3BeeYo="}}
|
12
layouts/shortcodes/katex.html
Normal file
12
layouts/shortcodes/katex.html
Normal file
|
@ -0,0 +1,12 @@
|
|||
{{ if not (.Page.Scratch.Get "katex") }}
|
||||
<!-- Include katext only first time -->
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.11.0/dist/katex.min.css" integrity="sha384-BdGj8xC2eZkQaxoQ8nSLefg4AV4/AwB3Fj+8SUSo7pnKP6Eoy18liIKTPn9oBYNG" crossorigin="anonymous">
|
||||
<script defer src="https://cdn.jsdelivr.net/npm/katex@0.11.0/dist/katex.min.js" integrity="sha384-JiKN5O8x9Hhs/UE5cT5AAJqieYlOZbGT3CHws/y97o3ty4R7/O5poG9F3JoiOYw1" crossorigin="anonymous"></script>
|
||||
<script defer src="https://cdn.jsdelivr.net/npm/katex@0.11.0/dist/contrib/auto-render.min.js" integrity="sha384-kWPLUVMOks5AQFrykwIup5lo0m3iMkkHrD0uJ4H5cjeGihAutqP0yW0J6dpFiVkI" crossorigin="anonymous" onload="renderMathInElement(document.body);"></script>
|
||||
{{ .Page.Scratch.Set "katex" true }}
|
||||
{{ end }}
|
||||
|
||||
<p class="katex{{ with .Get "class" }} {{ . }}{{ end }}">
|
||||
{{ .Inner }}
|
||||
</p>
|
||||
|
Loading…
Reference in a new issue