math.ts#
6 documented symbols. Read the signatures first, then expand each item for parameters, return types, and examples.
Reference#
fndecodeHtmlAttr(value: string): stringDecodes the attribute back to the TeX the author wrote. The placeholder is esca…
Decodes the attribute back to the TeX the author wrote.
The placeholder is escaped by Rust and re-serialized by the rehype passes that run before this one, and those two do not agree on a spelling — an apostrophe leaves Rust untouched and comes back from rehype as '. A general decoder covers whichever spelling arrives; chained replaceAll calls over a fixed list did not, and the leftover ' reached KaTeX as five literal characters.
One left-to-right pass, so &lt; decodes to < rather than <.
Signature
function decodeHtmlAttr(value: string): stringParameters
-
valuestring
Returns
string
modulemathBuild-time KaTeX rendering for opt-in / math. KaTeX is an optional peer. Sites that never enable math do not…
Build-time KaTeX rendering for opt-in / math.
KaTeX is an optional peer. Sites that never enable math do not install it, and the published plugin does not bundle or depend on it.
typeMathErrorPolicy = "literal" | "error" | "render"What to do with a run KaTeX cannot parse.
What to do with a run KaTeX cannot parse.
Signature
export type MathErrorPolicy = "literal" | "error" | "render"interfaceMathRenderFailureOne run KaTeX refused, for the caller to report.
One run KaTeX refused, for the caller to report.
Signature
export interface MathRenderFailureMembers
Properties
| Name | Type | Description |
|---|---|---|
block |
boolean |
Whether it was written as block math. |
message |
string |
KaTeX's own message. |
tex |
string |
The TeX between the delimiters. |
fnrenderKatexMath(html: string, onError: MathErrorPolicy = "literal", failures?: MathRenderFailure[]): Promise<string>Replaces rust ox-math placeholders with static KaTeX HTML. Leaves the escaped T…
Replaces rust ox-math placeholders with static KaTeX HTML. Leaves the escaped TeX fallback when katex is not installed.
onError decides what a run KaTeX cannot parse becomes. Prose that quotes math syntax is picked up as math by the heuristics, and the default — putting the source back the way it was written — keeps that page readable instead of stamping red error text into the middle of a sentence. Failures are collected either way, so the caller can warn.
Signature
export async function renderKatexMath(html: string, onError: MathErrorPolicy = "literal", failures?: MathRenderFailure[]): Promise<string>Parameters
-
htmlstring -
onErrorMathErrorPolicyoptional · default: "literal"
-
failuresMathRenderFailure[]optional
Returns
Promise<string>
fnresolveKatexDist(): string | nullDirectory that contains katex.min.css and fonts/, or null.
Directory that contains katex.min.css and fonts/, or null.
Signature
export function resolveKatexDist(): string | nullReturns
string | null