renderMath
How to read this API
These are TypeScript APIs compiled into SnapTeX; a .tex project cannot load them at runtime.
function name(...)is a helper that your rule imports and calls.apply(...),render(...),extract(...), andcollect(...)are callbacks that your rule implements and SnapTeX calls.renderer.name(...),context.name(...),input.name(...), anddeps.name(...)are methods SnapTeX supplies to callbacks; do not import or construct them.service.name(...)is an instance method called after your host or test constructsPreviewUpdateService.
Register extension declarations through SNAP_TEX_RULES in src/rules.ts. See Source API Scope for imports, value ownership, output safety, rebuilds, and testing.
Renders TeX through KaTeX and protects the generated HTML for the legacy Markdown pipeline. Use this imported helper inside a legacy rule; AST rules call context.renderMath instead.
Signature
ts
function renderMath(
tex: string,
displayMode: boolean,
renderer: RenderContext
): stringParameters
| Parameter | Description |
|---|---|
tex | Math body without surrounding $ delimiters |
displayMode | true for display math, false for inline math |
renderer | Current legacy rendering context |
Returns
A protected token containing KaTeX HTML, suitable for insertion into transformed legacy source.
Call relationships
- Calls: KaTeX with
renderer.currentMacrosand thenrenderer.protectHtml. - Called by: built-in math rules and custom legacy renderers.
- AST equivalent:
context.renderMath, which returns HTML directly.
text
TeX body + legacy renderer -> KaTeX -> protectHtml -> temporary legacy tokents
const token = renderMath('x^2 + y^2', false, renderer);KaTeX runs with trust: false and non-throwing error output. Do not include $...$ around tex.