How to make a separate bibliography for different chapters of the thesis in one document?

2»
  • To be clear, this is absolutely possible with Zotero, it's just a bit cumbersome. I don't see this happening as built in functionality any time soon though
  • edited November 15, 2021
    Not an easy/convenient solution by any stretch, but if Zotero allows for multiple bibliographies in a document, it should be technically possible to insert a (full) bibliography at the end of each chapter and at the end of the book, and have a script run through the document xml to delete entries from the per-chapter rendered bibliographies that don't appear in that chapter.

    My personal solution: https://tex.stackexchange.com/questions/87414/per-chapter-bibliographies-in-biblatex, but I'm a TeX-head.
  • edited November 15, 2021
    It's easy enough to do manually: make each section a separate document, then manually combine them to produce a combined bibliography and combine all of those for the final report. If you need it to be automatic, that won't work, but it is possible.

    (In principle, you might also be able to write a complicated Word macro that would do this: create separate documents for each section, then import them into one main document [is that possible in a macro? or you could use a Master Document], then the macro would need to search through it for Zotero bibliography fields, which can be identified by their metadata, then take all of the references in each of those, combine them into a long list and resort and remove duplicates. I'm certain someone who knows much more about Word macros than I do could create that somehow. If you're doing this for a company, you could look into hiring someone to do it. It might not be that hard for an expert.)

    Alternatively, what about a footnote format that does have the references throughout the document, but then also adding a bibliography at the end? Maybe that's a reasonable compromise for your organization?

    Even closer, you could set Word to create endnotes at the end of each section (rather than footnotes throughout), and then also add a bibliography at the end. That's very close to what you're after. You could even set a custom mark for the endnotes so they look less like endnotes. I haven't tried all of that, but I think it could look very close. (Possible limitations: 1. what happens if you cite the same item repeatedly, it would have a separate entry in the endnotes each time; they'd also be organized by order of citation, not alphabetically; 2. you might get some interference if you're also looking to add some other unrelated footnotes or endnotes.)
  • Hi All

    Thanks for the suggestions - for the simple scenario of a thesis with several chapters I can see how this would work OK. For my (admittedly niche) challenge, I often need to create up to 100 sub-bibliographies in a document with a global bibliography of >200 citations. Often the sub-bibliographies only contain one or two citations, sometimes >20.

    As you can imagine, both of the proffered solutions aren't therefore very practical for me. (My simplest solution may very well be to continue to lobby the architects of this report to make it rather less cumbersome!)

    Thanks very much indeed to adamsmith, emilainoeheyns and djross3 for the suggestions, they are much appreciated and I am grateful for your advice and support.
  • If you typically have so few citations per section, it seems like simply using footnotes plus a final bibliography would be the easiest solution, within the standard features of Zotero. Maybe focus on lobbying for that.
  • I would like to jump in, too, and vote in favour of an option to have separate bibliographies for chapters, e.g. specific sections in WORD that are formatted accordingly.

    My use case is a teaching syllabus that is updated every year. The chapters / sections reflect the different sessions in the course, and it is absolutely not possible to work with 14 mini-documents as I am not the only one working on the doc. Colleagues update their lecture descriptions etc., and the references they put in ought to be reflected in a bibliography right below their section.

    At the moment, this is a lot of manual work -- so I support the feature request.
  • PS: if the development work is the issue and if it takes a lot of money, I will be delighted to financially support a crowd-funding campaign. I can promise that a lot of academics I know would be delighted to pay for it, too. We really don't want to go back to Endnote...
  • > it is absolutely not possible to work with 14 mini-documents as I am not the only one working on the doc.

    Could you explain your reasoning here? Why does having several contributors make several documents unpractical? I for one would think the opposite. Just being curious, not arguing...
  • One reason is that our guest lecturers and tutors change all the time, so their names need to be added in different sections of the doc. If all is in one place, searching and replacing names is very easy, but I can promise that no over-worked academic is going to open 14 individual files to update names. Also, the different sections are highly interwoven in terms of content. We give an overall course outline at the beginning and reference assignments that are later on explained down below. So if, for instance, the word count for an essay changes, that also needs to be fixed in several places. The teaching handbook is regularly exported as a PDF with hyperlinks to be provided to students and staff alongside the virtual teaching platform. This is different from editing a book which at some point has a "final" version.
  • OK, I see your point. I had assumed that each contributor would be working mostly on 1, maybe 2 sections - if it isn't the case that becomes indeed a significant burden.
  • I had a bit of spare time so looked to see if this could be done as a macro.
    There are a couple of things to consider when using the attached python script.
    1) This is for libreoffice (a linux distribution version so that the standard python could be accessed).
    2) citeproc and lxml need to be loaded into python (for a debian based distro this is probably python-citeproc)
    3) Headings need to use the basic format of Heading1 etc. This can be changed in the script if more esoteric formatting is used.
    4) If there are no citations in a chapter (aka Heading1 format) then nothing is entered.
    6) citations before the first Heading1 format are ignored.
    7) This is really only for author date reference formats. I could not see a way to maintain a link between numbers for numbered reference formats. However, you can get a list of references even if the numbers are wrong. I would suggest to change sorting to False (note the capital letter).
    8) The python is not state of the art. Mainly so that the ideas could be transferred more easily for vba for MSoffice.
    9) Formatting marks such as ttt are ignored but this should be simple enough to search and replace.
    10) The line starting with style can be simply the full path name and file name of a citation style from the Zotero directory.


    import uno
    import json
    import ast

    # Import the citeproc-py classes we"ll use below.
    from citeproc import CitationStylesStyle, CitationStylesBibliography
    from citeproc import Citation, CitationItem
    from citeproc import formatter
    from citeproc.source.json import CiteProcJSON

    style = "harvard1"

    sorting = True # True or False

    document = XSCRIPTCONTEXT.getDocument()


    def delete_previously_inserted_sections():
    vSections = document.getTextSections()
    sEventNames = vSections.getElementNames()
    for sEventName in sEventNames:
    if "Zotero_references_chapter" in sEventName:
    oSection = document.getTextSections().getByName(sEventName)
    oSectionTextRange = oSection.getAnchor()
    oSectionTextRange.setString("")
    oSection.dispose()


    def find_headings():
    """Use the search function to locate the headings and
    return a list of cursor start"""
    heading_list = []
    search_object = document.createSearchDescriptor()
    search_object.SearchRegularExpression = False
    search_object.SearchStyles = True
    search_object.SearchString = "Heading 1"
    found = document.findFirst(search_object)
    while found:
    text_cursor = found.Text.createTextCursorByRange(found)
    # m = document.Text.compareRegionEnds(text_cursor.getEnd(), text_cursor.getStart()) # less is 1, more is -1, same is 0
    heading_list.append(text_cursor.getStart())
    found = document.findNext(found, search_object)
    return heading_list



    def get_reference_marks_data(start, stop):
    reference_marks = document.ReferenceMarks
    reference_list = []
    ci = ""

    for reference_mark in reference_marks:
    m = document.Text.compareRegionEnds(reference_mark.getAnchor(), start)
    n = document.Text.compareRegionEnds(reference_mark.getAnchor(), stop)

    if m == -1 and n == 1:
    reference_mark_content = reference_mark.Name
    reference_mark_content, _ = reference_mark_content.rsplit(" ", 1)
    _, _, reference_mark_data = reference_mark_content.split(" ", 2)
    data_dictionary = json.loads(reference_mark_data, strict=False)

    for citation_items in data_dictionary["citationItems"]:
    ci = (ci + str(citation_items["itemData"]) + ",")

    ci = ci[:-1]
    ci = ("[" + ci + "]")
    return ci


    def create_bibliography(json_data):

    bib_style = CitationStylesStyle(style, validate=False)
    bib_source = CiteProcJSON(json_data)

    bibliography = CitationStylesBibliography(bib_style, bib_source, formatter.html)

    for key,value in bib_source.items():
    citation = Citation([CitationItem(key)])
    bibliography.register(citation)

    reference_list = "Chapter references"

    if sorting == True:
    for item in sorted(bibliography.bibliography()):
    item = str(item)
    reference_list = reference_list + "\r\n" + item
    if sorting == False:
    for item in bibliography.bibliography():
    item = str(item)
    reference_list = reference_list + "\r\n" + item

    return reference_list


    def insert_text_section(bib, chapter, location):
    text_cursor = document.getText().createTextCursorByRange(location)
    text_cursor.goLeft(1, False)
    name = "Zotero_references_chapter " + chapter
    doc_text = document.getText()
    section = document.createInstance("com.sun.star.text.TextSection")
    section.setName(name)
    doc_text.insertTextContent(text_cursor, section, True)
    oSection = document.getTextSections().getByName(name)
    oSectionTextRange = oSection.getAnchor()
    doc_text.insertString(oSectionTextRange, bib, True)


    def author_date_chapter_reference_tables():
    delete_previously_inserted_sections()
    heading_list = find_headings()
    items = len(heading_list) - 1
    for item in range(items, 0, -1):
    ci = ast.literal_eval(get_reference_marks_data(heading_list[item-1], heading_list[item]))
    json_data = json.loads(json.dumps(ci))
    reference_list = create_bibliography(json_data)
    if reference_list != "Chapter references":
    insert_text_section(reference_list, str(item), heading_list[item])


    g_exportedScripts = author_date_chapter_reference_tables,






  • I would like to reiterate the desire for separate chapter by chapter bibliographies. I am going to try making a separate collection for each of my chapter citations in Zotero to create distinct bibliographies that way, but it seems like a significantly more difficult step for a program that is supposed to minimize the risk of manual error by updating citations automatically.

    I am admittedly not a programmer or a software engineer but would love to see a function that could allow you to manually select the section of text that you want to make a bibliography for. With all the linked citations selected in the selected text, wouldn't the program recognize them and be able to create a bibliography out of them?
Sign In or Register to comment.