Sort a bibliography by type

Like all first year EUI historians, recently, I had to send in the first few chapters of my PhD thesis. The first part was a literature review of the published books available on my topic, while the second part was about my first period of fieldwork. Unsurprisingly, I finished writing the paper just before the deadline. The text still needed editing and the bibliography created by Zotero was listed alphabetically without any distinction between primary and secondary sources, or the type of source—whether they were journal articles, books, chapters and so on.

Manually reordering all of the final bibliography was not feasible for two reasons. First, it was simply just too time-consuming. Second, I was still editing my paper and hence still refreshing my Zotero bibliography. At each refresh I would have lost all the changes made to my document. Thus, I relied on the official Zotero forum (here) for a quicker and more definitive solution. In the rest of the post I will describe how, with the help of Zotero forum users, I resolved this problem (here the link to the discussion in the forum of Zotero). This solution requires a certain familiarity with the basics of style editing—they are explained here.

The only possible alternative was to modify the code of the citation style—in my case, the “Chicago Manual Style (full note).” What I was trying to do was to make Zotero sort my final Bibliography by Zotero reference types. So, I started with adding a sort macro right above this line:

<citation et-al-min="4" et-al-use-first="1" disambiguate-add-names="true">

The basic form of the macro is this:

<macro name="sort-key">
<choose>
<if type="book bookSection" match="any">
<text value="1"/>
</if>
<else-if type="article-journal article-magazine" match="any">
<text value="2"/>
</else-if>
<else>
<text value="3"/>
</else>
</choose>
</macro>

This macro instructs Zotero to sort all the boos and book sections quoted in my text together in alphabetic order, then to sort all the magazine and journal articles and, finally, to sort the rest of the quoted items in the same group together. It is possible to find a list of all the csl item types and how they map to Zotero item types here. You can then use that to make as many sort distinctions as you want. The macro assigns a number to every group of item types and you can then just sort by it.

The next step is to find the sort section for the bibliography. It currently looks like this:

<sort>
<key macro="contributors-sort"/>
<key variable="title"/>
<key variable="genre"/>
<key variable="issued"/>
</sort>

and add

<key macro="sort-key"/>

as the first line. The result is something like this:

<sort>
<key macro="sort-key"/>
<key macro="contributors-sort"/>
<key variable="title"/>
<key variable="genre"/>
<key variable="issued"/>
</sort>

This solution automatised an annoying and time-consuming procedure. I am now able to refresh my quotations and final bibliography every time I need without worrying about any losing any settings.