If we really insist on plopping a package or template file in some arbitrary directory as a repository for useful functions, on our own heads be it.
As a brief comment, I wanted to mention that this is already possible. Consider the project structure below:
project
├── some
│ └── sub
│ └── folder
│ └── file.typ
└── template.typ
You can import your template from anywhere in your project easily through /absolute/paths/from/project/root
, by just adding the line at the top of the file.typ
example below:
// template.typ
#let func(x) = [Hello #x]
// file.typ
// Note the '/' before template.typ
// Works at any level of nesting
#import "/template.typ": *
// Can use
#func[ABC ABC ABC]
I’d consider this equivalent to a per-project preamble (even more flexible than that, actually, since you can pick what to import, import multiple files or a different file, and so on).
You can even use symlinks here if you want template.typ
to point at some arbitrary file in your system which could change depending on a script you write (for example).
So the desired functionality is retained, just in a way that is more integrated with the Typst language, and also more readable and portable as was already mentioned.