mylloon.fr/static/js/libs/katex.js

30 lines
733 B
JavaScript
Raw Normal View History

2023-04-24 16:18:54 +02:00
window.addEventListener("load", () => {
const macros = {};
for (const item of new Map(
Object.entries({
N: "mathbb{N}",
R: "mathbb{R}",
Z: "mathbb{Z}",
O: "Theta",
ra: "rightarrow",
la: "leftarrow",
RA: "Rightarrow",
LA: "Leftarrow",
2023-12-10 19:26:20 +01:00
u: "mu",
2023-04-24 16:18:54 +02:00
})
)[Symbol.iterator]()) {
2024-04-01 17:28:17 +02:00
const bs = "\\";
macros[`${bs}${item[0]}`] = `${bs}${item[1]}`;
2023-04-24 16:18:54 +02:00
}
2024-03-31 18:05:31 +02:00
const attribute = "data-math-style";
2024-03-31 20:34:12 +02:00
for (const element of document.querySelectorAll(`span[${attribute}]`)) {
2024-03-31 18:05:31 +02:00
katex.render(element.textContent, element, {
throwOnError: false,
displayMode: element.getAttribute(attribute) === "display",
2024-04-01 17:33:33 +02:00
macros: macros,
2024-03-31 18:05:31 +02:00
output: "mathml",
});
}
2023-04-24 16:18:54 +02:00
});