vspinu / zotelo

Manage zotero collections from emacsemacs.
121 stars 8 forks source link

Wrong Zotero collection IDs on different computers. #28

Open a-fent opened 8 years ago

a-fent commented 8 years ago

I am working with the same set of files and same Zotero database (synced by Zotero sync) across two different computers. I set the Zotero collection on one machine and all works well with update - this is a great library, thanks.

When I move to the other machine (the org files are kept in sync with Unison), C-u z u seems to work, but exports the wrong collection to my .bib file. Looking at the output of zotelo-set-collection with zotelo-verbose, this is because the ID numbers given to each collection are different on the two machines. The same collections, just different 1-2 digit IDs.

These IDs are drawn directly from the database (see https://github.com/zotero/zotero/blob/4dd56eadfca9b89e1728661776407337bb823ebd/chrome/content/zotero/xpcom/data_access.js#L43) but since they are simply insertion-order it seems they are not guaranteed to be stable across different synced instances of the database. Looking at the zotero.sqlite on the two computers they are indeed different.

This is basically a problem, I think, with Zotero.getCollections(), which should return the "key" field not the "id" field to identify collections uniquely and stably. In the meantime, however, it would fix the bug in zotelo not to rely on the collection ID to store the connected collection, but simply to save the name/path.

vspinu commented 8 years ago

This is unfortunate. I always thought that ID is the key. Cannot we retrieve the "key" field ourselves? Sadly I am not using zotelo that much anymore nor I have the possibility to play with zotero on multiple machines right now.

So, if you can propose a patch with a reliable identification scheme, I would be more than happy to merge it in. Thanks.

a-fent commented 8 years ago

Thanks for the reply. I had some related discussion on the Zotero forums: https://forums.zotero.org/discussion/57659/different-collection-ids-on-different-machines/

I now have an export-pull from Emacs working using the Better Biblatex add-on for Zotero (instead of using MozRepl). It has the additional advantage of being a lot faster!

I think Zotelo is a useful package so I will try to implement its interface using Better Biblatex. If I get that far you can decide if you would like to merge it, as e.g. Zotelo 2.

andersjohansson commented 8 years ago

I already hacked zotelo some years ago to use BetterBibtex. I dumped the code here now: https://gist.github.com/andersjohansson/fa7ca643782771b6e15da41514e1358a

I'm not using it myself for the moment and it isn't up to date with recent zotelo versions, but perhaps you could use it.

I'm currently using the automatic export feature of betterbibtex and think that works pretty well.

andersjohansson commented 8 years ago

I didn't really polish that code much. Some of the unneeded parts are just commented out it seems.

andersjohansson commented 8 years ago

BTW, my temporary solution for this problem was earlier to do this:

% Local Variables:
% eval: (add-to-list 'file-local-variables-alist  (list 'zotero-collection (if (quote ajjb) 331 332)))
% End:

where ajjb is a variable I defined in my init file for indicating what computer I was on (I use two):

(defvar ajjb (if (string= "ajjb" (system-name)) t nil))

331 and 332 was the two collection keys in the different databases.

But as I said before, I think it's much more reasonable to use betterbibtex in some way nowadays.

andersjohansson commented 8 years ago

BTW. You can also use zotxt to pull zotero items or collections with an arbitrary translator: http://localhost:23119/zotxt/items?key=0_QGD3SGD4&format=f895aa0d-f28e-47fe-b247-2ea77c6ed583 or http://localhost:23119/zotxt/items?collection=Calif.%20Econ%20History&format=bibtex (currently only by name I believe).

Being a heavy org-mode user I usually write in org and export to latex (or odt). With the help of zotxt and zotero-odf-scan it is even possible to make citations work correctly both in latex and odt-export (my code for doing this, recent discussion about possibly auto-exporting a bib-file based on included references in document (now implemented here)).

(Sorry for spamming, just wanting to make you aware of the several possible ways of using zotero emacs and latex together)

vspinu commented 8 years ago

Thanks for bringing all those links together. I haven't been writing that many papers recently, but this might change in the near future. So I might eventually look at how to integrate all those tools into zotelo.

In meanwhile, if you can provide backward compatible patches for whatever integration you already have I would be happy to pull those.

I already hacked zotelo some years ago to use BetterBibtex. I dumped the code here now: https://gist.github.com/andersjohansson/fa7ca643782771b6e15da41514e1358a

Looks like a right place for this is zotelo proper. It re-uses zotelo moz-repl communication. No much point for multiple versions of similar things floating around.

I think Zotelo is a useful package so I will try to implement its interface using Better Biblatex. If I get that far you can decide if you would like to merge it, as e.g. Zotelo 2.

Thanks for this, but it should be backward compatible. No need to break existent use cases for the sake of new features. I think current interface works well enough for a lot of users (myself included).

andersjohansson commented 8 years ago

Looks like a right place for this is zotelo proper. It re-uses zotelo moz-repl communication. No much point for multiple versions of similar things floating around.

But it doesn't use moz-repl. It just stores a betterbiblatex collection url and fetches it with url-copy-file ([https://gist.github.com/andersjohansson/fa7ca643782771b6e15da41514e1358a#file-emacs-zotero-bib-fetch-el-L239](see line 239)).

That is why I made kind of a "new" package of it.

But I agree everything could be integrated into zotelo. It could actually have three backends then: moz-repl, betterbibtex, and zotxt.

The problem would be with the different ways of specifying the collection, where as we have seen here ID would be ideal, but that only seems to work for betterbibtex for now.

a-fent commented 8 years ago

Thanks for all the links and suggestions. I also do a lot of writing now in org-mode so useful information. Also nice to have a proper zotelo-like using Biblatex rather than my own hack-y version (I didn't know url-copy-file ... saved about 10 lines).

Whilst it would be nice to have a single official package, it seems a fair bit of work to make it run with three different backends and identifiers. Perhaps enough to make sure people can find them -- hopefull this thread will help.