Skip to content

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(...), 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 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 ​

ts
context.renderImage(path: string, options?: string): string

Parameters ​

ParameterDescription
pathLaTeX image path
optionsOptional 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 \\includegraphics rules.
  • Configured by: SmartRenderer.createAstRenderContext.
  • Default context: emits an escaped <img> element for isolated rule tests.
ts
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.

See also ​

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