Skip to content

API reference

A flexible Svelte preprocessor with extensive LaTeX support.

Interfaces

InterfaceDescription
CodeConfigurationResolved configuration the CodeHandler is constructed with.
FrontmatterConfigurationControls which parts of the frontmatter block SvelTeX turns into generated code.
MarkdownConfigurationType of the configuration object used to configure the markdown processor.
MathConfigurationType of the configuration object used to configure the math processor.
SveltexThe 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.
SveltexConfigurationSveltex configuration options.
TexConfigurationConfiguration options for the TeX backend.

Functions

FunctionDescription
getDefaultCacheDirectoryThe default cache directory for SvelTeX.
getDefaultCodeConfigGet the default configuration for a given code backend.
getDefaultMarkdownConfigThe defaults SvelTeX uses for the markdown slice of its configuration when the user supplies none. The returned object's shape varies with the backend: unified gets remark/rehype/retext plugin slots, marked gets extensions, markdown-it gets a bare options, and so on. Useful for callers that need to inspect or extend the defaults programmatically.
getDefaultMathConfigGet the default configuration for a given math backend.
getDefaultSveltexConfigGet the default SvelTeX configuration options for the given backends.
getDefaultTexConfigThe defaults SvelTeX uses for the tex slice of its configuration when the user supplies none — TeX engine and arguments, the dvisvgm / Poppler conversion settings, output and cache directories, SVGO pipeline, and verbosity. Useful for callers that need to inspect or extend the defaults programmatically; most users can rely on the implicit defaults and never call this directly.
getDefaultVerbEnvConfigGet the default configuration for a given verbatim environment type.
getTexPresetDefaultsThe defaults for a SvelTeX TeX preset — the bundled, named libraries + options sets a tex-type verbatim environment can opt into via its preset configuration. The only preset shipped today is 'tikz', which loads a sensible TikZ baseline (e.g. the babel, calc, and arrows.meta libraries).
sveltexReturns a promise that resolves to a new instance of Sveltex.

Inspecting defaults programmatically

ts
import {
    
getDefaultSveltexConfig
,
getDefaultCodeConfig
,
getDefaultMarkdownConfig
,
getDefaultMathConfig
,
getDefaultTexConfig
,
getDefaultVerbEnvConfig
,
getTexPresetDefaults
,
getDefaultCacheDirectory
,
} from '@nvl/sveltex'; // The full default config for a `unified` / `shiki` / `katex` combo. const
defaults
=
getDefaultSveltexConfig
('unified', 'shiki', 'katex');
// Just the math slice, with the `'hybrid'` CSS approach. const
mathDefaults
=
getDefaultMathConfig
('mathjax', 'hybrid');
// The bundled `tikz` preset's defaults. const
tikz
=
getTexPresetDefaults
('tikz');

Each helper returns a freshly-cloned object — mutating it has no effect on subsequent calls.