Using Overleaf with Zotero
2019-07-05

Overleaf is an online latex editor that allows collaboration, and I don't think there is an alternative to it at the moment. Zotero is one of those bibliography management tools; although other alternatives exist, I find it the most intuitive.

The way to import Zotero references into Overleaf is to create a .bib file from your personal Zotero library, which contains references from all your collections and can be refreshed to sync any changes you made to your personal library [1]. But there is no way to import only from a single collection or a Zotero group library. When multiple people want to use a Zotero group to track the references and an Overleaf project for collaborative writing, unless they are okay with large .bib files, they would need to manually export the group library into a .bib file and upload it to their Overleaf project to keep things in sync.

But I really want to use Overleaf with Zotero groups! If you have the same thought and have Python installed, the following workaround could be helpful:

  1. Git clone your Overleaf project as a git repository locally [2].
  2. Open your Overleaf project in a browser and click open Menu. Under Sync, click open Git. This will open a pop-up that tells you how to git clone your project. Then run this command from the command line; follow the linked tutorial to complete the process.

  3. Write a script that can automatically read a Zotero group library and export it to .bib.
  4. I followed [3] (about how to obtain api key and libray id) and [4]. Below is the Python script output_bib.py:

    from pyzotero import zotero import bibtexparser api_key = 'REPLACE: your own api key' library_id = 'REPLACE: your own library id' library_type = 'group' zot = zotero.Zotero(library_id, library_type, api_key) zot.add_parameters(format='bibtex', style='REPLACE: your own style') bib_db = zot.top() with open('references.bib', 'w') as bibtex_file: bibtexparser.dump(bib_db, bibtex_file)

    The dependencies can be installed from command line with

    pip install pyzotero pip install bibtexparser
  5. Use the job scheduler on your OS to run the previous script regularly and push to git.
  6. I'm on Mac OS, so I followed [5] (tutorial on launchd). Below is the plist file com.myx.pushbibupdates.plist:

    <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>Label</key> <string>com.myx.pushbibupdates</string> <!-- replace the name! --> <key>ProgramArguments</key> <array> <string>sh /REPLACE/path/to/push_bib_updates.sh</string> </array> <key>StartInterval</key> <integer>43200</integer> <!-- 12 hours --> <key>StandardErrorPath</key> <string>/tmp/PushBibUpdates1.err</string> <key>StandardOutPath</key> <string>/tmp/PushBibUpdates1.out</string> </dict> </plist>

    And the shell script push_bib_updates.sh:

    git pull python3 output_bib.py git add references.bib git commit -m "routine: push bib updates (if any)" git push

    Now we are ready to schedule this task. Note that in my case the shell script and the Python script live in the git repository, and the plist file lives in $HOME\Library\LaunchAgents. As the linked tutorial shows, we can use the following commands to load and unload the task (specific to my case):

    launchctl load com.myx.pushbibupdates.plist launchctl list | grep 'myx' launchctl unload com.myx.pushbibupdates.plist launchctl list | grep 'myx'

That's it!

Finally, this is a very simple workaround with absolutely no error handling. If you intend to try it, please be very careful!


Update on May 25, 2020: thanks to Christian Møldrup Legaard, we now have an easier workaround by directly using the url generated by pyzotero! If your group is public, sending a request to this URL should return the bibliography in bibtex format: https://api.zotero.org/groups/INSERT_GROUPID/items/top?format=bibtex&style=numeric&limit=100. Then you can use this url to create a new file directly in Overleaf as shown in the screenshot.


Blog Home. Prev: None. Next: Student Volunteer at SIGGRAPH 2019.