const md = require("markdown-it")();const mk = require("@vscode/markdown-it-katex").default;md.use(mk);// double backslash is required for javascript strings, but not html inputconst result = md.render("# Math Rulez! \n $\\sqrt{3x-1}+(1+x)^2$");
import MarkdownIt from "markdown-it";import mk from "@vscode/markdown-it-katex";import katex from "katex";// Load some katex extensionsimport "katex/contrib/mhchem";import "katex/contrib/copy-tex";const md = new MarkdownIt();md.use(mk.default, { katex });const result = md.render("# Math Rulez! \n $\\sqrt{3x-1}+(1+x)^2$");const chemResult = md.render("$\\ce{Hg^2+ ->[I-] HgI2 ->[I-] [Hg^{II}I4]^2-}$");console.log
Syntax
Math parsing in markdown is designed to agree with the conventions set by pandoc:
Anything between two $ characters will be treated as TeX math. The opening $ musthave a non-space character immediately to its right, while the closing $ musthave a non-space character immediately to its left, and must not be followedimmediately by a digit. Thus, $20,000 and $30,000 won’t parse as math. If for somereason you need to enclose text in literal $ characters, backslash-escape them andthey won’t be treated as math delimiters.
Math Syntax Support
KaTeX is based on TeX and LaTeX. Support for both is growing. Here's a list of
currently supported functions: