Skip to content

Commit

Permalink
feat: add support for math notation, close #7
Browse files Browse the repository at this point in the history
  • Loading branch information
hikerpig committed Sep 2, 2021
1 parent b6d878e commit ea998f4
Show file tree
Hide file tree
Showing 5 changed files with 109 additions and 1 deletion.
2 changes: 2 additions & 0 deletions _layouts/gatsby-browser.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'prism-themes/themes/prism-nord.css'

import 'katex/dist/katex.min.css'

import './src/styles/main.css'
5 changes: 5 additions & 0 deletions _layouts/gatsby-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ module.exports = {
noInlineHighlight: true,
},
})

// add math support
defaultPluginMdx.options.remarkPlugins.push(require('remark-math'))
if (!defaultPluginMdx.options.rehypePlugins) defaultPluginMdx.options.rehypePlugins = []
defaultPluginMdx.options.rehypePlugins.push(require('rehype-katex'))
return defaultPluginMdx
},
},
Expand Down
4 changes: 3 additions & 1 deletion _layouts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
"gatsby-remark-prismjs": "^5.10.0",
"gatsby-theme-kb": "^0.7.7",
"prism-themes": "^1.8.0",
"prismjs": "^1.24.1"
"prismjs": "^1.24.1",
"rehype-katex": "^5.0.0",
"remark-math": "^3.0.1"
}
}
70 changes: 70 additions & 0 deletions _layouts/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1881,6 +1881,11 @@
resolved "https://registry.npmjs.org/@types/json5/-/json5-0.0.29.tgz#ee28707ae94e11d2b827bcbe5270bcea7f3e71ee"
integrity sha1-7ihweulOEdK4J7y+UnC86n8+ce4=

"@types/katex@^0.11.0":
version "0.11.1"
resolved "https://registry.npmjs.org/@types/katex/-/katex-0.11.1.tgz#34de04477dcf79e2ef6c8d23b41a3d81f9ebeaf5"
integrity sha512-DUlIj2nk0YnJdlWgsFuVKcX27MLW0KbKmGVoUHmFr+74FYYNUDAaj9ZqTADvsbE8rfxuVmSFc7KczYn5Y09ozg==

"@types/lodash@^4.14.92":
version "4.14.168"
resolved "https://registry.npmjs.org/@types/lodash/-/lodash-4.14.168.tgz#fe24632e79b7ade3f132891afff86caa5e5ce008"
Expand Down Expand Up @@ -6672,6 +6677,11 @@ hast-util-from-parse5@^6.0.0:
vfile-location "^3.2.0"
web-namespaces "^1.0.0"

hast-util-is-element@^1.0.0:
version "1.1.0"
resolved "https://registry.npmjs.org/hast-util-is-element/-/hast-util-is-element-1.1.0.tgz#3b3ed5159a2707c6137b48637fbfe068e175a425"
integrity sha512-oUmNua0bFbdrD/ELDSSEadRVtWZOf3iF6Lbv81naqsIV99RnSCieTbWuWCY8BAeEfKJTKl0gRdokv+dELutHGQ==

hast-util-parse-selector@^2.0.0:
version "2.2.5"
resolved "https://registry.npmjs.org/hast-util-parse-selector/-/hast-util-parse-selector-2.2.5.tgz#d57c23f4da16ae3c63b3b6ca4616683313499c3a"
Expand Down Expand Up @@ -6704,6 +6714,15 @@ hast-util-to-parse5@^6.0.0:
xtend "^4.0.0"
zwitch "^1.0.0"

hast-util-to-text@^2.0.0:
version "2.0.1"
resolved "https://registry.npmjs.org/hast-util-to-text/-/hast-util-to-text-2.0.1.tgz#04f2e065642a0edb08341976084aa217624a0f8b"
integrity sha512-8nsgCARfs6VkwH2jJU9b8LNTuR4700na+0h3PqCaEk4MAnMDeu5P0tP8mjk9LLNGxIeQRLbiDbZVw6rku+pYsQ==
dependencies:
hast-util-is-element "^1.0.0"
repeat-string "^1.0.0"
unist-util-find-after "^3.0.0"

hastscript@^6.0.0:
version "6.0.0"
resolved "https://registry.npmjs.org/hastscript/-/hastscript-6.0.0.tgz#e8768d7eac56c3fdeac8a92830d58e811e5bf640"
Expand Down Expand Up @@ -7677,6 +7696,13 @@ kapsule@^1.13.4:
dependencies:
debounce "^1.2.1"

katex@^0.13.0:
version "0.13.17"
resolved "https://registry.npmjs.org/katex/-/katex-0.13.17.tgz#1f1e3d6e0f29e6bc685829d86452ea31b0c68255"
integrity sha512-Mkxj7uXs9xBRBIWGhcvf0K2c1DAbPqETjEebjur04fqJ4UXfj1ky9vrgkNJIwJJ4J4owS69vAqgBkKyr4Lh0eQ==
dependencies:
commander "^6.0.0"

keyv@3.0.0:
version "3.0.0"
resolved "https://registry.npmjs.org/keyv/-/keyv-3.0.0.tgz#44923ba39e68b12a7cec7df6c3268c031f2ef373"
Expand Down Expand Up @@ -10089,11 +10115,36 @@ regjsparser@^0.6.4:
dependencies:
jsesc "~0.5.0"

rehype-katex@^5.0.0:
version "5.0.0"
resolved "https://registry.npmjs.org/rehype-katex/-/rehype-katex-5.0.0.tgz#b556f24fde918f28ba1cb642ea71c7e82f3373d7"
integrity sha512-ksSuEKCql/IiIadOHiKRMjypva9BLhuwQNascMqaoGLDVd0k2NlE2wMvgZ3rpItzRKCd6vs8s7MFbb8pcR0AEg==
dependencies:
"@types/katex" "^0.11.0"
hast-util-to-text "^2.0.0"
katex "^0.13.0"
rehype-parse "^7.0.0"
unified "^9.0.0"
unist-util-visit "^2.0.0"

rehype-parse@^7.0.0:
version "7.0.1"
resolved "https://registry.npmjs.org/rehype-parse/-/rehype-parse-7.0.1.tgz#58900f6702b56767814afc2a9efa2d42b1c90c57"
integrity sha512-fOiR9a9xH+Le19i4fGzIEowAbwG7idy2Jzs4mOrFWBSJ0sNUgy0ev871dwWnbOo371SjgjG4pwzrbgSVrKxecw==
dependencies:
hast-util-from-parse5 "^6.0.0"
parse5 "^6.0.0"

remark-footnotes@2.0.0:
version "2.0.0"
resolved "https://registry.npmjs.org/remark-footnotes/-/remark-footnotes-2.0.0.tgz#9001c4c2ffebba55695d2dd80ffb8b82f7e6303f"
integrity sha512-3Clt8ZMH75Ayjp9q4CorNeyjwIxHFcTkaektplKGl2A1jNGEUey8cKL0ZC5vJwfcD5GFGsNLImLG/NGzWIzoMQ==

remark-math@^3.0.1:
version "3.0.1"
resolved "https://registry.npmjs.org/remark-math/-/remark-math-3.0.1.tgz#85a02a15b15cad34b89a27244d4887b3a95185bb"
integrity sha512-epT77R/HK0x7NqrWHdSV75uNLwn8g9qTyMqCRCDujL0vj/6T6+yhdrR7mjELWtkse+Fw02kijAaBuVcHBor1+Q==

remark-mdx@1.6.22:
version "1.6.22"
resolved "https://registry.npmjs.org/remark-mdx/-/remark-mdx-1.6.22.tgz#06a8dab07dcfdd57f3373af7f86bd0e992108bbd"
Expand Down Expand Up @@ -11698,6 +11749,18 @@ unified@^8.4.2:
trough "^1.0.0"
vfile "^4.0.0"

unified@^9.0.0:
version "9.2.2"
resolved "https://registry.npmjs.org/unified/-/unified-9.2.2.tgz#67649a1abfc3ab85d2969502902775eb03146975"
integrity sha512-Sg7j110mtefBD+qunSLO1lqOEKdrwBFBrR6Qd8f4uwkhWNlbkaqwHse6e7QvD3AP/MNoJdEDLaf8OxYyoWgorQ==
dependencies:
bail "^1.0.0"
extend "^3.0.0"
is-buffer "^2.0.0"
is-plain-obj "^2.0.0"
trough "^1.0.0"
vfile "^4.0.0"

union-value@^1.0.0:
version "1.0.1"
resolved "https://registry.npmjs.org/union-value/-/union-value-1.0.1.tgz#0b6fe7b835aecda61c6ea4d4f02c14221e109847"
Expand Down Expand Up @@ -11730,6 +11793,13 @@ unist-builder@2.0.3, unist-builder@^2.0.0:
resolved "https://registry.npmjs.org/unist-builder/-/unist-builder-2.0.3.tgz#77648711b5d86af0942f334397a33c5e91516436"
integrity sha512-f98yt5pnlMWlzP539tPc4grGMsFaQQlP/vM396b00jngsiINumNmsY8rkXjfoi1c6QaM8nQ3vaGDuoKWbe/1Uw==

unist-util-find-after@^3.0.0:
version "3.0.0"
resolved "https://registry.npmjs.org/unist-util-find-after/-/unist-util-find-after-3.0.0.tgz#5c65fcebf64d4f8f496db46fa8fd0fbf354b43e6"
integrity sha512-ojlBqfsBftYXExNu3+hHLfJQ/X1jYY/9vdm4yZWjIbf0VuWF6CRufci1ZyoD/wV2TYMKxXUoNuoqwy+CkgzAiQ==
dependencies:
unist-util-is "^4.0.0"

unist-util-generated@^1.0.0:
version "1.1.6"
resolved "https://registry.npmjs.org/unist-util-generated/-/unist-util-generated-1.1.6.tgz#5ab51f689e2992a472beb1b35f2ce7ff2f324d4b"
Expand Down
29 changes: 29 additions & 0 deletions math.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Math and katex

With the help of `remark-math` and `rehype-katex`, math notation is supported.

## Inline math

```
Some inline math, coming right up. $T_n = a + (n-1)d$
```

Some inline math, coming right up. $T_n = a + (n-1)d$

## Math block

Or math block:

```
$$
T_n = a + (n-1)d
$$
```

$$
T_n = a + (n-1)d
$$

Special thanks to [flashshare](https://github.com/flashshare) in [#7](https://github.com/hikerpig/foam-template-gatsby-kb/issues/7).

And a super helpful tutorial of [Adding math support to a Gatsby MDX blog | Nicky blogs](https://nickymeuleman.netlify.app/blog/math-gatsby-mdx#wiring-up-remark-math).

0 comments on commit ea998f4

Please sign in to comment.