reddit / emacs

Using the power of Zotero in Emacs org-mode to manage citations

mpedramfar · 2022-07-06 21:10
One of the great things about Zotero is the set of [Zotero translators](https://www.zotero.org/support/translators) that is there and is being maintained. Basically for any website, e.g. arxiv.org, there is a translator that describes how to get the bibliographic data from the url. I wanted to use these translators in my Emacs setup and I came across [Zotero translation server](https://github.com/zotero/translation-server/). So I wrote a few functions to bridge between the translation server and Emacs. Now I have a bookmark in my browser that I can click to automatically export the bibtex citation of the webpage to my default bib file, basically like a [Zotero connector](https://www.zotero.org/download/connectors) for Emacs. Thought this might be useful for others, so here it is: [https://github.com/mpedramfar/zotra](https://github.com/mpedramfar/zotra)
emodario · 2022-07-06 23:52
This is too good to be true. I must try it!
sadbasilisk · 2022-07-07 01:33
This is excellent.
azfrak · 2022-07-07 03:59
Just tried it, works great, thank you. One thing I noticed on the Zotero side, is that the translation servers wouldn't work when on arXiv and looking at the pdf itself, but would work when looking at the arXiv `abs` page.ie, running it on [`https://arxiv.org/abs/1607.06450`](https://arxiv.org/abs/1607.06450) works, but [`https://arxiv.org/pdf/1607.06450.pdf`](https://arxiv.org/pdf/1607.06450.pdf) I might play with the functionality in `zotra-protocol` to do the conversion between the two when applicable so will work :)
tmting · 2022-07-07 09:34
That's like a dream coming true
RemcoProgrammer · 2022-07-07 09:57
I use Zotero for a single feature and it's already awesome for that: store a PDF in it, then read it and highlight passages, and later extract those into notes that I can edit. More integration with Emacs would be awesome.
orgtre · 2022-07-07 10:34
This is great - thanks for sharing your code! I've been using some wrappers around [biblio-zotero](https://github.com/gkowzan/biblio-zotero) to achieve similar functionality. You might find some inspiration there. That package relies on [biblio-core](https://github.com/cpitclaudel/biblio.el), but by adding `bibtex-clean-entry` to `zotra-after-add-entry-hook` one gets basically the same thing. Some tips: - Many people might want to make changes in `zotra-get-bibtex-from-json` so that `"export?format=biblatex"`. - For some journals the web translator doesn't work while things still work when proving an identifier and making use of the "Search Translation" endpoint of the Zotero transation server. All one has to do to create a function for that is change `zotra-get-json` to allow using `"/search"` instead of `"/web"`. - Finally, I've found that (on macOS at least) running the translation server via Docker is ridiculously resource intensive, but when running it via npm (as described [here](https://github.com/zotero/translation-server)) almost no resources are used and retrieving is much faster too. It is indeed great that Zotero translators are available like this. Making use of it with your package or biblio-zotero, in combination with parts of bibtex.el, Citar, biblio.el, org-cite, plus some glue and other extensions, one has a good Emacs alternative to desktop Zotero and Jabref.
psychfi · 2022-07-07 13:17
Wow. This is wonderful!
pastels_sounds · 2022-07-07 17:57
I'm not sure I understand your use case. This is for adding article to zotero when you're using a browser within emacs?
libanp · 2022-07-07 17:58
I wrote a bit of elisp to open org-ref references in zotero and there's possibly the functionality to do what you're looking for through [BetterBibtex's JSON-RPC api](https://retorque.re/zotero-better-bibtex/exporting/json-rpc/https://retorque.re/zotero-better-bibtex/exporting/json-rpc/) (maybe zotxt as well but it doesn't really have documentation). When you ask BetterBibtex/Zotero for an item's attachments it sends you all the pdf annotations as well.
mpedramfar · 2022-07-07 18:15
You're welcome :) You're right, the translation server can't handle urls to pdf files. I'm not sure if this is being worked on: [https://github.com/zotero/translation-server/issues/70](https://github.com/zotero/translation-server/issues/70) I'll fix the issue for arxiv from zotra, but it's kind of a hack, since this is the kind of thing that translators are meant to handle and I'll basically be reimplementing parts of the translator for arxiv. To fix the issue for all websites and not just arxiv, it should probably be addressed in the translation server.
mpedramfar · 2022-07-07 18:23
You might like to check out the function `malb/pdf-annot-export-as-org` in [https://github.com/malb/emacs.d/blob/master/malb.org#pdf-viewer](https://github.com/malb/emacs.d/blob/master/malb.org#pdf-viewer) . You can copy this function and `pdf-tools-org-edges-to-region` defined right above it to your init file and check it out :)
mpedramfar · 2022-07-07 18:26
I have a references.bib file and I don't have Zotero desktop. When I visit a paper/article/whatever on my browser, sometimes I like to add a reference to that to my bib file. Zotero does that with a browser plugin called Zotero connector, and adds it to Zotero database. Zotra does that with a bookmark instead of a plugin with a separate button and adds it to the bib file. Zotero connector needs Zotero desktop to be open. Zotra needs Zotero tranlation server to be running.
mpedramfar · 2022-07-07 18:36
Thanks, I didn't know of biblio-zotero, I'll check it out. Good tips, I'll add them. :)
azfrak · 2022-07-08 00:45
absolutely agree that this is something that should be done on the Zotero side, just seemed like an easy problem to address and found it a bit weird that they werent doing it, and that since using within emacs is the only time I will probably use it, Im fine with a hacky elisp solution for my purposes. Thanks again for sharing this, really appreciate it and I will definitely be using this moving forward!
mpedramfar · 2022-07-09 19:09
I added this function and the option to define more functions to handle links to PDFs for other websites. :)
mpedramfar · 2022-07-09 19:09
I updated the repo with your suggestions
Solatle · 2022-07-09 19:50
I use org and org-tangle to manage all my bibtex pieces and corresponding notes. I highly rely on [biblio.el](https://github.com/cpitclaudel/biblio.el) to search (title or author&date), download (if it is available on arxiv) and insert bibtex citation directly into my literature dot org. I just don't want to leave my emacs!
orgtre · 2022-07-10 11:52
Great, that is very helpful
azfrak · 2022-07-11 00:41
Absolutely fantastic. This is basically what I was planning on doing. Thank you so much :)
titaniumbones · 2022-07-12 15:21
I was just fiddling with a very similar pair of functions in my own config (maybe sourced from the same place back in the day). I noticed that any annotations made in evince that \*cross page boundaries\* seem to break the org export with pdf-info-query: epdfinfo: Expected a relative rectangle: -0.048611 0.9547326666666667 0.236111 1.0282923333333334 I'm assuming that the negative number in the first position messes things up somehow, but haven't had the bandwidth to dig through the edges calculations to figure out a workaround. Have you had the same issue?
titaniumbones · 2022-07-12 15:29
I'm in a very similar situation. I don't use the built-in zotero pdf reader, but I do use it to \*store\* my pdfs, and as you say, it's great for that. Does anyone see a way to use zotra or biblio-zotero to manage PDF's as well? ​ I have a bit of a hard time imagining a UI in emacs that is as good as the search in Zotero, though. The paned interface of zotero collections is powerful and pretty crucial for my workflow, teaching classes & writing different projects etc.
mpedramfar · 2022-07-12 15:36
I'm not sure. I started using it a while ago, but then changed my workflow a bit, so now I don't usually extract annotations from pdfs.
Printrea · 2022-08-10 23:17
Could you make a couple screenshots and describe this workflow? I’m relatively close to having a new attachment interface and might be able to implement a clone.
titaniumbones · 2022-09-13 13:30
Hey I missed this -- is it something you're interested in?
titaniumbones · 2022-09-13 13:31
coming back to this thread after a while -- I will just say that I am not thrilled about the new PDF note feature not saving the notes in the PDF itself. What's your workflow for extracting notes post facto?
Printrea · 2022-09-13 13:34
Yes! I put together an attachment implementation, but I don’t know what your Zotero workflow looks like.
mpedramfar · 2022-12-17 18:47
Support for attachments is now added!