Skip to content

sveltex()

ts
function sveltex<M extends MarkdownBackend, C extends CodeBackend, T extends MathBackend>(backendChoices?: BackendChoices<M, C, T> | undefined, configuration?: SveltexConfiguration<M, C, T> | undefined): Promise<Sveltex<M, C, T>>;

Returns a promise that resolves to a new instance of Sveltex.

Important: You must await the result of this function before using the Sveltex instance.

Type parameters

  • M extends MarkdownBackend
  • C extends CodeBackend
  • T extends MathBackend

Parameters

backendChoices? BackendChoicesbase/Sveltex.ts:79

The backend choices to use for the Sveltex instance.

Backend to use for processing code blocks and inline code snippets.

  • 'shiki' (recommended): Syntax highlighting with Shiki. Install:
sh
<pnpm|bun|npm|yarn> add -D shiki
  • 'starry-night': Syntax highlighting with starry-night. Install:
sh
<pnpm|bun|npm|yarn> add -D "@wooorm/starry-night" hast-util-find-and-replace hast-util-to-html
  • 'highlight.js': Syntax highlighting with highlight.js. Install:
sh
<pnpm|bun|npm|yarn> add -D highlight.js
  • 'escape': Escape special HTML characters and curly brackets in code blocks, but don't apply syntax highlighting. By default, code blocks will be surrounded by <pre><code> tags, and inline code snippets will be surrounded by <code> tags.

The following backends do not escape special HTML characters nor curly brackets in code blocks:

  • 'none': Leave code blocks as they are. NB: Special HTML characters and curly brackets will not be escaped with this backend, and code blocks or spans will not be surrounded by any tags. Because SvelTeX

Default 'none'

Backend to use to parse Markdown. Affects extensibility.

sh
npm add -D marked
sh
npm add -D markdown-it
sh
npm add -D micromark
sh
npm add -D unified remark-parse remark-rehype remark-retext rehype-stringify

Default 'none'

Engine to use to render math (e.g., $$x^2$$).

Default

ts
`'none'`.
  • 'katex': Install:

    sh
    <pnpm|bun|npm|yarn> add -D katex
  • 'mathjax': Install:

    sh
    <pnpm|bun|npm|yarn> add -D

configuration? SveltexConfiguration<M, C, T> | undefinedbase/Sveltex.ts:80

See SveltexConfiguration.

The configuration to use for the Sveltex instance.

Returns

Promise<Sveltex<M, C, T>>

Throws: Error if the backend choices are invalid.