Skip to content

Convenient syntax for nested import #2148

@ntjess

Description

@ntjess

Description

It would be highly convenient to allow full folders to exist as local packages:

#import "@local/my-templates/proposal/nsf.typ": *

Currently, this results in the following error:

error: `templates/proposal/nsf` is not a valid package name

Use Case

I have one templates folder with several options:

templates
├───slides
|   ├───dark.typ
|   └───light.typ
└───proposal
    ├───nsf.typ
    └───sbir.typ

Currently, the best workaround is to use a relative import:

#import "../../../templates/slides/dark.typ": *

This is not ideal because (1) it is sensitive to the location of the main document and (2) requires typst to be run with --root to work.

I would love to symlink this folder to typst/packages/local and access it as a "package" to increase reusability. Even if I were to "publish" templates as a package to make this happen, it would still require "flattening" each template into something individually accessible since only one entrypoint can be specified:

#import "@local/templates:0.1.0": slides-dark
// Even so, this does not allow for star-imports of *only* the "slides/dark" template helpers

It seems like potential solutions are to:

  • Allow multiple entrypoints
  • Allow the entrypoint to be a keyword like "folder" or "none" or something similar that indicates there are subpackages
  • Allow arbitrary folders to be placed in local without complaining that they are nonconformant packages

Metadata

Metadata

Assignees

Labels

feature requestNew feature or requestgood contributionSuitable for contribution, but unlike "good first issue", it may need prior experiencepackagesAnything related to Typst package management.scriptingAbout Typst's coding capabilities

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions