How to sort bibliography by type

I would like to know how to have the bibliography sorted in categories named after types (I use Hayagriva). The types are to be translated into the used language (can eventually be done manually)

Since CSL can only sort by macros and variables, you can’t sort by type, as it’s neither of them, IIUC.

https://docs.citationstyles.org/en/stable/specification.html#sorting

Maybe info from https://forum.typst.app/t/pergamon-biblatex-for-typst/5818 can help.

As @Andrew says: If you’re willing to use Pergamon instead of Typst’s builtin bibliography model, you can filter bibliographies by entry type. I think this is your use case, yes?

Section 4.5 of the documentation has an example that illustrates this.

Let me know if you run into any trouble.

It could work but (1) I’d like to keep the freedom of choosing Hayagriva or bib and (2) I’d like to stay standart. However your Pergamon really is an interesting project and I wish typst configuration would be possible alongside CSL in the standart bibliography model.

I then tried doing that categorizing programmatically in typst :

#let bib-select(bib, type) = {
  let sub-bib = (:)
  for (key, value) in bib {
    if value.type == type {
      sub-bib.insert(key, value)
    }
  }

  return sub-bib
}

#let bib-only(bib, type) = bytes(yaml.encode(bib-select(bib, type)))

#let bibit(bib, type, name) = {
  heading(numbering:none, level: 2, outlined: false)[#name]
  bibliography(bib-only(bib, type), full: true, title: none)
}

#heading(numbering:none, level: 1)[Bibliographie]
#let bib = yaml("bibliography.yml")

#bibit(bib, "Article", "Articles")

Now that works (naively but fine) and rightfully makes the articles category but when I tried to add a 2 more :

#bibit(bib, "Video", "Vidéos")
#bibit(bib, "Book", "Livres")

The compiler errored saying that multiple bibliographies were not allowed. That crushed my heart lol, I wanted to get over it and do actual work. Maybe I’ll look into it later and post something here.

1 Like

Thank you for your help

1 Like

Funnily enough @akoller I have found one temporary solution to be the alexandria package :frowning: (until its implemented, if it is really planned)
Thank you very much for your help