Integrate Zotero with Trilium

- w
2025-04-28

Trilium is a powerful note-taking software. Zotero is another excellent tool for scientific research and document management software. However, there aren't any plugins that combine both as of now. I tried to use Zotero's HTTP citing protocol to make a script in Trilium, but there aren't many documents about this protocol, and I have a hard time finding where the error comes from.

Then I found a GitHub repo liuxiawei/Trilium_zotero_plugin, which uses an easy way to generate citations from Zotero desktop. Thanks to this repo, I have the idea to add some more functions and polish the citation style.

Mechanism

The generation of the citation done in liuxiawei/Trilium_zotero_plugin  is using the Better Bibtex's CAYW URL (you can see the documentation here). This is much simpler compared to Zotero's HTTP citing protocol. In order to use this, you must install Better Bibtex in Zotero first. Then you need to create a front-end script and add #run=frontendStartup so the shortcut will be set when you open Trilium.

When you press Alt+Shift+X, a request will be sent to Zotero using the CAYW URL and you will see the citation dialog of Zotero. After you finish choosing the documents, this URL will return a JSON. The JSON will be further processed to generate a citation in author-year format. Multiple citations will be separated by ;.

Added Functionality

Based on the repo liuxiawei/Trilium_zotero_plugin, I made two changes. One is minor, to improve the author-year format; the other is to be able to scan the document and generate a bibliography at the end of the document. You can access my fork here.

Polished Author-Year Format

The original repo uses the author-date format, but I prefer author-year, which is more standard. So in the script, I interpret the date string first and try to extract the year from the string. If this information is not available, either the original string is returned or n.d. (no date) is generated.

In addition, the hyperlink related to each citation will be a zotero:// link. Clicking on it will navigate to the item in your Zotero desktop.

Adding Bibliography

The bibliography is done by scanning the document for specific HTML tags. The scanning is done in the front-end. Then the IDs of Zotero elements will be stored and sent to Better Bibtex's JSON-RPC (see the documentation here). Finally, a bibliography list will be inserted in the cursor position. You can trigger this function using Alt+Shift+B.

Limitations: if you want to update the bibliography, you need to delete the original one. There is no automatic process for updating currently. At least I haven't done one.

An example of a text note with citation and bibliography is shown below.

Alt text
An example of a text note with citations and bibliography.

Summary

Zotero and Trilium are both powerful tools. Integrating Zotero in Trilium is essential for me as a researcher. Thanks again to the author of liuxiawei/Trilium_zotero_plugin  for the initial attempt of integrate Zotero with Trilium.


Content