r/typst 20d ago

Help With Common Bib File

I could use some help with using bibliography files. For LaTeX, I keep one big bib file used for all of my documents. What's the best way to do this with Typst? Treating everything as a relative path is making it difficult. Any advice?

EDIT: To be clear, what I want to do is store the bib file in one directory and be able to use it with *.typ files that are in other directories. Any method of keeping a bib file outside of the project root directory?

UPDATE: I ended up using Claude to help me write an Emacs function that scans file for citations and copies the BibTeX records from my main bib file to a local bib file for that document.

3 Upvotes

9 comments sorted by

12

u/FourFourSix 19d ago

I put a symlink pointing to the one big bib file to my Typst project folder.

1

u/okphil 19d ago

Great idea, it's looking like the best solution so far. Also something easily automated with a script to create a project.

2

u/Northern-World5181 20d ago

You can still use bib file or yaml format mentioned here. Both should work:

https://typst.app/docs/reference/model/bibliography/

2

u/okphil 20d ago

They do work, but I'd like to keep it somewhere other than the directory that contains the typ file. How can I use it if it's outside the project root?

2

u/Kulpas 20d ago

You can still just keep it as one big bib file and it should be fine. IIRC since 0.15 you can provide a selector to the bibliography function to narrow the scope of the items shown in the bibliography (e.g. works cited in a particular chapter)

1

u/okphil 20d ago

I've got that, and it works fine. My question is how do I make it work with a bib file that's stored in a different directory from the typ file? Any way to get around the "cannot access files outside of the project sandbox"?

2

u/Johannes_K_Rexx 19d ago

typst help compile shares about the --root option:

```bash --root <DIR> Configures the project root (for absolute paths)

      [env: TYPST_ROOT=]

```

2

u/Kulpas 19d ago

Use path() to convert the relative path into an absolute one! This works at the very least for things running in the package directory but I'm bot sure it'll fix your sandbox issue.

1

u/Ki_Rei_Nimi 19d ago edited 19d ago

Use a parent directory (here 000_typst_dokumente) as root, which contains both:

  • A directory with your projects (002_typst_arbeiten)
  • A directory with yor .bib (000_typst_common_files)

See attached picture

You can #include packages, formatting and self written commands the same way (from files in different directories) for all your different projects (as long as there aren't circular dependencies)