How do I specify the bib file's location via a package property/argument?

Hello, i am building a template. One of its properties (passed to with) is a path to the bib file, so that the template can display bibliography in the correct location. However, due to how relative paths work, it obviously cannot find the file that is in the consumer’s project.

So I tried to pass the file content directly, like you do for Typst files with #include. But… you can’t? So how do i let consumers specify the bib file location?

Edit: found a trick by making the consumer pass read("biblio.bib", encoding: none). Ugly but might the best typst allows right now?

That seems to be the proper way.

See How to provide assets (image files) with a template so that they could eventually be overwritten? - #3 by Andrew

In Typst 0.15.0 the path type was added. It is resolved relative to where it is called (e.g. user code) and can also be passed to packages, allowing them to read the file.

So you could now require users to provide a path to their bibliography file; this is most likely more efficient and less error-prone than your read(...) approach.
On the other hand, users might not only want to specify where to load the bibliography from, but customize it further. So you could use type(...) to determine the type of the value:

  • type path: load the bibliography from that path

  • type content: assume it represents a bibliography(...) and display it as is

Depending on how your template works, the path approach might suffice if users of your template can use set rules to customize the bibliography.

This is also what I used before 0.15! Even if users want to customize the bibiliography, path can still be an option because users can set bibliography anyway. Still, I see no reason not to allow passing bibliography as an alternative to path, so I would still support it. (You as the template author can also do set bibliography to adjust a bibliography element the user has passed, both ways should work out.)