Sort Bibliography by Reference Type

I searched the forums and did not see a thread on this. If I overlooked it please accept my apologies.

I would like to see a feature that sorts the bibliography (with headings) by reference type, then alphabetical by author last name. For some humanities using Chicago Style we are required to format our bibliography with subheadings for reference type and under each subheading list the references alphabetically.

The most common subheadings are listed below, but there may be others for other disciplines.

Books and Scholarly Journal Articles
Newspapers and Magazines
Government Documents
Doctoral Dissertations and Masters Theses
Manuscripts and Archival Material
Audio and Video Recordings
Oral References

Thanks.
«1
  • I have the same query.

    Is there a way to do this sorting?

    Thanks.
  • actually this might be possible now, at least without the sub headings (which could then be added at the end). I'll see what I can get, but that will take a while.
  • Haven't tested, but it looks like "type" is available to the processor (it's used for conditionals like <if type="book">), so it should be possible to sort on it. However ...

    There is no "type" variable in CSL 1.0, so it would not be valid CSL, and the style code might well break if it were run on other systems. Also, the sort would be done on the underlying type identifier (so "Newspaper Article" would sort on the CSL "identifier article-newspaper"), without localization (CSL locales don't contain terms for the various item types, that label is known only to Zotero itself).
  • Correct me if I'm wrong, but the OP is actually asking for a sectioned bibliography. Sorting seems rather orthogonal.
  • The OP is asking for a sectioned bibliography - but why wouldn't it be possible to - at least mostly - get that by sorting according to a type macro? I don't think we could get section headings, but that wouldn't be unreasonable to edit in at the end.
  • edited April 9, 2011
    Well, for one thing, the types descriptions people typically use to divide a sectional bibliography often don't have a very strong relation to the Zotero or CSL types.

    I thought Frank had some experimental code for sectional bibs?
  • Thanks guys.

    But sadly, a lot of your technical language went over my head. I was hoping to have a plug-in or simple click or two to make this happen!

    I feel dumb.
  • @bdarcus, Yes, that's actually embedded in citeproc-js itself. It would take some work in the plugins and in the UI to hook it up.

    @mccorkell: The idea would be to do a rough sort of the bibliography that pretty much clusters the material in each of your target categories together (then sorting by author or date or whatever the style requires). You could then freeze a copy of the document at the last stage of production by deleting Zotero codes, and insert the headings and whatnot by hand. For the reasons given above, it's not really recommended (not because it's dangerous or anything, but because it's non-standard). The code for it would look like this (right below the <bibliography> tag):<sort>
    <key variable="type"/>
    <key macro="author"/>&lt;!-- or whatever --&gt;
    </sort>
    No guarantees, but it seems like it might work.
  • Here for general instructions
    http://www.zotero.org/support/csl_simple_edits?s[]=csl
    I suspect this won't do and we'd need further modifications, as the sort by type would, e.g. separate journal articles from books and book chapters.
  • @mccorkell - sorry about that. I was sort of doing a more technical sidebar to see if we really understood what you are asking for. Do you agree that you want a sectional bibliography (different sections, with different headings, for different types of sources)?

    If yes, I frankly don't think Zotero supports this now, and that it's probably easier to just manually reshuffle the bibliography after you're done with the document.
  • The easiest way to do this manually is to create collections or saved searches (with tags) for each section of the bibliography, then generate bibliographies from collections and paste them together in the end of the document.
  • I have the same request as Risikio, but simplified. I would only want a separate section for the Statutes and the Cases. Everything else is the residual section. These types certainly exist in Zotero and CSL. Would this also be impossible with the current CSL?

    Thanks!
  • edited May 4, 2011
    I've come around to the belief this probably isn't the domain of CSL, but rather of the bib app (in this case, Zotero/citeproc-js).

    And I don't think sections should be based on type, because often people want sections that don't really correspond to the Zotero or CSL type systems.
  • but yes, it is possible - if you want to do it yourself, create a macro (anywhere among the other macros)

    <macro name="type-sorting">
    <choose>
    <if type="case statute" match="any">
    <text value="1"/>
    </if>
    <else>
    <text value="2"/>
    </else>
    </choose>
    </macro>


    and then, in the
    section of the bibliography, which currently looks something like this:
    <sort>
    <key macro="author"/>
    <key variable="title"/>
    </sort>

    add the macro as the first parameter, i.e.
    <sort>
    <key macro="type-sorting"/>
    <key macro="author"/>
    <key variable="title"/>
    </sort>

    See here for general instructions on style changes:
    http://www.zotero.org/support/dev/citation_styles/style_editing_step-by-step
  • I pretty firmly disagree-- we have well-documented situations where citations are split into sections by type (primary source/archival source/secondary source in many places, book/thesis in the present French case) or by language (GOST styles, covering much of the former Soviet Union).

    This handling is specific to the style, and not a personal choice by the author, so CSL and its processors should explore whether this is feasible for a future revision of the language.
  • I think the question Bruce raises is not whether this should be possible - which it clearly should - but how. For example, if we keep this in csl, you won't be able to sort by tag or collection etc.

    The alternative would seem to me to, for example, handle this in the word-plugin - maybe as part of an edit-bibliography dialogue, where you could specify how many bibliographies to create, what sub-headings they should have, what they should be sorted by and, if desired, move items between bibliographies. I understand Bruce as proposing something along those lines.
  • But this will only be possible as an automatic part of styles that require it if it is included, at least in some way, in the CSL spec.

    The magic in the CSL processors that make this happen would hopefully be made flexible enough that it could support sections defined by the user and not just those defined by the style. Essentially, I'm talking about adding sectioned bibliographies with limited functionality (including grouping by language and type, although we know the latter may be a little difficult) as part of CSL.

    Additional work with sectioning, which many scholars use in large monographs, could be treated as outside the spec, could be handled by CSL processors and by Zotero and other clients without further implications for CSL. But I'd like to get the basic functionality of sectioning into the core of CSL.
  • edited May 4, 2011
    Type-based sectioning would also be very nice for generating CVs.

    While adamsmith's workaround is pretty neat, I guess it would be helpful if you could also define section headers. E.g. (not claiming this is a good idea), we could add a cs:sections element, similar to cs:sort. E.g.

    <bibliography>
    <sections>
    <section type="book thesis" header="Books"/>
    <section type="article-journal" header="Peer-reviewed Journal Papers"/>
    <section header="Other"/>
    </sections>
    </bibliography>


    The contents of each section would then be subject to the general sorting algorithm defined with cs:sort.
  • This discussion should probably be moved to xbiblio-devel (http://sourceforge.net/mailarchive/forum.php?forum_name=xbiblio-devel), since it obviously has implications beyond Zotero and is not about immediate solutions to the problem raised.

    For now, adamsmith's sorting trick is the best solution. The problem is a pretty well-known one, and I suppose we'll try to keep this and the other forum threads abreast of any developments.
  • edited May 4, 2011
    Bruce has said many times his belief that citation styles should not rely on item types. I don't know to what extent that is possible but I'm sure that zotero items should not be taken too seriously/strictly: it's a matter of flexibility.

    However, bibliographies sorted by types are quite common (at least in France). What I suggest is to rely on tags-saved searches or collection with a support of citeproc-js.

    ATM, you can put items in different collections ("Primary source"/"Secondary source") and then generate a bibliography. But it lacks automaticity: user must have put all items he cites in a collection (or tags) and create his bibliography from zotero ui.
    Do you think that would be possible (and desirable) to rely on collections/saved searches in order to create bibliographies sorted by types?
    With this option selected (e.g: something like "sort-by-collections=yes" like particle management in csl 1.0), the processor will generate the bibliography when one clicks on the "Zotero insert bibliography" but after having checked that cited items belongs to differents collections.

    The problem is that we don't use collections/tags only for that. A dialog could be useful in order to let the user decide which collections have to be taken into account.
  • I agree that an interface in Zotero for manually shifting items between sections to handle idiosyncratic sections is certainly going to be necessary, and I understand adamsmith to be saying the same.
  • I'm too slow: my idea is close to what adamsmith said, I think.
    part of an edit-bibliography dialogue, where you could specify (...) what they should be sorted by
    That could be partly automated if the plugin relies on collections/saved searches as I said.
  • edited May 4, 2011
    FWIW, what I meant more concretely was ...

    The way the bibtex world handles sectional bibs is to allow citations to be assigned to named groups ("primary", "peer-reviewed", "other", "media", "legal", whatever). This is the solution I tend to prefer, as I'm pretty certain it will prove more flexible.

    E.g. consider a CV where one needs to distinguish between peer-reviewed and non-peer-reviewed book chapters, or an article manuscript where you need a section for primary documents that includes audio tapes, photographs, and letters.
  • Hi,

    why dont´t a <text value="3"/> or 4 or 5... worked?
    it would be great

    Is somebody working on the type sorting issue? ;)

    thank you for your great work


    <macro name="type-sorting">
    <choose>
    <if type="book thesis" match="any">
    <text value="1"/>
    </if>
    <if type="article-journal article-newspaper" match="any">
    <text value="2"/>
    </if>
    </choose>
    </macro>
  • yes, that would be exactly the way to do this right now - it works well, too - the reason people are considering other ways is that separate bibliographies don't correspond to item types so there need to be other ways to assign items to those bibliographies.
  • I have problems using code snippets from here to get the following ordering: 1) not public 2) publicly available/accessible 3) published
    Here the my code
    <macro name="sort-key-bibliogroup">
    <choose>
    <if variable="archive archive_location URL" match="any">
    <text value="2"/>
    </if>
    <else-if variable="publisher edition" match="any">
    <text value="3"/>
    </else-if>
    <else>
    <text value="1"/>
    </else>
    </choose>
    </macro>

    <bibliography ... >
    <sort>
    <key macro="sort-key-bibliogroup"/>
    <key macro="sort-keysort-key"/>
    <key variable="issued"/>
    </sort>

    The output was weird; I couldn't recognize a ordering - it was looking like the ordering was coming from the ordering in the Zotero window.
  • that's impossible to diagnose. with that information.
    Why don't you add the the sort-key-bibliogroup macro as a variable before each items to see if it does what you want.

    The general idea is right.
  • edited August 25, 2011
    @fbennett: yes, I use validating of my style.
    @adamsmith: thank you to be patient with me ;-) It was late and as non-usal-coder (or experienced programmer) I had forgotten about the debug behaviour of output a function/variable and also linking to the full file.
    I had tested two upgrades of my code. To understand this better here the important code and the link to the full file:

    The base of my mod is http://www.zotero.org/styles/chicago-note-bibliography (but it is modded a lot now)

    BIBLIOGRAPHY SORTING Variant a
    Code Link http://pastebin.com/uBbARWMb
    <macro name="bibliogroup-key">
    <choose>
    <if variable="publisher ISBN edition" match="any">
    <text value="3"/>
    </if>
    <else-if variable="archive archive_location URL call-number" match="any">
    <text value="2"/>
    </else-if>
    <else>
    <text value="1"/>
    </else>
    </choose>
    </macro>
    <macro name="sort-key">
    <text macro="bibliogroup-key" suffix=" "/>
    <text macro="contributors-sort" suffix=" "/>
    <date variable="issued" suffix=" "/>
    <date variable="accessed" suffix=" "/>
    <text variable="title" suffix=" "/>
    <text variable="genre"/>
    </macro>
    ...
    <bibliography ...>
    <sort>
    <key macro="sort-key"/>
    <key variable="issued"/>
    </sort>
    <layout suffix=".">
    <group delimiter=". ">
    <text macro="sort-key"/>
    <text macro="contributors"/>
    <text macro="title"/>
    ...

    trying to insert in the layout gave me javsscript error

    BIBLIOGRAPHY SORTING Variant b
    same like in variant a, sort-key and biblio output is changed:
    Code Link http://pastebin.com/EhFmLycV

    <macro name="sort-key">
    <text macro="contributors-sort" suffix=" "/>
    ...
    <bibliography ...>
    <sort>
    <text macro="bibliogroup-key"/>
    <key macro="sort-key"/>
    <key variable="issued"/>
    </sort>
    <layout suffix=".">
    <group delimiter=". ">
    <text macro="bibliogroup-key" suffix=" "/>
    <text macro="contributors"/>
    <text macro="title"/>
    ...


    While variant a seems to not work, variant b sorts the list correctly by the group key, but the alphabetical sorting in every group is not working.
    I am tired now and thinking about giving up on this feature wish. Or can you help me find the error in thinking/coding?
  • edited September 7, 2011
    It does work now; the macro sort-key has to be limited on:
    <macro name="sort-key">
    <text macro="contributors-sort" suffix=" "/>
    </macro>

    Before there I had the date variable.
Sign In or Register to comment.