Export Bibliography but Preserve Hierarchy of Sub-folders?
Thanks as always for superb support and a wonderful application. Zotero is such a life saver.
My question:
Is there a way to export a bibliography that preserves the sub-folders in the result, perhaps marked by a subheading or saved as separate files, or whatever? Or a plugin that does something similar?
Let us say I have a folder with 20 sub-folders. I often like to share a list of sources broken up into sub-sections represented by folders, and would love for this to be preserved, rather than having them all end up in a single unbroken alphabetical list on export. I can currently accomplish the same result by manually by exporting each of the sub-folders separately and then merging the result with some headers to indicate each sub-topic.
My thanks in advance,
Konrad
My question:
Is there a way to export a bibliography that preserves the sub-folders in the result, perhaps marked by a subheading or saved as separate files, or whatever? Or a plugin that does something similar?
Let us say I have a folder with 20 sub-folders. I often like to share a list of sources broken up into sub-sections represented by folders, and would love for this to be preserved, rather than having them all end up in a single unbroken alphabetical list on export. I can currently accomplish the same result by manually by exporting each of the sub-folders separately and then merging the result with some headers to indicate each sub-topic.
My thanks in advance,
Konrad
I'm wondering if you could somehow rig something together with better bibtex and a pandoc-based script? Maybe @emilianoeheyns has an idea at least conceptually
defbibfilter/filter=
andkeyword=
onprintbibliography
.It is technically possible to run citeproc in translators by webpack'ing citeproc into a translator.
You can export all your collections into separate files by creating a BBT auto-export and ticking the
recursive
option after creation. After that it shouldn't be hard to create a script to create a pandoc source that creates a source for each; you can create standalone word documents for each and then use Word's multi-document feature to assemble them. You can also export your items to a BBT CSL file, and use a BBT postscript to add the collection info to the CSL items, and then use a script to break the one CSL file to multiple based on the section info you put in there, create a pandoc source document for each, etc etc.Thank you kindly both for your replies. I haven't used pandoc with bibtext before, but see it in the docs. When you say "BBT auto-export" do you mean an "auto-export" using the "zotero-better-bibtex" add-on?
If so, I will give this a shot (installing the add-on now). If indeed, in one go, all sub-folders can be exported into separate bibtext files (I'll have to see what it names those files so hopefully there is soom hook to the collection names), and these are understood by pandoc, then, as you say, the matter would simply be a script that handles the post-export loop through the files to convert and merge them together.
My thanks again,
Konrad
Indeed, when I say BBT I mean zotero-better-bibtex. The latter is a bit of a mouthful, and the fact that it covers more scenarios than Zotero's stock bibtex import/export translators (at the cost of speed and complexity) is now overshadowed by the improved workflow it provides for text-based authoring with Zotero. Also, as mentioned, it no longer just exports bibtex, and the name zotero-better-bibtex-and-csl-and-oh-yeah-citekeys-and-doc-migration-oh-wait-autoexport-and-reference-picker-and-and seemed a bit excessive.
To get all collections in one go, you need to make an export using one of the translators whose name starts with "Better " of your library or a collection, make sure to check the "keep updated" checkbox, then go into the preferences, and check "recursive" on the auto-export config it created. BBT will export each collection as a file named after the full path to the collection from the point of export (library or collection). If you have duplicate collection names under one parent (which Zotero allows, for good reasons), it is indeterminate which will overwrite which, so just don't do that.
If your library is large, you may want to set export to "on idle" rather than "on change" in the preferences.
You have already helped a lot, but if you have any thoughts on what I'm doing wrong with the CSL (though better bibtex export seems to work) I would appreciate it. The problem seems to be my use of Pandoc (2.12, OS X).
Pandoc conversion of the CSL json export (to any format) doesn't seem to work for me:
pandoc test.json --citeproc -t [insert any format here] -o test.[any format]
produces:
JSON parse error: Error in $: mempty
(however, the exported CSL seems to be valid, according to https://jsonlint.com/)
I noticed the better bibtex website (I'm guessing that is you judging by github commits to repo?) also suggested using CSL (https://retorque.re/zotero-better-bibtex/exporting/pandoc/), shame I can't get it to work.
Pandoc conversion of better-bibtex to markdown_strict seems to work fine and I'll work on a script from that to assemble the converted files into one large markdown file:
pandoc test.bib -s --citeproc -t markdown_strict -o test.md
This works, so I need merely create a shell or python script to concatenate the output of this after converting all sub-folder exports.
https://pastebin.com/KRWthHFL
Here is a test command on that file which produces the JSON parse error:
pandoc export-test.json --citeproc -t plain -o export.txt
(2.12, OS X, Better BibTex 5.2.125)
I have a clunky shell script that does what I wanted here, just in case it is of use to anyone else:
https://gist.github.com/kmlawson/3bdfd917ef55969faec7768c140dcdaa
There must be many better ways to do this, or at least better scripts. Gladly accept any improvements or easier ways to go about this.
pandoc -s --bibliography
csl-json-file.json
--citeproc --cslcsl-style.csl
source-document
-ooutput-document
#!/usr/bin/python3
import json
import sys
import os
import shlex
for src in sys.argv[1:]:
if os.path.splitext(src)[1] == '.json':
with open(src) as f:
bib = json.load(f)
md = src.replace('.json', '.md')
html = src.replace('.json', '.html')
with open(md, 'w') as f:
for entry in bib:
f.write('@' + entry['id'] + '\n')
print('pandoc -s --bibliography ' + shlex.quote(src) + ' --citeproc --csl apa.csl ' + shlex.quote(md) + ' -o ' + shlex.quote(html))
invoke as
./render.py export-test.json export-test-2.json
or./render.py export-test.json export-test-2.json | bash
if you trust the output.export-test.md
,export-test.html
,export-test-2.md
andexport-test-2.html
. It does no checking to see if these exists)I probably just didn't make things clear in the beginning. The end goal is just to easily share a list of sub-divided readings with someone.
I have a list of books in a collection, that collection has many sub collections, each with many books. I want another person (who doesn't have zotero) to get a document which contains any kind of list of info of the books in that collection divided into sub-sections. Zotero is amazing but doesn't make it easy to simply share a list of suggested readings to students and friends in a way that divides a collection up by its sub-collections. If I have a student interested in urban history and I have 1000 books and articles in a folder with lots of sub-folders according to city/theme/approach etc., there is no an easy way to share those reading suggestions with students without manually exporting each sub-collection, one at a time, or giving them an undivided dump of all 1000 entries with no division by sub-topic. While doing this once is not difficult, my collections are evolving all the time, and I'm updating them often, and sharing them often with students and colleagues. The citation format doesn't really matter, nor even the final outputted document type, all that is key is that some list of titles of works are listed in a single document, but divided by sub-topics. Ideally, one could right click on a folder "export" it, and produce a single list of readings that include sub-headings.
It is of course a very niche request so I knew there would have to be some fiddling. Thanks to your wonderful "better bibtex" plugin, I now have an easy (if multi-step) process which perfectly solves this desired task, if anyone else happens to have the same goal as me of sharing reading suggestions with people that are divided by sub-topics.
Here is what ultimately worked:
1) Install Better bibTeX. Export the folder (that has sub-folders) with Better bibTeX, checking "keep update" - export to its own empty folder to be on safe side.
2) Then go to Zotero preferences, switch to Better bibTeX "automatic export" settings and turn on "Export all child collections" - clicking that will re-export the folder again but this time it will also export every sub-folder as a separate bibTeX file.
3) navigate to the folder on the command line, which should now contain a list of .bib files there ready to be merged. After giving it execute permissions, run the gist (https://gist.github.com/kmlawson/3bdfd917ef55969faec7768c140dcdaa) from within the same folder. It will convert all bib files in the folder to markdown bibliographies in the default Chicago note formate (without need for any other "citation" source document or specifying any csl). It will then merge all those markdown files together. You can optionally uncomment two lines in there if you also want it to clean up by deleting all the exported .bib files and other .md files leaving only the final merged result.
At the end of the proces you will have a list of all sources in a collection and all its sub-collections, but these sub-divisions having headers dividing them, based on the collection names. Though clunky, that works great for now!
Thanks to both script-makers!