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

36 lines
847 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]()) {
macros[`\\${item[0]}`] = `\\${item[1]}`;
}
document.querySelectorAll("span[data-katex]").forEach((element) => {
const rawLaTeXFormula = element.getAttribute("data-katex");
const displayMode = rawLaTeXFormula.startsWith("$$");
const strip = displayMode ? 2 : 1;
katex.render(
rawLaTeXFormula.slice(strip, rawLaTeXFormula.length - strip),
element,
{
throwOnError: false,
macros,
displayMode,
output: "mathml",
}
);
2023-04-24 16:18:54 +02:00
});
});