Skip to content

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(...), and collect(...) are callbacks that your rule implements and SnapTeX calls.
  • renderer.name(...), context.name(...), input.name(...), and deps.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 constructs PreviewUpdateService.

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
): string

Parameters ​

ParameterDescription
texMath body without surrounding $ delimiters
displayModetrue for display math, false for inline math
rendererCurrent legacy rendering context

Returns ​

A protected token containing KaTeX HTML, suitable for insertion into transformed legacy source.

Call relationships ​

  • Calls: KaTeX with renderer.currentMacros and then renderer.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 token
ts
const token = renderMath('x^2 + y^2', false, renderer);

KaTeX runs with trust: false and non-throwing error output. Do not include $...$ around tex.

See also ​

A fast structural preview, not a replacement for a full TeX compiler.