From: Jambunathan K <kjambunathan@gmail.com>
To: Erik Hetzner <egh@e6h.org>
Cc: Org Mode <emacs-orgmode@gnu.org>, mail@christianmoe.com
Subject: zotero-cite (A Proposal)
Date: Sat, 12 Nov 2011 02:04:52 +0530 [thread overview]
Message-ID: <81k4762yab.fsf_-_@gmail.com> (raw)
In-Reply-To: <87k477hnqy.wl%egh@e6h.org> (Erik Hetzner's message of "Thu, 10 Nov 2011 09:48:53 -0800")
[-- Attachment #1: Type: text/plain, Size: 3972 bytes --]
Hello Erik
Good news.
Getting a frugal Zotero-based citations is *definitely* possible. It is
just a matter of time. Your libraries already provide the necessary
plumbing to accomplish the job.
Long story
==========
For my own understanding, I tried trimming down zot4rst to it's bare
essentials and the attached zotcite.py is the result.
What zotcite does is this:
For two Zotero Items, it prints their Bibliogrpahic entries and their
Citation Reference, in "Text" format using Chicago-Author-Date style.
I believe a commandline interface could be built around this file along
the following lines. (Will you be interested in building this interface
for us?)
$ zotcite --style chicago --format <text> --items I1, I2 --print biblio
$ zotcite --style chicago --format <text> --items I1, I2 --print citeref
Once this is done, Emacs/Org can do invoke zotcite and get the required
Bibliographic definitions and references using "shell-command".
The assumption is that Emacs/Org somehow has captured zotero keys
through org-protocol or org-zotero.el or someother means.
Here is a output from zotcite.py.
--8<---------------cut here---------------start------------->8---
$ python zotcite.py
C.UTF-8
C.UTF-8
======== KEYS ========
I4AUIZ4S
AKJZBHRW
======== ITEM_IDs ========
[6, 40]
======== BIBDATA ========
[u'Brin, S. 1999. \u201cExtracting patterns and relations from the world wide web.\u201d The World Wide Web and Databases: 172\u2013183.\n', u'Jambunathan, K. On Choice of Connection-Polynomials for LFSR-Based Stream Ciphers. In Progress in Cryptology \u2014INDOCRYPT 2000, ed. Bimal Roy and Eiji Okamoto, 1977:9-18. Berlin, Heidelberg: Springer Berlin Heidelberg. http://www.springerlink.com/content/n27yjr5eqhabux0g/.\n']
===== CITATION REFERENCE =====
(This Brin 1999 That)
--8<---------------cut here---------------end--------------->8---
IIRC, I made two changes to the export.js in your Javascript backend.
1. I had trouble understanding the organization of citation clusters. So
I modified getCitationBlock as below. Note the use of "true" as a
second param of the appendCitationCluster. This is OK as
registerItemIds already does updateItems().
--8<---------------cut here---------------start------------->8---
function getCitationBlock (citation) {
var results;
var str = "";
try {
results = zotero.reStructuredCSL.appendCitationCluster(citation, true);
} catch (e) {
zotero.debug("XXX oops: "+e);
}
// var index = citation['properties']['index'];
// for (var i = 0 ; i <= results.length ; i++) {
// // if (results[i][0] == index) {
// return escape(str + results[i][1]);
// // }
// }
return escape(results[0][1]);
}
--8<---------------cut here---------------end--------------->8---
2. There should be way to set the output format form python side of
things. I had to modify instantiateCiteProc by hand to set the output
format to "text". You know what output format that LibreOffice plugin
uses? I see "text", "html" and "rtf" as output formats. But not ODT.
See https://bitbucket.org/fbennett/citeproc-js/src/tip/src/formats.js
--8<---------------cut here---------------start------------->8---
function instantiateCiteProc (styleid) {
// Suspenders and a belt.
try {
if (!styleid) {
styleid = "chicago-author-date";
}
if (styleid.slice(0,7) !== 'http://') {
styleid = 'http://www.zotero.org/styles/' + styleid;
}
zotero.debug("XXX does this exist?: " + styleid);
var style = zotero.Styles.get(styleid);
zotero.reStructuredCSL = style.csl;
zotero.reStructuredCSL.setOutputFormat("text");
} catch (e) {
zotero.debug("XXX instantiateCiteProc oops: " + e);
}
};
--8<---------------cut here---------------end--------------->8---
Btw, I found that with my 2-day old zotero database and for printing the
above 2 keys, the whole machinery takes a perceivably a lot of time. Is
this your experience as well? I am not a netbook.
[-- Attachment #2: zotcite.py --]
[-- Type: text/plain, Size: 1920 bytes --]
"""
Module
"""
# -*- coding: utf-8 -*-
import ConfigParser
import json
import os
# Workaround for crashes seen with localename setting
print os.environ["LANG"]
os.environ["LANG"]="C.UTF-8"
print os.environ["LANG"]
import string
import sys
import jsbridge
from zot4rst.util import unquote
DEFAULT_CITATION_FORMAT = "http://www.zotero.org/styles/chicago-author-date"
# placeholder for global bridge to Zotero
zotero_conn = None;
# verbose flag
verbose_flag = False
class ZoteroConn(object):
def __init__(self, format, **kwargs):
# connect & setup
self.back_channel, self.bridge = jsbridge.wait_and_create_network("127.0.0.1", 24242)
self.back_channel.timeout = self.bridge.timeout = 60
self.methods = jsbridge.JSObject(self.bridge, "Components.utils.import('resource://csl/export.js')")
if zotero_conn is None:
zotero_conn = ZoteroConn(DEFAULT_CITATION_FORMAT)
zotero_conn.methods.instantiateCiteProc(DEFAULT_CITATION_FORMAT)
print "======== KEYS ========"
key1 = "I4AUIZ4S"
key2 = "AKJZBHRW"
print key1
print key2
print "======== ITEM_IDs ========"
itemid1 = int(zotero_conn.methods.getItemId(key1))
itemid2 = int(zotero_conn.methods.getItemId(key2))
itemids = []
itemids.append(itemid1)
itemids.append(itemid2)
print itemids
zotero_conn.methods.registerItemIds(itemids)
print "======== BIBDATA ========"
bibdata = unquote(json.loads(zotero_conn.methods.getBibliographyData()))
print bibdata[1]
print "===== CITATION REFERENCE ===== "
from xciterst import CitationInfo
citation = CitationInfo();
citation.id = "40";
citation.prefix="This";
citation.suffix="That";
citation = { 'citationItems' : [citation],
'properties' : { 'index' : 0, # zotero_conn.get_index(cluster)
'noteIndex': 0 # note_index
}}
res = zotero_conn.methods.getCitationBlock(citation)
print unquote(res)
next prev parent reply other threads:[~2011-11-11 20:35 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-11-09 2:06 zotero plain, org-odt, and citations in general Matt Price
2011-11-09 5:26 ` Jambunathan K
2011-11-10 15:17 ` Jambunathan K
2011-11-10 15:50 ` Thomas S. Dye
2011-11-10 17:48 ` Erik Hetzner
2011-11-11 15:51 ` Matt Price
2011-11-11 16:12 ` Erik Hetzner
2011-11-11 18:45 ` Matt Price
2011-11-12 0:07 ` Erik Hetzner
2011-11-12 23:45 ` Christian Moe
2011-11-12 23:46 ` Christian Moe
2011-11-11 20:34 ` Jambunathan K [this message]
2011-11-14 15:38 ` zotero-cite (A Proposal) Matt Price
2011-11-16 5:25 ` Erik Hetzner
2011-11-11 21:13 ` zotero plain, org-odt, and citations in general Jambunathan K
2011-11-12 7:21 ` Christian Moe
2011-11-12 14:20 ` Matt Price
2011-11-16 5:30 ` Erik Hetzner
2011-11-09 7:03 ` Erik Hetzner
2011-11-09 7:25 ` Jambunathan K
2011-11-09 14:13 ` Ken Williams
2011-11-09 19:39 ` Christian Moe
2011-11-10 4:53 ` Erik Hetzner
2011-11-10 9:01 ` Christian Moe
2011-11-11 15:37 ` Matt Price
2011-11-11 17:51 ` Erik Hetzner
2011-11-11 18:34 ` Matt Price
2011-11-09 15:28 ` Matt Price
2011-11-10 4:40 ` Erik Hetzner
2011-11-13 22:47 ` Christian Moe
2011-11-14 15:38 ` Matt Price
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=81k4762yab.fsf_-_@gmail.com \
--to=kjambunathan@gmail.com \
--cc=egh@e6h.org \
--cc=emacs-orgmode@gnu.org \
--cc=mail@christianmoe.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.