A mini guide to Sort Bibliography by Reference Type

I have been trying to follow the post in which it is explained how to modify a code to sort the bibliography by reference type for days, but I have not been able to come out with any result.
http://forums.zotero.org/discussion/16531/sort-bibliography-by-reference-type/

What I need is to sort my bibliography based on Chicago manual of style (full note) by reference type. Thus, Is there some one that might write a step-by-step mini guide to to do that.

I have modified a couple of time my style, and so, although I am not quite a beginner in that, I ask to be as much clear as possible.
Thank you.
«1
  • I'll try to do this soon-ish. Remind me in a week if you haven't heard back?
  • Sure! I will do that. Thank you.
  • edited March 9, 2017
    OK, so I'll assume you're familiar with the basics of style editing - they're explained here:
    http://www.zotero.org/support/dev/citation_styles/style_editing_step-by-step
    We first start by writing a sort macro.
    Let's put this right above this line:
    <citation et-al-min="4" et-al-use-first="1" disambiguate-add-names="true">

    The basic form of this macro is this:
    <macro name="sort-key">
    <choose>
    <if type="book chapter" 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>


    You can find a list of all the csl item types and how they map to Zotero item types here: aurimasv.github.io/z2csl/typeMap.xml and can use that to make as many sort distinction as you want. The macro assigns a number to every group of item types and you can then just sort by it.

    Once you're done, 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, ie.d.
    <sort>
    <key macro="sort-key"/>
    <key macro="contributors-sort"/>
    <key variable="title"/>
    <key variable="genre"/>
    <key variable="issued"/>
    </sort>


    I believe this will sort from 1 to 3 (or whatever the highest number is). You can reverse the sort order by adding sort="ascending" into the sort key, as in:
    <key macro="sort-key" sort="ascending"/>

    Any problems let me know.
  • It works! I had to modify a bit the code as the Chicago style has already a sort macro and so you have to delete first that macro and then write what you have suggested.
    Thanks a lot!
  • why don't you put your version of the style on gist.github.com and link to it here- other people might be interested and more intimidated by the thought of modifying a style.
  • cool, thanks.
  • I am a librarian, and my patrons frequently request this type of function from Zotero. Is this Chicago style, sort by item type available anywhere? I didn't see it in the Zotero Style Repository. I thought I'd check before I try to re-create it based on the instructions included in this post.

    Thanks! Amanda
  • I don't think it's available anywhere -- the problem is that people have different needs as to which item types should be grouped into categories and I just don't see how to get this right.

    Let me know if you run into problems, feel free to e-mail me as needed.
  • I'm wondering if there is any way to have an additional layer of the search by date.

    For example, say you are referencing a thesis with a historic topic. Newspapers, books, etc, from the time (say, 1800-1900) are likely to be archival Primary Sources, whereas modern newspaper articles would be Secondary Sources.

    Is there any way to adjust the sort-key macro to take date into account?
  • no, sorry, you can't test for specific content of any field. You can, though, check whether there's anything in the archive field, which would in almost all cases be a good way to distinguish between primary&secondary sources.
  • Thanks, adamsmith! Let me have a look into the archive field, and see what I can do.
  • edited June 2, 2017
    Hi, I have a similar question too. I am working on my bibliography in the MLA format. I need to separate my sources into two different headings: "Primary sources" and "Secondary sources" that would look like this (https://i.stack.imgur.com/CdxIx.png), listing the authors' names in the alphabetical order under two separate headings. I'd be greatly appreciated if someone could kindly let me know how to nail this with Zotero.
  • The key question is how primary and secondary sources are distinguished in Zotero. Unless they have different item types or one of them consistently has a field that the other lacks (say, archive for primary sources), there's no way to do this.
  • edited June 2, 2017
    Thanks for the lightning-fast answer, adamsmith!

    I think I might not be able to do this with Zotero then. Originally I was expecting that if it's possible to add something like a code that will make Zotero to ask me whether the source to be inserted into the bibliography is a primary source or secondary source. But you seem to be saying that at the first place there must be a way to distinguish the type of the source, which I don't think there is.

    Take what I am doing now for example. Almost every item I use is either a book or a journal article. But then, say, if this book is John Milton's _Paradise Lost_, one of the most magisterial works ever of English literature, then it is definitely to be categorized as a primary source; and if it is a journal article or another book discussing _Paradise Lost_, then it is a secondary source. However, with my understanding of your question, I don't think I can do this in Zotero, right?
  • correct, not at this time, at least.
  • Got it. Will try to find out some other way to work it out. Thank you for the time!
  • Has there been any update on this?
    I would like to do the same thing that swhuang was wanting also "primary" and "secondary" in bibliography.
  • No sorry, nothing new
  • Hi Adam, I have been reading the threats relating to sorting references in bibliography and I am not clear about this: can Zoteror automatically differentiate between books, journals and reports (according to the type of document selected when inserting the reference in Zotero)?
    I am trying to get a biography that separates those documents and I cannot manage to do it, though I see that cases and statutes do appear separated from books journals and reports.

    Thank you!
  • yes, you can absolutely distinguish between books ("book" in CSL), journal articles ("article-journal") and reports ("report") -- not clear what your starting point is, but if you say where you are with your custom style, someone will likely be able to help.
  • I'm using Oscola
  • You'll have to modify the style. My post above describes how this works in general:
    https://forums.zotero.org/discussion/comment/127355/#Comment_127355

    Oscola already has some of this logic built in, that means you only have to adapt the sort-key macro to what you want.
  • Thanks Adam, this does the trick!
  • Hi Adam, is there a way to sort by a field such as court, system, etc. (basically a field that is not used for citation purposes) but used for categorization purposes in the background? I think if i could use one of these open fields in my database it would resolve my issues.
  • You could use the CSL variable “keyword” for this by adding them to Extra like this:
    Keyword: Category
  • edited October 18, 2019
    @bwiernik That opens fascinating possibilities - I can't get it to work, though.

    I've entered keyword: primary and keyword: secondary into the Extra field and then
    got a sort macro doing this, but with it called first for my bibliography, I'm not getting the sort order I want. Any ideas?


    <macro name="sort-key">
    <choose>
    <if keyword="primary">
    <text value="1"/>
    </if>
    <else-if keyword="secondary">
    <text value="2"/>
    </else-if>
    <else>
    <text value="3"/>
    </else>
    </choose>
    </macro>
  • This won't work. CSL is not smart enough to actually read and understand what is within that field. You can call it sort for it alphabetically.
  • Thanks, that's what I thought originally - ok, I'll stop trying then.
  • There is a way which is not CSL conform but it works. You'll get a warning from Zotero about the non-conformity to CSL though.

    In the "Extra" field install a new item type: "type: PERSINTERVIEW"

    then in Adam Smiths code replace the type in the sort macro with type="PERSINTERVIEW" (or whatever you name it).

    That way I was able to distinguish between general bibliography, interviews which I have done, and archival records
Sign In or Register to comment.