Skip to content

context.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 math to direct KaTeX HTML in AST mode. The AST renderer supplies context when it calls your rule.

Signature ​

ts
context.renderMath(tex: string, displayMode: boolean): string

Returns ​

KaTeX HTML using the current document macros. Unlike legacy renderMath, this result is not a protection token.

Call relationships ​

  • Calls: KaTeX with the current AST render context macros.
  • Called by: AST math rules and inline rendering callbacks.
text
TeX body + current macros -> context.renderMath -> final KaTeX HTML
ts
const mathHtml = context.renderMath('x^2', false);
return { html: mathHtml };

Do not wrap the result in legacy protectHtml; AST output bypasses Markdown.

See also ​

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