Created
January 21, 2021 16:59
-
-
Save recmo/abbeeffc2449ba53273fac75a074d3a7 to your computer and use it in GitHub Desktop.
Katex in mdbook
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[book] | |
authors = ["Remco Bloemen"] | |
language = "en" | |
multilingual = false | |
src = "src" | |
[build] | |
create-missing = false | |
[preprocessor.html] | |
command = "python3 html.py" | |
renderer = ["html"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import json | |
import sys | |
if len(sys.argv) > 1: | |
if sys.argv[1] == 'supports': | |
# sys.argv[2] is the renderer name | |
sys.exit(0) | |
html = '\n' + open('katex-header.html', 'r').read() | |
context, book = json.load(sys.stdin) | |
def fix(items): | |
for section in items: | |
if 'Chapter' in section: | |
section['Chapter']['content'] += html | |
fix(section['Chapter']['sub_items']) | |
fix(book['sections']) | |
json.dump(book, sys.stdout) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/katex.min.css" | |
integrity="sha384-zB1R0rpPzHqg7Kpt0Aljp8JPLqbXI3bhnPWROx27a9N0Ll6ZP/+DiW/UqRcLbRjq" crossorigin="anonymous"> | |
<script defer src="https://cdn.jsdelivr.net/npm/[email protected]/dist/katex.min.js" | |
integrity="sha384-y23I5Q6l+B6vatafAwxRu/0oK/79VlbSz7Q9aiSZUvyWYIYsd+qj+o24G5ZU2zJz" | |
crossorigin="anonymous"></script> | |
<script defer src="https://cdn.jsdelivr.net/npm/[email protected]/dist/contrib/auto-render.min.js" | |
integrity="sha384-kWPLUVMOks5AQFrykwIup5lo0m3iMkkHrD0uJ4H5cjeGihAutqP0yW0J6dpFiVkI" | |
crossorigin="anonymous"></script> | |
<script> | |
document.addEventListener("DOMContentLoaded", function () { | |
renderMathInElement(document.body, { | |
fleqn: false, | |
macros: { | |
"\\F": "\\mathbb{F}", | |
"\\O": "\\mathcal{O}", | |
"\\(": "\\left(", | |
"\\)": "\\right)", | |
"\\norm": "\\left\\vert #1 \\right\\vert", | |
"\\set": "\\mathcal{ #1 }", | |
"\\floor": "\\left\\lfloor{ #1 }\\right\\rfloor", | |
"\\ceil": "\\left\\lceil{ #1 }\\right\\rceil", | |
"\\mod": "\\left\\[{ #1 }\\right\\]", | |
}, | |
delimiters: [ | |
{ left: "$$", right: "$$", display: true }, | |
{ left: "\\(", right: "\\)", display: false }, | |
{ left: "$", right: "$", display: false }, | |
{ left: "\\[", right: "\\]", display: true } | |
] | |
}); | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment