Skip to content

Commit

Permalink
add katex integration
Browse files Browse the repository at this point in the history
  • Loading branch information
HidegonSan committed Nov 25, 2023
1 parent 444b89b commit e78a5d7
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 98 deletions.
94 changes: 1 addition & 93 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,96 +4,4 @@

## Thanks

**Hugo**:
[https://gohugo.io/](https://gohugo.io/)

**PaperMod**:
[https://github.com/adityatelange/hugo-PaperMod/](https://github.com/adityatelange/hugo-PaperMod/)

**instant.page**:
[https://instant.page/](https://instant.page/)

**GitHub Pages**:
[https://pages.github.com/](https://pages.github.com/)

**GoatCounter**:
[https://www.goatcounter.com/](https://www.goatcounter.com/)

**Google Forms**:
[https://www.google.com/intl/ja_jp/forms/about/](https://www.google.com/intl/ja_jp/forms/about/)

Maybe inspired:

Show related posts:
[https://github.com/adityatelange/hugo-PaperMod/pull/1049](https://github.com/adityatelange/hugo-PaperMod/pull/1049)

Adding a render-link hook:
[https://github.com/adityatelange/hugo-PaperMod/discussions/542](https://github.com/adityatelange/hugo-PaperMod/discussions/542)

Add margin top to certain single elements surrounded by code blocks for consistency:
[https://github.com/adityatelange/hugo-PaperMod/pull/1128/](https://github.com/adityatelange/hugo-PaperMod/pull/1128/)

fix: Adjust margin-bottom in nested lists:
[https://github.com/adityatelange/hugo-PaperMod/pull/1284](https://github.com/adityatelange/hugo-PaperMod/pull/1284)

Magnific Image Pop-Up Modal for Hugo:
[https://gist.github.com/zjeaton/0cdd7e4bed9d292ab6f3d76b0369f16d](https://gist.github.com/zjeaton/0cdd7e4bed9d292ab6f3d76b0369f16d)

Modal Image Pop-up:
[https://compassionate-feynman-1e69e9.netlify.app/modal/](https://compassionate-feynman-1e69e9.netlify.app/modal/)

Hugoの画像を自動で圧縮する方法:
[https://kakudo.org/blog/auto-image-compression-in-hugo/](https://kakudo.org/blog/auto-image-compression-in-hugo/)

Overview of Hugo/PaperMod, modifying PaperMod, and comparison to al-folio:
[https://jessewei.dev/blog/2023/papermod/](https://jessewei.dev/blog/2023/papermod/)

オッズに合う - Hugo:
[https://joni.jp/categories/hugo/](https://joni.jp/categories/hugo/)

アロハル - Hugo:
[https://aloha-ru.com/hugo/](https://aloha-ru.com/hugo/)

k-kaz が Hugo で遊ぶサイト:
[https://k-kaz-git.github.io/](https://k-kaz-git.github.io/)

mokuzine.net - hugo:
[https://mokuzine.net/tags/hugo/](https://mokuzine.net/tags/hugo/)

まくまく Hugo ノート:
[https://maku77.github.io/hugo/](https://maku77.github.io/hugo/)

ひよこまめ Hugo:
[https://blog.chick-p.work/tags/hugo](https://blog.chick-p.work/tags/hugo)

Nelis Oostens - Hugo:
[https://oostens.me/posts/hugo/](https://oostens.me/posts/hugo/)

hugo-PaperModX:
[https://github.com/reorx/hugo-PaperModX](https://github.com/reorx/hugo-PaperModX)

hugo-WonderMod:
[https://github.com/Wonderfall/hugo-WonderMod](https://github.com/Wonderfall/hugo-WonderMod)

hugo-BurgerMod:
[https://github.com/mylesagray/hugo-BurgerMod](https://github.com/mylesagray/hugo-BurgerMod)

hugo-shortcode-roneo-collection:
[https://github.com/RoneoOrg/hugo-shortcode-roneo-collection](https://github.com/RoneoOrg/hugo-shortcode-roneo-collection)

hugo-plus:
[https://github.com/H4tch/hugo-plus](https://github.com/H4tch/hugo-plus)

hugo-modules:
[https://github.com/gethugothemes/hugo-modules](https://github.com/gethugothemes/hugo-modules)

hugo-leaflet:
[https://github.com/altrdev/hugo-leaflet](https://github.com/altrdev/hugo-leaflet)

hugo-video:
[https://github.com/martignoni/hugo-video](https://github.com/martignoni/hugo-video)

hugo-cloak-email:
[https://github.com/martignoni/hugo-cloak-email](https://github.com/martignoni/hugo-cloak-email)

In addition, many others, all dependency, thanks!
[https://hidegonsan.github.io/blog/pages/thanks/](https://hidegonsan.github.io/blog/pages/thanks/)
16 changes: 11 additions & 5 deletions content/pages/thanks/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,21 @@ ShowBreadCrumbs: false
**PaperMod**:
[https://github.com/adityatelange/hugo-PaperMod/](https://github.com/adityatelange/hugo-PaperMod/)

**GitHub Pages**:
[https://pages.github.com/](https://pages.github.com/)

**GoatCounter**:
[https://www.goatcounter.com/](https://www.goatcounter.com/)

**instant.page**:
[https://instant.page/](https://instant.page/)

**GitHub Pages**:
[https://pages.github.com/](https://pages.github.com/)
**KaTeX**:
[https://katex.org/](https://katex.org/)

<!-- **Google Analytics**: -->
<!-- [https://marketingplatform.google.com/about/analytics/](https://marketingplatform.google.com/about/analytics/) -->

**GoatCounter**:
[https://www.goatcounter.com/](https://www.goatcounter.com/)

**Google Forms**:
[https://www.google.com/intl/ja_jp/forms/about/](https://www.google.com/intl/ja_jp/forms/about/)

Expand All @@ -59,6 +62,9 @@ Modal Image Pop-up:
Hugoの画像を自動で圧縮する方法:
[https://kakudo.org/blog/auto-image-compression-in-hugo/](https://kakudo.org/blog/auto-image-compression-in-hugo/)

Hugo でエスケープの問題を回避しつつ KaTeX を使う:
[https://www.oshikiri.org/posts/use-katex-in-hugo/](https://www.oshikiri.org/posts/use-katex-in-hugo/)

Overview of Hugo/PaperMod, modifying PaperMod, and comparison to al-folio:
[https://jessewei.dev/blog/2023/papermod/](https://jessewei.dev/blog/2023/papermod/)

Expand Down
2 changes: 2 additions & 0 deletions layouts/partials/extend_head.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
{{- partialCached "head/goatcounter.html" . -}}

{{- partial "head/katex.html" . -}}

{{- partial "head/seo.html" . -}}

{{/* {{- partialCached "head/anti_adblock.html" . -}} */}}
Expand Down
76 changes: 76 additions & 0 deletions layouts/partials/head/katex.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@

{{- if or (.Params.katex) (.Params.mhchem) -}}

{{- $katex_license_body := "/*\nSPDX-License-Identifier: MIT\nLicensed under the MIT license.\nhttps://github.com/KaTeX/KaTeX/blob/main/LICENSE\nhttps://opensource.org/license/mit/\n*/\n" -}}
{{- $katex_license_css := $katex_license_body | resources.FromString "css/katex_license.css" -}}
{{- $katex_license_js := $katex_license_body | resources.FromString "js/katex_license.js" -}}

{{- with (slice $katex_license_css (resources.Get "css/katex/katex.min.css")) | resources.Concat "assets/css/katex.min.css" | fingerprint -}}
<link
crossorigin="anonymous"
href="{{- .RelPermalink -}}"
integrity="{{- .Data.Integrity -}}"
rel="stylesheet"
>
{{- end -}}

{{- with (slice $katex_license_js (resources.Get "js/katex/katex.min.js")) | resources.Concat "assets/js/katex/katex.min.js" | fingerprint -}}
<script
defer
crossorigin="anonymous"
type="module"
src="{{- .RelPermalink -}}"
integrity="{{- .Data.Integrity -}}"
></script>
{{- end -}}

{{- with (slice $katex_license_js (resources.Get "js/katex/contrib/auto-render.min.js")) | resources.Concat "assets/js/katex/contrib/auto-render.min.js" | fingerprint -}}
<script
defer
crossorigin="anonymous"
type="module"
src="{{- .RelPermalink -}}"
integrity="{{- .Data.Integrity -}}"
></script>
{{- end -}}

{{- with (slice $katex_license_js (resources.Get "js/katex/contrib/copy-tex.min.js")) | resources.Concat "assets/js/katex/contrib/copy-tex.min.js" | fingerprint -}}
<script
defer
crossorigin="anonymous"
type="module"
src="{{- .RelPermalink -}}"
integrity="{{- .Data.Integrity -}}"
></script>
{{- end -}}

{{- if .Params.mhchem -}}
{{- with (slice $katex_license_js (resources.Get "js/katex/contrib/mhchem.min.js")) | resources.Concat "assets/js/katex/contrib/mhchem.min.js" | fingerprint -}}
<script
defer
crossorigin="anonymous"
type="module"
src="{{- .RelPermalink -}}"
integrity="{{- .Data.Integrity -}}"
></script>
{{- end -}}
{{- end -}}

<script>
document.addEventListener("DOMContentLoaded", function() {
renderMathInElement(document.body, {
delimiters: [
{left: '$$', right: '$$', display: true},
{left: '$', right: '$', display: false},
{left: '\\(', right: '\\)', display: false},
{left: '\\[', right: '\\]', display: true}
],
throwOnError : false
});
document.querySelectorAll(".katex_sc").forEach(function(e) {
katex.render(e.getAttribute("data-katex"), e, { throwOnError: false });
});
});
</script>

{{- end -}}
7 changes: 7 additions & 0 deletions layouts/shortcodes/katex.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{{- if eq (.Get 0) "display" -}}
<p class="katex_sc" data-katex="\displaystyle {{ trim .Inner "\n\r" }}">{{ trim .Inner "\n\r" }}</p>
{{- else if eq (.Get 0) "inline" -}}
<span class="katex_sc" data-katex="{{ trim .Inner "\n\r" }}">{{ trim .Inner "\n\r" }}</span>
{{- else -}}
<p class="katex_sc" data-katex="\displaystyle {{ trim .Inner "\n\r" }}">{{ trim .Inner "\n\r" }}</p>
{{- end -}}

0 comments on commit e78a5d7

Please sign in to comment.