* Towards a solution for Zotero -> Org -> ODT
I think I have a way to get Zotero references from Org links into ODT
as working reference marks. Interested parties, please
test if this works for you at all.
1. Create Zotero links such as e.g.:
: [[zotero:0_RADJMJ8Q][{Bolin, 1958}]]
Below, I include code for a simple Zotero export translator
(OrgMode.js) that will create such links at a keystroke/mouse drag,
since some of us are currently experiencing difficulties with
zotero-plain.
2. Define a custom link export function to fake a Zotero field code
for ODT. Code below.
3. Export to ODT and do the things you normally do with Zotero, like
generating a bibliography. (Note that Zotero won't let you insert a
bibliography until you've inserted at least one Zotero reference
from within LibreOffice. You can always delete it afterwards.)
If this works for you, the code (which is a quickly thrown-together
mess) can probably be improved on.
Yours,
Christian Moe
** OrgMode.js translator
Installation:
1. Tangle or copy the below to a file called "OrgMode.js".
2. Place it in the Zotero translators folder (on Mac, that's
~/Library/Application
Support/Firefox/Profiles/[PROFILENAME]/zotero/translators/
3. Restart Firefox.
4. Open Zotero > Actions (the cogwheel icon) > Preferences. From the
drop-down menu, select "Org-mode" as the Quick Copy default format.
Use: you can
- drag and drop references from the Zotero panel to the Emacs buffer,
or
- "Quick Copy" to clipboard with Shift-Cmd-C (Mac) and yank in the
Emacs buffer
#+name: OrgMode.js
#+begin_src javascript
{
"translatorID": "b0006c6f-b743-4508-beaf-490bbd68a403",
"label": "Org-mode",
"creator": "Christian Moe",
"target": "org",
"minVersion": "2.1.9",
"maxVersion": "",
"priority": 200,
"displayOptions": {
"exportCharset": "UTF-8",
"exportNotes": true,
"exportFileData": false
},
"inRepository": false,
"translatorType": 2,
"browserSupport": "gcs",
"lastUpdated": "2011-11-12 17:05:00"
}
// Loosely based on Scott Campbell's ZotSelect.js
// posted at
http://forums.zotero.org/discussion/8306/testing-zoteroselect/
function doExport() {
// Zotero.write("zotero://select//");
// Zotero.write("\n");
var item;
var notfirst = false;
while(item = Zotero.nextItem()) {
// Separate multiple links
if (notfirst) {
Zotero.write("; ")
}
// Org link path
Zotero.write("[[zotero:");
var library_id = item.LibraryID ? item.LibraryID : 0;
Zotero.write(library_id+"_"+item.key);
// Org link descr
Zotero.write("][{");
// create a unique citation key
//var descr = buildCiteKey(item, citekeys);
// write citation key
//Zotero.write("/"+citekey);
// Authorname
if(item.creators && item.creators[0] && item.creators[0].lastName) {
Zotero.write(item.creators[0].lastName);
} else {
Zotero.write("n.a.")
}
// Separator
Zotero.write(", ")
// Year
var numberRe = /^[0-9]+/;
if(item.date) {
var date = Zotero.Utilities.strToDate(item.date);
if(date.year && numberRe.test(date.year)) {
Zotero.write(date.year);
}
} else {
Zotero.write("n.d.");
}
// Close Org link
Zotero.write("}]]")
notfirst = true;
}
}
#+end_src
** Zotero link type
Evaluate the following (or place it in your .emacs for repeated use).
Note that clicking the links does not work on Mac and probably won't
work on Linux/Windows, either (but please let me know if it does!).
Consider org-zotero-open a placeholder for now.
#+begin_src elisp
(org-add-link-type "zotero"
'org-zotero-open
'org-zotero-export)
(defun org-zotero-open (path)
(browse-url (format "zotero://select//%s" path)))
(defun org-zotero-export (path desc format)
(cond
((eq format 'odt)
(let
((refmark "<text:reference-mark-start
text:name=\"%s\"/>%s<text:reference-mark-end text:name=\"%s\"/>")
(zitem "ZOTERO_ITEM
{"citationID":"%s","citationItems":[{"uri":["http://zotero.org/users/local/%s/items/%s"]}]}
%s")
(citation-id (substring (org-id-new) -10)) ; Is this a
good way to make a unique ID?
(library-id (car (split-string path "_")))
(item-key (car (cdr (split-string path "_"))))
(rnd (concat "RND" (substring (org-id-new) -10))))
(setq zitem
(format zitem
citation-id
library-id
item-key
rnd))
(setq desc (format "(%s)" desc))
(format refmark zitem desc zitem)))
(t desc)))
#+end_src