Skip to content

Commit 27ae3b0

Browse files
committed
Updated mathjax parsing.
1 parent d29c479 commit 27ae3b0

3 files changed

Lines changed: 34 additions & 9 deletions

File tree

js/mathjax.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
window.MathJax = {
2+
loader: {
3+
load: ['input/tex', 'output/chtml']
4+
},
25
tex: {
3-
packages: { '[+]': ['noerrors', 'ams', 'tipa'] },
6+
packages: { '[+]': ['noerrors', 'ams', 'textmacros'] },
47
macros: {
58
qed: "\\square",
69
ran: "\\text{ran}",
@@ -25,9 +28,12 @@ window.MathJax = {
2528
proj: ["\\text{proj}_{#1}", 1],
2629
},
2730
inlineMath: [['$', '$'], ['\\(', '\\)']],
28-
displayMath: [['$$', '$$'], ['\\[', '\\]']]
31+
displayMath: [['$$', '$$'], ['\\[', '\\]']],
32+
textipa: ['{\\fontfamily{tipa}\\selectfont #1}', 1]
2933
},
3034
svg: {
3135
fontCache: 'global'
32-
}
33-
};
36+
},
37+
cthml: {
38+
},
39+
};

note.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,13 @@
1313
}
1414
})();
1515
</script>
16+
1617
<meta charset="UTF-8" />
1718
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
1819
<title>Note – Robin’s Site</title>
1920
<link rel="stylesheet" href="css/shared.css" />
2021
<link rel="stylesheet" href="css/notes.css" />
22+
<link rel="stylesheet" href="https://mirrors.ctan.org/fonts/tipa/tipa.sty/tex/tipa/fonts/tipa/tipa.css" />
2123
<meta http-equiv="Content-Security-Policy" content="default-src 'self';
2224
script-src 'self' https://cdn.jsdelivr.net;
2325
connect-src 'self';

notes/js/note.js

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,32 +71,49 @@ fetch(`/notes/courses/${course}/${noteSlug}.md`)
7171
const contentDiv = document.createElement("div");
7272
contentDiv.innerHTML = sanitize(dirty);
7373

74-
if (headingData.length) {
74+
const tocEntries = [];
75+
76+
contentDiv.querySelectorAll("h1, h2, h3, h4, h5, h6").forEach(h => {
77+
tocEntries.push({
78+
text: h.textContent,
79+
level: parseInt(h.tagName.charAt(1), 10),
80+
slug: h.id
81+
});
82+
});
83+
84+
if (tocEntries.length) {
7585
const tocNav = document.createElement("nav");
7686
tocNav.className = "table-of-contents";
7787
const ul = document.createElement("ul");
7888

79-
headingData.forEach(({ text, level, slug }) => {
89+
tocEntries.forEach(({ text, level, slug }) => {
8090
const li = document.createElement("li");
8191
li.style.marginLeft = `${(level - 1) * 16}px`;
8292

8393
const a = document.createElement("a");
8494
a.href = `#${slug}`;
8595
a.textContent = text;
8696
li.append(a);
87-
li.addEventListener("click", (e) => {
97+
98+
li.addEventListener("click", e => {
8899
e.preventDefault();
89-
document.getElementById(slug).scrollIntoView({ behavior: "smooth" });
100+
document.getElementById(slug)
101+
.scrollIntoView({ behavior: "smooth" });
90102
});
91103
ul.append(li);
92104
});
93105

94-
tocNav.appendChild(ul);
106+
tocNav.append(ul);
95107
container.prepend(tocNav);
96108
}
97109

98110
container.append(contentDiv);
99111

112+
if (window.MathJax && MathJax.typesetPromise) {
113+
MathJax.typesetPromise([container])
114+
.catch(err => console.error('MathJax typeset failed:', err));
115+
}
116+
100117
const back = document.getElementById("back-to-course");
101118
back.href = `course.html?id=${encodeURIComponent(course)}`;
102119
})

0 commit comments

Comments
 (0)