From mboxrd@z Thu Jan 1 00:00:00 1970 From: Nicolas Goaziou Subject: Re: ox-bibtex works well with \cite{} entries but not with cite: links Date: Tue, 09 Jul 2013 22:15:58 +0200 Message-ID: <8738rn1och.fsf@gmail.com> References: <87li5hmbkg.fsf@pinto.chemeng.ucl.ac.uk> <87li5hduhp.fsf@gmail.com> <87k3kzv7z4.fsf@ucl.ac.uk> <871u77v76d.fsf@ucl.ac.uk> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:58816) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UweKC-0003zU-Im for emacs-orgmode@gnu.org; Tue, 09 Jul 2013 16:15:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UweKB-0001gi-0f for emacs-orgmode@gnu.org; Tue, 09 Jul 2013 16:15:48 -0400 Received: from mail-wg0-x22d.google.com ([2a00:1450:400c:c00::22d]:48818) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UweKA-0001ge-Mc for emacs-orgmode@gnu.org; Tue, 09 Jul 2013 16:15:46 -0400 Received: by mail-wg0-f45.google.com with SMTP id j13so5238982wgh.12 for ; Tue, 09 Jul 2013 13:15:45 -0700 (PDT) Received: from selenimh ([91.224.148.150]) by mx.google.com with ESMTPSA id nb12sm63330218wic.7.2013.07.09.13.15.44 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Tue, 09 Jul 2013 13:15:44 -0700 (PDT) In-Reply-To: <871u77v76d.fsf@ucl.ac.uk> (Eric S. Fraga's message of "Tue, 9 Jul 2013 20:56:26 +0100") 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: emacs-orgmode@gnu.org --=-=-= Content-Type: text/plain Hello, Eric S Fraga writes: > In other words, the traversal of the document to determine which > references are actually cited, to build up the bib html file, would > appear to only search for \cite{} entries? Indeed. Would you mind testing the following update (just drop the previous patch)? Regards, -- Nicolas Goaziou --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0001-ox-bibtex-Add-cite-.-links-support.patch >From 8556211564104f766dee3c21050fd5594378152a Mon Sep 17 00:00:00 2001 From: Nicolas Goaziou Date: Mon, 8 Jul 2013 15:55:12 +0200 Subject: [PATCH] ox-bibtex: Add [[cite:...]] links support * contrib/lisp/ox-bibtex.el (org-latex-link, org-html-link): New functions. (org-bibtex-citation-p, org-bibtex-get-citation-key): Update function to support "cite" links. (org-bibtex-process-bib-files): Also look after "cite" links when building citation list. --- contrib/lisp/ox-bibtex.el | 67 +++++++++++++++++++++++++++++++++++++---------- 1 file changed, 53 insertions(+), 14 deletions(-) diff --git a/contrib/lisp/ox-bibtex.el b/contrib/lisp/ox-bibtex.el index 3e6f8e6..c4ac078 100644 --- a/contrib/lisp/ox-bibtex.el +++ b/contrib/lisp/ox-bibtex.el @@ -64,10 +64,19 @@ ;; into the TeX file when exporting. ;; ;; For HTML export it: -;; 1) converts all \cite{foo} to links to the bibliography, +;; 1) converts all \cite{foo} and [[cite:foo]] to links to the +;; bibliography, ;; 2) creates a foo.html and foo_bib.html, ;; 3) includes the contents of foo.html in the exported HTML file. +;; +;; For LaTeX export it: +;; 1) converts all [[cite:foo]] to \cite{foo}. + +;; Initialization +(require 'ox-html) +(require 'ox-latex) +(org-add-link-type "cite" 'ebib) ;;; Internal Functions @@ -109,18 +118,22 @@ contains a list of strings to be passed as options ot (setq limit (not (equal "nil" value)))) ((equal "option" key) (push value options))))))))) -(defun org-bibtex-citation-p (fragment) - "Non-nil when a LaTeX macro is a citation. -FRAGMENT is a `latex-fragment' type object." - (string-match "\\`\\\\cite{" (org-element-property :value fragment))) +(defun org-bibtex-citation-p (object) + "Non-nil when an Org object is a citation. +OBJECT is a `latex-fragment' or `link' type object." + (if (eq (org-element-type object) 'link) + (equal (org-element-property :type object) "cite") + (string-match "\\`\\\\cite{" (org-element-property :value object)))) (defun org-bibtex-get-citation-key (citation) "Return key for a given citation, as a string. -CITATION is a `latex-fragment' type object satisfying to -`org-bibtex-citation-p' predicate." - (let ((value (org-element-property :value citation))) - (and (string-match "\\`\\\\cite{" value) - (substring value (match-end 0) -1)))) +CITATION is a `latex-fragment' or `link' type object satisfying +to `org-bibtex-citation-p' predicate." + (if (eq (org-element-type citation) 'link) + (org-element-property :path citation) + (let ((value (org-element-property :value citation))) + (and (string-match "\\`\\\\cite{" value) + (substring value (match-end 0) -1))))) @@ -139,7 +152,16 @@ Fallback to `latex' back-end for other keywords." (concat (and style (format "\\bibliographystyle{%s}\n" style)) (format "\\bibliography{%s}" file)))))))) +(defadvice org-latex-link (around bibtex-link) + "Translate \"cite\" type links into LaTeX syntax. +Fallback to `latex' back-end for other keywords." + (let ((link (ad-get-arg 0))) + (if (not (org-bibtex-citation-p link)) ad-do-it + (setq ad-return-value + (format "\\cite{%s}" (org-bibtex-get-citation-key link)))))) + (ad-activate 'org-latex-keyword) +(ad-activate 'org-latex-link) @@ -176,8 +198,25 @@ Fallback to `html' back-end for other keywords." (org-split-string (org-bibtex-get-citation-key fragment) ",") ""))))) +(defadvice org-html-link (around bibtex-link) + "Translate \"cite:\" type links into HTML syntax. +Fallback to `html' back-end for other types." + (let ((link (ad-get-arg 0))) + (if (not (org-bibtex-citation-p link)) ad-do-it + (setq ad-return-value + (mapconcat + (lambda (key) + (format "[%s]" + key + (or (cdr (assoc key org-bibtex-html-entries-alist)) + key))) + (org-split-string (org-bibtex-get-citation-key link) + "[ \t]*,[ \t]*") + ""))))) + (ad-activate 'org-html-keyword) (ad-activate 'org-html-latex-fragment) +(ad-activate 'org-html-link) ;;;; Filter @@ -202,10 +241,10 @@ Return new parse tree. This function assumes current back-end is HTML." ;; argument. (when (plist-get arguments :limit) (let ((citations - (org-element-map tree 'latex-fragment - (lambda (fragment) - (and (org-bibtex-citation-p fragment) - (org-bibtex-get-citation-key fragment)))))) + (org-element-map tree '(latex-fragment link) + (lambda (object) + (and (org-bibtex-citation-p object) + (org-bibtex-get-citation-key object)))))) (with-temp-file (setq temp-file (make-temp-file "ox-bibtex")) (insert (mapconcat 'identity citations "\n"))) (setq arguments -- 1.8.3.2 --=-=-=--