context.renderImage
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 an image reference through the current host-aware image renderer. Use it instead of constructing browser or VS Code resource URLs inside an AST rule.
Signature
context.renderImage(path: string, options?: string): stringParameters
| Parameter | Description |
|---|---|
path | LaTeX image path |
options | Optional raw \\includegraphics option text |
Returns
Direct image HTML. In the production renderer the host later resolves project resources through its normal resource pipeline.
The interface preserves options for host contexts and isolated tests. SnapTeX's current production SmartRenderer delegates only path, so a custom rule must not rely on production handling of width/scale options yet.
Call relationships
- Called by: AST figure and
\\includegraphicsrules. - Configured by:
SmartRenderer.createAstRenderContext. - Default context: emits an escaped
<img>element for isolated rule tests.
return { html: context.renderImage('figures/result.pdf', 'width=\\linewidth') };Do not construct host resource URIs inside a rule; keep path resolution in the renderer/host layer.