Skip to content

Commit 253b938

Browse files
committed
feat: add katex math typesetting
1 parent ee9b898 commit 253b938

File tree

72 files changed

+159
-4
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+159
-4
lines changed

.eslintignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
assets/js/index.js
2+
assets/js/katex.js
23
assets/js/vendor
34
node_modules

assets/js/katex.js

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
document.addEventListener('DOMContentLoaded', function() {
2+
renderMathInElement(document.body, {
3+
delimiters: [
4+
{left: '$$', right: '$$', display: true},
5+
{left: '$', right: '$', display: false},
6+
{left: '\\(', right: '\\)', display: false},
7+
{left: '\\[', right: '\\]', display: true},
8+
],
9+
});
10+
});

assets/scss/app.scss

+3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
/** Import highlight.js */
1111
// @import "highlight.js/scss/dracula";
1212

13+
/** Import KaTeX */
14+
@import "katex/dist/katex";
15+
1316
/** Import theme styles */
1417
@import "common/fonts";
1518
@import "common/global";

assets/scss/common/_global.scss

+4
Original file line numberDiff line numberDiff line change
@@ -223,3 +223,7 @@ body {
223223
-webkit-text-fill-color: transparent;
224224
-moz-text-fill-color: transparent;
225225
}
226+
227+
.katex {
228+
font-size: $font-size-md;
229+
}

config/_default/config.toml

+3
Original file line numberDiff line numberDiff line change
@@ -85,3 +85,6 @@ rel = "sitemap"
8585
[[module.mounts]]
8686
source = "node_modules/flexsearch"
8787
target = "assets/js/vendor/flexsearch"
88+
[[module.mounts]]
89+
source = "node_modules/katex"
90+
target = "assets/js/vendor/katex"

config/_default/params.toml

+1
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,4 @@ editPage = false
5555
bootStrapJs = false
5656
breadCrumb = false
5757
highLight = true
58+
kaTex = true

config/postcss.config.js

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ module.exports = {
2323
'./assets/scss/components/_code.scss',
2424
'./assets/scss/components/_search.scss',
2525
'./assets/scss/common/_dark.scss',
26+
'./node_modules/katex/dist/katex.css'
2627
]),
2728
],
2829
}),

content/docs/examples/code.md

+2-2

content/docs/examples/math.md

+44

layouts/partials/footer/script-footer.html

+20-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
{{ $highlight := resources.Get "js/highlight.js" -}}
88
{{ $highlight := $highlight | js.Build -}}
99

10+
{{ $katex := resources.Get "js/vendor/katex/dist/katex.js" -}}
11+
{{ $katexAutoRender := resources.Get "js/vendor/katex/dist/contrib/auto-render.js" -}}
12+
1013
{{ $app := resources.Get "js/app.js" -}}
1114

1215
{{ $slice := slice $app -}}
@@ -40,6 +43,12 @@
4043
{{ $slice = $slice | append $darkMode -}}
4144
{{ end -}}
4245

46+
{{ if .Site.Params.options.kaTex -}}
47+
{{ $katexConfig := resources.Get "js/katex.js" -}}
48+
{{ $katexConfig := $katexConfig | js.Build -}}
49+
{{ $slice = $slice | append $katexConfig -}}
50+
{{ end -}}
51+
4352
{{ $js := $slice | resources.Concat "main.js" -}}
4453

4554
{{ if eq (hugo.Environment) "development" -}}
@@ -50,6 +59,10 @@
5059
{{ if .Site.Params.options.highLight -}}
5160
<script src="{{ $highlight.Permalink }}" defer></script>
5261
{{ end -}}
62+
{{ if .Site.Params.options.kaTex -}}
63+
<script src="{{ $katex.Permalink }}" defer></script>
64+
<script src="{{ $katexAutoRender.Permalink }}" onload="renderMathInElement(document.body);" defer></script>
65+
{{ end -}}
5366
{{ if .Site.Params.options.flexSearch -}}
5467
<script src="{{ $index.Permalink }}" defer></script>
5568
{{ end -}}
@@ -58,12 +71,18 @@
5871
{{ $index := $index | minify | fingerprint "sha512" -}}
5972
{{ $bs := $bs | minify | fingerprint "sha512" -}}
6073
{{ $highlight := $highlight | minify | fingerprint "sha512" -}}
74+
{{ $katex := $katex | minify | fingerprint "sha512" -}}
75+
{{ $katexAutoRender := $katexAutoRender | minify | fingerprint "sha512" -}}
6176
{{ if .Site.Params.options.bootStrapJs -}}
6277
<script src="{{ $bs.Permalink }}" integrity="{{ $bs.Data.Integrity }}" crossorigin="anonymous" defer></script>
6378
{{ end -}}
6479
<script src="{{ $js.Permalink }}" integrity="{{ $js.Data.Integrity }}" crossorigin="anonymous" defer></script>
6580
{{ if .Site.Params.options.highLight -}}
66-
<script src="{{ $highlight.Permalink }}" defer></script>
81+
<script src="{{ $highlight.Permalink }}" integrity="{{ $highlight.Data.Integrity }}" crossorigin="anonymous" defer></script>
82+
{{ end -}}
83+
{{ if .Site.Params.options.kaTex -}}
84+
<script src="{{ $katex.Permalink }}" integrity="{{ $katex.Data.Integrity }}" crossorigin="anonymous" defer></script>
85+
<script src="{{ $katexAutoRender.Permalink }}" integrity="{{ $katexAutoRender.Data.Integrity }}" crossorigin="anonymous" onload="renderMathInElement(document.body);" defer></script>
6786
{{ end -}}
6887
{{ if .Site.Params.options.flexSearch -}}
6988
<script src="{{ $index.Permalink }}" integrity="{{ $index.Data.Integrity }}" crossorigin="anonymous" defer></script>

package-lock.json

+66
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@
2828
"test": "npm run -s lint",
2929
"env": "env",
3030
"precheck": "npm version",
31-
"check": "hugo version"
31+
"check": "hugo version",
32+
"copy:katex-fonts": "shx cp ./node_modules/katex/dist/fonts/* ./static/fonts/"
3233
},
3334
"devDependencies": {
3435
"@babel/cli": "^7.13",
@@ -43,13 +44,15 @@
4344
"highlight.js": "^10.6.0",
4445
"hugo-bin": "^0.69",
4546
"instant.page": "^5.1",
47+
"katex": "^0.13.0",
4648
"lazysizes": "^5.3",
4749
"markdownlint-cli": "^0.27",
4850
"netlify-lambda": "^2.0",
4951
"postcss": "^8.2",
5052
"postcss-cli": "^8.3",
5153
"purgecss-whitelister": "^2.4",
5254
"rimraf": "^3.0",
55+
"shx": "^0.3.3",
5356
"standard-version": "^9.1",
5457
"stylelint": "^13.12",
5558
"stylelint-config-standard": "^21.0"

static/fonts/KaTeX_AMS-Regular.ttf

69.3 KB
Binary file not shown.

static/fonts/KaTeX_AMS-Regular.woff

36 KB
Binary file not shown.

static/fonts/KaTeX_AMS-Regular.woff2

30.4 KB
Binary file not shown.
15.1 KB
Binary file not shown.
9.16 KB
Binary file not shown.
8.2 KB
Binary file not shown.
14.6 KB
Binary file not shown.
8.93 KB
Binary file not shown.
8.05 KB
Binary file not shown.

static/fonts/KaTeX_Fraktur-Bold.ttf

23.8 KB
Binary file not shown.

static/fonts/KaTeX_Fraktur-Bold.woff

15.8 KB
Binary file not shown.

static/fonts/KaTeX_Fraktur-Bold.woff2

13.6 KB
Binary file not shown.
23.3 KB
Binary file not shown.
15.5 KB
Binary file not shown.
13.3 KB
Binary file not shown.

static/fonts/KaTeX_Main-Bold.ttf

58.6 KB
Binary file not shown.

static/fonts/KaTeX_Main-Bold.woff

34.2 KB
Binary file not shown.

static/fonts/KaTeX_Main-Bold.woff2

29.2 KB
Binary file not shown.
41.9 KB
Binary file not shown.
23.9 KB
Binary file not shown.
20.7 KB
Binary file not shown.

static/fonts/KaTeX_Main-Italic.ttf

44.9 KB
Binary file not shown.

static/fonts/KaTeX_Main-Italic.woff

24.8 KB
Binary file not shown.

static/fonts/KaTeX_Main-Italic.woff2

21.6 KB
Binary file not shown.

static/fonts/KaTeX_Main-Regular.ttf

67.3 KB
Binary file not shown.

static/fonts/KaTeX_Main-Regular.woff

37 KB
Binary file not shown.

static/fonts/KaTeX_Main-Regular.woff2

31.6 KB
Binary file not shown.
41.3 KB
Binary file not shown.
23.4 KB
Binary file not shown.
20.7 KB
Binary file not shown.

static/fonts/KaTeX_Math-Italic.ttf

43.4 KB
Binary file not shown.

static/fonts/KaTeX_Math-Italic.woff

24.1 KB
Binary file not shown.

static/fonts/KaTeX_Math-Italic.woff2

21.2 KB
Binary file not shown.

static/fonts/KaTeX_SansSerif-Bold.ttf

31.8 KB
Binary file not shown.
17.6 KB
Binary file not shown.
14.9 KB
Binary file not shown.
29.2 KB
Binary file not shown.
16.6 KB
Binary file not shown.
14.1 KB
Binary file not shown.
28 KB
Binary file not shown.
15.3 KB
Binary file not shown.
13 KB
Binary file not shown.

static/fonts/KaTeX_Script-Regular.ttf

23 KB
Binary file not shown.
12.7 KB
Binary file not shown.
11.5 KB
Binary file not shown.

static/fonts/KaTeX_Size1-Regular.ttf

11.7 KB
Binary file not shown.

static/fonts/KaTeX_Size1-Regular.woff

6.15 KB
Binary file not shown.
5.21 KB
Binary file not shown.

static/fonts/KaTeX_Size2-Regular.ttf

10.8 KB
Binary file not shown.

static/fonts/KaTeX_Size2-Regular.woff

5.87 KB
Binary file not shown.
4.96 KB
Binary file not shown.

static/fonts/KaTeX_Size3-Regular.ttf

6.86 KB
Binary file not shown.

static/fonts/KaTeX_Size3-Regular.woff

4.05 KB
Binary file not shown.
3.32 KB
Binary file not shown.

static/fonts/KaTeX_Size4-Regular.ttf

9.77 KB
Binary file not shown.

static/fonts/KaTeX_Size4-Regular.woff

5.68 KB
Binary file not shown.
4.61 KB
Binary file not shown.
33.8 KB
Binary file not shown.
19.2 KB
Binary file not shown.
16.5 KB
Binary file not shown.

0 commit comments

Comments
 (0)