It is widely known that citeproc and CSL have very limited capabilities for sorting bibliographic entries (by type), due to the lack of support for type headings. After much deliberation with Proton Lumo, however, I arrived at a solution that may prove particularly useful for those using Typst through Quarto.
Example:
First, the sorting. Suppose we want to sort sources in the following order: general, software, and video. I insert the following macro in my CSL file:
<macro name="sort-group">
<choose>
<if type="software" match="any">
<text value="2"/>
</if>
<else-if type="motion_picture broadcast video" match="any">
<text value="3"/>
</else-if>
<else>
<text value="1"/>
</else>
</choose>
</macro>
I add the following code within the bibliography tag:
<sort>
<key macro="sort-group"/>
<key macro="author" sort="ascending"/>
<key variable="title" sort="ascending"/>
<key variable="issued" sort="ascending"/>
</sort>
The entries are then sorted, but headings are still missing. Therefore (since I use Biblatex), I add the following entries to the .bib file:
@software{HDR-SOFTWARE,
title = {__11HDR_SOFTWARE__},
sortname = {9999}
}
@video{HDR-FILMS,
title = {__11HDR_FILMS__},
sortname = {9999}
}
(The 11 prefix serves to push these entries above others of the same type.)
Now for the best part. To the Quarto file that uses Typst, I add the following code within the include-in-header parameter:
#show block.where(label: <ref-HDR-SOFTWARE>): it => {
v(1.5em)
heading(level: 2)[Software]
}
#show block.where(label: <ref-HDR-FILMS>): it => {
v(1.5em)
heading(level: 2)[Video]
}
Here is the result (I am using Polish).

