Skip to content

math.ts#

View Markdown

Source

6 documented symbols. Read the signatures first, then expand each item for parameters, return types, and examples.

6 symbols 3 functions 1 interfaces 1 types 1 modules 4 parameters 3 members 3 returns

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 &amp;lt; decodes to &lt; rather than <.

Signature

function decodeHtmlAttr(value: string): string

View source

Parameters

  • value string

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.

View source

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"

View source

interfaceMathRenderFailureOne run KaTeX refused, for the caller to report.

One run KaTeX refused, for the caller to report.

Signature

export interface MathRenderFailure

View source

Members

Properties
NameTypeDescription
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>

View source

Parameters

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 | null

View source

Returns

string | null