From mboxrd@z Thu Jan 1 00:00:00 1970 From: Christian Moe Subject: Re: Let's discuss citation and Org syntax Date: Wed, 22 May 2013 11:02:04 +0200 Message-ID: References: <878v38cylw.fsf@pank.eu> <87zjvobjve.fsf@pank.eu> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from eggs.gnu.org ([208.118.235.92]:32909) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Uf4sl-0007Ua-Ao for emacs-orgmode@gnu.org; Wed, 22 May 2013 04:58:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Uf4sj-0000ga-OF for emacs-orgmode@gnu.org; Wed, 22 May 2013 04:58:51 -0400 Received: from mail-forward2.uio.no ([129.240.10.71]:41025) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Uf4sj-0000HT-9E for emacs-orgmode@gnu.org; Wed, 22 May 2013 04:58:49 -0400 Received: from exim by mail-out2.uio.no with local-bsmtp (Exim 4.75) (envelope-from ) id 1Uf4s6-0001MC-Kq for emacs-orgmode@gnu.org; Wed, 22 May 2013 10:58:10 +0200 In-reply-to: <87zjvobjve.fsf@pank.eu> List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Rasmus Cc: emacs-orgmode@gnu.org --=-=-= Content-Type: text/plain Hi, I'd be cool with a dedicated citation syntax, or using a yet-to-be-introduced extensible syntax for citations. But link syntax does make sense to me -- after all, citations do point to things. And unlike one of the opinions you cited, I think link descriptions *are* meaningful in citations, and can be made more meaningful yet (code attached). First, with links, you can have an easily human-readable reference in the description, and the link keyword and citekey tucked away, e.g. as you note: > [[cite:jones-etal-2000][Jones et al., 2000]] That makes for a better authoring experience when revising your document months or years later. Sure, Bibtex users usually keep their citekeys mnemonic. However, there are alternatives to Bibtex, and people will increasingly be keying their references to very non-mnemonic DOIs, Zotero IDs or other database keys, etc. But second, and more interesting: Parsing the description part as meaningful would also let us think outside the latex box and handle things like page numbers and post-notes a bit more intuitively. The following is an example of thinking like latex: > So, a possible extension of that could, for instance, > use a third pair of [] as in > [[cite:jones-etal-2000][Jones et al., 2000][[citationcommand][prenote][postnote]]] > ^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^ > key displayed in org Why should the prenote go nearly at the end? Do we really to add a citation command? (Or define a bunch of different link types, one for each citation command, as in Thomas S. Dye's excellent setup?) And do we need all those brackets anyway? My preference would be to write something like: [[cite:jones2000][(see further: Jones et al., 2000: p.18)]] and use a simple algorithm and a smidgen of extra processing power to make sense of different human-meaningful forms of description, so that e.g.: [[cite:jones2000][(2000: p.17)]] becomes a \citeyear [[cite:jones2000][Jones, 2000]] without round parens becomes a \citet etc. I have a rough, working example of this enabling Zotero cites for ODT export (attached). I've been meaning to polish it up as a contributed module for Zotero users, but if there's interest in a unified citation syntax along these lines, I could rewrite it to work for Bibtex as well. Yours, Christian Moe --=-=-= Content-Type: application/emacs-lisp Content-Disposition: attachment; filename=org-zotero-export.el Content-Transfer-Encoding: quoted-printable ;;; org-zotero-export --- export Zotero cites to ODT ;; ;; Copyright (C) 2013 Christian Moe ;; ;; This program is free software; you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by ;; the Free Software Foundation; either version 3, or (at your option) ;; any later version. ;; ;; This program is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;; GNU General Public License for more details. ;; ;; You should have received a copy of the GNU General Public License ;; along with this program; if not, write to the Free Software ;; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. ;; ;;; Comments: ;;=20 ;; Adds a zotero link type. The path is the Zotero item ID. The ;; description is parsed to determine how Zotero should format the ;; citation. The description should be in the format: ;;=20 ;; (prenote: author, date: p.number: postnote)=20 ;; ;; e.g. ;; ;; (Jones et al., 2000) ;; (see: Jones et al., 2000: p.24:, see also the update) ;; (2000: p.47) ;; ;; Only the date is required, all other parts are optional. The date ;; must be a four-digit year or "n.d.". Page numbers, if supplied, ;; should be prefixed with "p." to distinguish them from other ;; post-notes. ;;=20 ;; Multiple citations are allowed: ;; ;; [[zotero:0_T3U33WR8;0_WMNA92GP][(McCright, 2011: p.5; Washington, 2011= : p.26)]]. ;; ;; As an experimental hack, org-zotero can fake textual cites though ;; Zotero does not support them. See the docstring of ;; org-zotero-use-textual-cites. (org-add-link-type "zotero"=20 'org-zotero-open 'org-zotero-export) (defvar org-zotero-loc-re "\\(@\\|pp?\\.\\)") (defcustom org-zotero-use-textual-cites nil "If t, links without parentheses around the link description will be handled as `textual' cites (with the default nil, they will be handled as `custom' cites, which are retained verbatim and are not updated by Zotero). Zotero does not provide an equivalent of natbib's \citet command, so in order to fake textual cites, one needs an appropriately customized CSL style that does not bracket citations. When this variable is set to t, therefore, parenthesized links will be exported with brackets placed around the field code. Note that these brackets are not part of the field code, and will not be updated in Zotero." ;; TODO add customization args ) (defun org-zotero-open (path) (browse-url (format "zotero://select//%s" path))) (defun org-zotero-export (path desc format) (cond=20 ((eq format 'odt) (let=20 ((refmark "%s")=20 (citation-id (substring (org-id-uuid) -10)) (rnd (concat "RND" (substring (org-id-uuid) -10))) ;; FIXME check = uniqueness? paths library-id key-item descs citeparts zitem custom=20 authdate citeyear prefix loc loctype suffix parenthesized c) ;; If desc is not parenthesized, this is ;; either a textual citation (if we're set to fake them) ;; or a custom citation to be passed verbatim (setq parenthesized=20 (and (string=3D "(" (substring desc 0 1)) (string=3D ")" (substring desc -1)))) (if parenthesized (setq desc (substring desc 1 -1)) (unless org-zotero-use-textual-cites (setq custom desc))) (when (and org-zotero-use-textual-cites parenthesized) (setq refmark (format "(%s)" refmark))) =20=20=20=20=20=20 ;; Start putting together the fieldcode (setq zitem (concat "ZOTERO_ITEM {" "\"citationID\":\"" citation-id "\"," (when custom (concat "\"properties\": {" (format "\"custom\": \"%s\"" custom) "},")) "\"citationItems\":[")) ;; If this is not a custom cite, parse it (unless custom ;; If multiple works parse all of them (setq paths (split-string path ";\\s-*")) (setq descs (split-string desc ";\\s-*")) (unless (=3D (length paths) (length descs)) (error "Mismatched path/desc length in Zotero cite [%s][%s]" path= desc)) (setq c 1) ; work counter (while descs ;; Parse the description (setq library-id (car (split-string (car paths) "_")) item-key (car (cdr (split-string (car paths) "_")))) (setq citeparts (split-string (car descs) "\\s-*:\\s-*")) ;; If there's a date in the first section, it's author-date (if (string-match "\\([0-9]\\{4\\}\\|n\\.d\\.\\)" (car citeparts)) (setq authdate (car citeparts) prefix nil) ;=20 ;; Else first is prefix, second is authordate.=20 (setq prefix (car citeparts) citeparts (cdr citeparts) authdate (car citeparts))) ;; If the author-date part has only date (if (=3D (length authdate) 4) ; FIXME Improve on this! (setq citeyear t)) ;; Figure out what of the rest is locator and what's suffix, if a= ny (setq citeparts (cdr citeparts)) (when citeparts ;; If there are two, it's easy (if (=3D 2 (length citeparts)) (setq loc (car citeparts) suffix (car (cdr citeparts))) ;; Else check for a locator label (if (string-match org-zotero-loc-re (car citeparts)) (setq loc (car citeparts)) (setq suffix (car citeparts)))) ;; Clean up the locator and set the label (when loc (string-match (concat org-zotero-loc-re " ?\\(.*\\)") loc) (let ((s (match-string 1 loc)))=20 (setq label (cond=20 ((string=3D s "@") "page") ((string=3D s "p.") "page")))) (setq loc (match-string 2 loc)))) ;; Complete the Zotero item (setq zitem=20 (concat zitem "{" (when citeyear "\"suppress-author\": true,") (when prefix (format "\"prefix\": \"%s\"," prefix)) (when loc (format "\"locator\": \"%s\"," loc)) (when loctype (format "\"label\": \"%s\"," loctype)) (when suffix (format "\"suffix\": \"%s\"," suffix)) "\"uri\":[" "\"http://zotero.org/users/local/" library-id "/items/" it= em-key "\"" "]" "}" (when (cdr descs) ","))); if there are more works to follow ;; Loop to next work (setq c (+ 1 c)) (setq paths (cdr paths)) (setq descs (cdr descs)))) ;; end fieldcode (setq zitem (concat zitem "]} " rnd)) (setq zitem (replace-regexp-in-string "\"" """ zitem)) (format refmark zitem desc zitem))) (t desc))) --=-=-=--