-
Notifications
You must be signed in to change notification settings - Fork 16
/
katex-header.html
56 lines (54 loc) · 2.4 KB
/
katex-header.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.16.8/dist/katex.min.css" integrity="sha384-GvrOXuhMATgEsSwCs4smul74iXGOixntILdUW9XmUC6+HX0sLNAK3q71HotJqlAn" crossorigin="anonymous">
<script defer src="https://cdn.jsdelivr.net/npm/katex@0.16.8/dist/katex.min.js" integrity="sha384-cpW21h6RZv/phavutF+AuVYrr+dA8xD9zs6FwLpaCct6O9ctzYFfFr4dgmgccOTx" crossorigin="anonymous"></script>
<style type="text/css">
.katex { font-size: 1.07em; }
/* rustdoc uses "overflow-x: auto" which adds wrong scrollbars, cf. https://github.com/KaTeX/KaTeX/discussions/2942 */
.docblock > :not(.more-examples-toggle):not(.example-wrap) {
overflow-x: visible;
}
</style>
<script>
"use strict";
document.addEventListener("DOMContentLoaded", function () {
// display blocks
document.querySelectorAll('pre.language-math > code').forEach((el) => {
let p = document.createElement("p");
katex.render(el.innerText, p, {displayMode: true, throwOnError: false});
el.parentNode.parentNode.replaceChild(p, el.parentNode);
});
// inline blocks
document.querySelectorAll(':not(pre) > code').forEach((el) => {
let text = el.innerText;
if (!text.startsWith('$') || !text.endsWith('$')) {
return;
}
let span = document.createElement("span");
katex.render(text.substr(1, text.length - 2), span, {displayMode: false, throwOnError: false});
el.parentNode.replaceChild(span.firstChild, el);
});
// comment in code
document.querySelectorAll('pre span.comment').forEach((el) => {
let html = el.innerText;
let children = [];
let offset = 0;
[...html.matchAll(/(?:[^\$]|^)(\$(?:\\.|[^\$])+\$)(?!\$)/g)].forEach((match) => {
let textBefore = html.substring(offset, match.index + 1);
children.push(document.createTextNode(textBefore));
let math = match[1].substring(1, match[1].length - 1);
let span = document.createElement("span");
katex.render(math, span, {displayMode: false, throwOnError: false});
children.push(span);
offset = match.index + match[0].length;
});
if (offset == 0) {
return;
}
let textAfter = html.substring(offset);
if (textAfter.length > 0) {
children.push(document.createTextNode(textAfter));
}
while (el.firstChild) { el.firstChild.remove(); }
children.forEach((child) => el.appendChild(child));
});
});
</script>