Documentation
¶
Overview ¶
Package typst projects composed render manifests into a compilable Typst workspace: a main .typ file, one .typ file per fragment, and inert asset bindings an effectful collector materializes.
Index ¶
- Constants
- Variables
- func Catalog() (*component.Catalog, error)
- func DefaultKeys() []component.Key
- func Definitions() ([]component.Definition, error)
- func Project(manifest composition.RenderManifest, options Options) (latex.Projection, error)
- func Register(builder *component.Builder) error
- type Options
- type Projector
- type UnsupportedComponentError
Constants ¶
const MainFile = "main.typ"
MainFile is the workspace-relative entry point of every projection.
const Target = "typst"
Target is the dispatch target these definitions register under and the backend name the projector answers to.
Variables ¶
var ( ErrInvalidManifest = errors.New("invalid render manifest") ErrNestedSection = errors.New("section fragments must be document roots") ErrUnsupportedAsset = errors.New("unsupported artifact media type") ErrUnsupportedComponent = errors.New("component has no typst projection") )
var DiagnosticPattern = regexp.MustCompile(`(?m)([^:\n]+\.typ):(\d+):\d+:\s*([^\n]+)`)
DiagnosticPattern matches `typst compile --diagnostic-format short` lines: submatch 1 is the file (root-relative, "/fragments/x.typ"), 2 the line and 3 the severity and message.
Functions ¶
func DefaultKeys ¶
DefaultKeys are the dispatch keys the projector accepts by default: exactly the keys of Definitions.
func Definitions ¶
func Definitions() ([]component.Definition, error)
Definitions returns the Typst projections of the builtin kinds of pkg/component: text (flow), section (section) and artifact (artifact). Text props are escaped as Typst markup; they are never interpreted.
func Project ¶
func Project(manifest composition.RenderManifest, options Options) (latex.Projection, error)
Project maps composition modes to Typst source boundaries: flow -> #include, root section -> page-isolated #include, artifact -> #image of a bound asset. The result shares latex.Projection's shape so the projection generator and preview pipeline carry it unchanged.
Types ¶
type Options ¶
type Options struct {
// TrustedPreamble is emitted verbatim at the top of main.typ (set and
// show rules). Callers must not route document content through it.
TrustedPreamble []byte
// FocusSections limits the build to these root sections; flow and
// artifact roots are always kept, as LaTeX's \includeonly does.
FocusSections []string
// Supported lists the dispatch keys whose fragments hold Typst markup.
// Nil selects DefaultKeys. Any other fragment is refused by name.
Supported []component.Key
}
Options controls trusted document-level Typst and focused section builds.
type Projector ¶
type Projector struct {
// contains filtered or unexported fields
}
Projector adapts Project to the document engine's projector seam.
func NewProjector ¶
NewProjector returns a projector that renders every manifest with options; a request contributes only its focus sections.
func (*Projector) ProjectManifest ¶
func (projector *Projector) ProjectManifest(manifest composition.RenderManifest, focusSections []string) (latex.Projection, error)
ProjectManifest satisfies the engine's projector seam.
type UnsupportedComponentError ¶
UnsupportedComponentError names the component the Typst projector refused and the dispatch key it carried. It matches ErrUnsupportedComponent.
func (*UnsupportedComponentError) Error ¶
func (failure *UnsupportedComponentError) Error() string
func (*UnsupportedComponentError) Is ¶
func (failure *UnsupportedComponentError) Is(target error) bool