[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [O] zotero plain, org-odt, and citations in general

From: Christian Moe
Subject: Re: [O] zotero plain, org-odt, and citations in general
Date: Sun, 13 Nov 2011 23:47:12 +0100
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:5.0) Gecko/20110624 Thunderbird/5.0

* 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

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.

Christian Moe

** OrgMode.js translator


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,
- "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
        var library_id = item.LibraryID ? item.LibraryID : 0;

        // Org link descr
        // create a unique citation key
        //var descr = buildCiteKey(item, citekeys);
        // write citation key

        // Authorname
        if(item.creators && item.creators[0] && item.creators[0].lastName) {
        } else {
        // 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)) {
        } else {

        // Close Org link
        notfirst = true;

** 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"

  (defun org-zotero-open (path)
    (browse-url (format "zotero://select//%s" path)))

  (defun org-zotero-export (path desc format)
     ((eq format 'odt)
((refmark "<text:reference-mark-start text:name=\"%s\"/>%s<text:reference-mark-end text:name=\"%s\"/>") (zitem "ZOTERO_ITEM {&quot;citationID&quot;:&quot;%s&quot;,&quot;citationItems&quot;:[{&quot;uri&quot;:[&quot;http://zotero.org/users/local/%s/items/%s&quot;]}]} %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
        (setq desc (format "(%s)" desc))
        (format refmark zitem desc zitem)))
     (t desc)))

reply via email to

[Prev in Thread] Current Thread [Next in Thread]