Render katex code in marked
Note: Block level katex requires at least 2 $
at the beginning and end.
This is inline katex: $c = \\pm\\sqrt{a^2 + b^2}$
This is block level katex:
$$
c = \\pm\\sqrt{a^2 + b^2}
$$
You will still need to include the css in your html document to allow katex styles.
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/katex.min.css" integrity="sha384-bYdxxUwYipFNohQlHt0bjN/LCpueqWz13HufFEV1SUatKs1cm4L6fFgCi1jT643X" crossorigin="anonymous">
const {marked} = require("marked");
const markedKatex = require("marked-katex-extension");
// or ES Module script
// import marked from "https://cdn.jsdelivr.net/gh/markedjs/marked/lib/marked.esm.js";
// import markedKatex from "https://cdn.jsdelivr.net/gh/UziTech/marked-katex-extension/lib/index.mjs";
const options = {
throwOnError: false
};
marked.use(markedKatex(options));
marked("katex: $c = \\pm\\sqrt{a^2 + b^2}$");
Options are sent directly to katex.renderToString