MarkedJS extesion to render katex
npm install marked-katex-extensionRender katex code in marked
``markdown
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.
`html`
`js
import {marked} from "marked";
import markedKatex from "marked-katex-extension";
// or in the browser
//
//
//
//
const options = {
throwOnError: false
};
marked.use(markedKatex(options));
marked.parse("katex: $c = \\pm\\sqrt{a^2 + b^2}$");
`
You can include newlines in block level katex. Block level katex must contain starting and ending delimiters on their own line.
`js
marked.parse(
$$
\\begin{array}{cc}
a & b \\\\
c & d
\\end{array}
$$);`
displayMode will be on by default when using two dollar signs ($$) in inline or block katex. And it will be off by default for a single dollar sign ($) in inline or block katex.
If you want to be able to parse mathematical formulas in non-standard markdown format, that is, without spaces before and after $ or $$, you can turn on the nonStandard option.
`js
import {marked} from "marked";
import markedKatex from "marked-katex-extension";
const options = {
nonStandard: true
};
marked.use(markedKatex(options));
marked.parse(
afdaf$x=x^2$4$x=x^2$
$$
x = x^2
$$);`
Options are sent directly to katex`