Skip to content

Sveltex

The Sveltex class implements Svelte's PreprocessorGroup interface, and is the awaited return type of the sveltex method. Its most important methods are markup, which is run on the Svelte file's entire contents, and script, which is run on the content of the <script> tag in the Svelte file, after the markup method. Together, they define how the Svelte file is preprocessed.

Properties

codeBackend Cbase/Sveltex.ts:125

The code backend used by the Sveltex instance.

codePresent Record<string, boolean>base/Sveltex.ts:278

Whether code (as in code blocks or code spans) is present in the Svelte file. Used to decide whether CSS should be added to the Svelte file's <svelte:head> tag (assuming that the user has enabled the feature and is using a code backend that can make use of this feature).

configuration FullSveltexConfiguration<M, C, T>base/Sveltex.ts:598-640

See SveltexConfiguration.

Deep copy of the configuration object.

Warning Mutating this object will have no effect on the Sveltex instance.

markdownBackend Mbase/Sveltex.ts:120

The markdown backend used by the Sveltex instance.

markup MarkupPreprocessorbase/Sveltex.ts:314-333

The preprocessors are run in the following order (see Svelte docs):

  1. markup
  2. script
  3. style

mathBackend Tbase/Sveltex.ts:130

The math backend used by the Sveltex instance.

mathPresent Record<string, boolean>base/Sveltex.ts:285

Whether math is present in the Svelte file. Used to decide whether CSS should be added to the Svelte file's <svelte:head> tag (assuming that the user has enabled the feature).

name "sveltex"base/Sveltex.ts:115

The name of the preprocessor group.

script Preprocessorbase/Sveltex.ts:161-270

Svelte preprocessor for <script> blocks.

Svelte invokes this for every <script> element of a .sveltex file after markup has run. SvelTeX uses it to append the script lines that markup queued up for the file: TeX-component imports and math / code stylesheet hooks for the instance script (<script>), and the export const metadata = { … } statement derived from the file's frontmatter for the module script (<script module>).

No-op for files whose extension isn't configured for SvelTeX, and for <script> blocks the file has nothing to append to (in which case Svelte leaves the original block unchanged).

scriptLines Record<string, string[]>base/Sveltex.ts:291

Lines to add to the <script> tag in the Svelte file, e.g. import statements for the TeX components.

scriptModuleLines Record<string, string[]>base/Sveltex.ts:298

Lines to add to the <script module> tag in the Svelte file, e.g. export const statements for the metadata defined in the frontmatter.

trace (content: string, filename?: string) => Promise<{ code: string; stages: …base/Sveltex.ts:575-590

Runs the preprocessing pipeline and captures its intermediate stages.

Unlike markup, this skips the filename/extension guard and always processes content. It is intended for tooling and documentation — in particular the pipeline playground — and, like the rest of SvelTeX, never executes any code from the document; it only transforms it.