@jaewangl/markdown-it-qutex
v0.1.0
Published
markdown-it plugin rendering $…$ and $$…$$ math to MathML with Qutex, with country-specific notation (ko, ja)
Maintainers
Readme
markdown-it-qutex
markdown-it plugin that renders
$…$ and $$…$$ math to MathML with Qutex,
including Qutex's country-specific school notation (locale, default "ko").
It is a port of markdown-it-math/temml from
markdown-it-math 6.0.1: the same
tokenizer and options, with Qutex instead of Temml as the renderer.
npm install markdown-it @jaewangl/markdown-it-qutex @jaewangl/qutex@jaewangl/qutex is a dependency of this plugin; install it directly as well when you
import its stylesheet.
Usage
import markdownIt from "markdown-it";
import markdownItQutex from "@jaewangl/markdown-it-qutex";
import "@jaewangl/qutex/qutex-lite.css"; // or @jaewangl/qutex/qutex.css (adds Noto Serif KR for Korean in math)
const md = markdownIt().use(markdownItQutex, {
locale: "ko", // default
qutexOptions: { macros: { "\\R": "\\mathbb{R}" } },
});
md.render(String.raw`$\binom{5}{2}=10$ 이고 $a\geq b$ 이다.`);
// ₅C₂ = 10, a ≥ b (Korean notation)| Locale | \binom{n}{k} | \geq, \geqq, \geqslant | \leq, \leqq, \leqslant |
| --- | --- | --- | --- |
| ko (default) | ₙCₖ | ≥ | ≤ |
| ja | ₙCₖ | ≧ | ≦ |
| tex | (n k) | unchanged | unchanged |
See the Qutex README
for the complete rules. BCP 47 tags such as ko-KR and ja-JP resolve by
language; an unsupported locale throws when the plugin is installed.
To choose the locale per render with one shared parser:
md.render(source, { qutexLocale: "ja" });Options
| Option | Default | |
| --- | --- | --- |
| locale | "ko" | Qutex locale (also read from qutexOptions.locale). |
| qutexOptions | {} | Passed to qutex.renderToString (macros, annotate, maxExpand, maxSize, …). displayMode is set per formula. Macros never carry between formulas. |
| errorRenderer | escaped source | (src, { displayMode, error, open, close, token, md }) => html for a formula Qutex cannot render. |
| inlineDelimiters | ["$", ["$`", "`$"]] | Empty turns inline math off. |
| inlineAllowWhiteSpacePadding | false | Allow $ x $. |
| blockDelimiters | "$$" | Empty turns block math off. |
| inlineCustomElement, blockCustomElement | | Emit the source in a custom element instead of MathML. |
| inlineRenderer, blockRenderer | Qutex | (src, token, md, env) => html to replace the renderer. |
Qutex always runs with trust: false and throwOnError: true. A formula that
fails to parse, or uses an untrusted command such as \href, is shown as its
escaped source with delimiters (<span class="qutex-error">$…$</span>, or a
div for block math), so one broken formula never hides a message and literal
dollar signs survive. Raw HTML stays under markdown-it's own html option.
Inline math follows markdown-it-math's rules: no whitespace right after the
opening or before the closing delimiter, so $ 5 $ and prices like
20,000원 $ stay text.
License
MIT. Portions derived from markdown-it-math, Copyright (c) 2015 Rúnar Berg Baugsson Sigríðarson (MIT); see LICENSE.
