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: Mon, 08 Jul 2013 15:57:54 +0200 Message-ID: <87li5hduhp.fsf@gmail.com> References: <87li5hmbkg.fsf@pinto.chemeng.ucl.ac.uk> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:52094) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UwBwn-0000hy-Nk for emacs-orgmode@gnu.org; Mon, 08 Jul 2013 09:57:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UwBwm-000452-9N for emacs-orgmode@gnu.org; Mon, 08 Jul 2013 09:57:45 -0400 Received: from mail-wi0-x233.google.com ([2a00:1450:400c:c05::233]:39613) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UwBwm-00044v-2g for emacs-orgmode@gnu.org; Mon, 08 Jul 2013 09:57:44 -0400 Received: by mail-wi0-f179.google.com with SMTP id hj3so3979165wib.12 for ; Mon, 08 Jul 2013 06:57:43 -0700 (PDT) Received: from selenimh ([91.224.148.150]) by mx.google.com with ESMTPSA id p1sm55265966wix.9.2013.07.08.06.57.40 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Mon, 08 Jul 2013 06:57:41 -0700 (PDT) In-Reply-To: <87li5hmbkg.fsf@pinto.chemeng.ucl.ac.uk> (Eric S. Fraga's message of "Mon, 8 Jul 2013 14:21:51 +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: > as noted a while back, I use cite:bibref type links in org to write > LaTeX papers. I have defined the cite link type as follows: > > #+begin_src emacs-lisp > (org-add-link-type "cite" 'ebib > (lambda (path desc format) > (cond > ((eq format 'latex) > (format "\\cite{%s}" path))))) > #+end_src > > This works really well for LaTeX export. However, it doesn't work at > all for html export. Obviously, I can add an html target but this > would only allow me a simple formatting capability. > > I have played around with ox-bibtex. This works well for both LaTeX and > HTML exports so long as I use \cite{bibref} directly in my org text > which is not as elegant. Would the following patch work? Regards, -- Nicolas Goaziou --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0001-ox-bibtex-Add-cite-.-links-support.patch >From fb23a30ba89ad34eb5f4cbdad7c0ffbb2f9e16b6 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. --- contrib/lisp/ox-bibtex.el | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/contrib/lisp/ox-bibtex.el b/contrib/lisp/ox-bibtex.el index 3e6f8e6..2ebbdd0 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 @@ -139,7 +148,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 (equal (org-element-property :type link) "cite")) ad-do-it + (setq ad-return-value + (format "\\cite{%s}" (org-element-property :path link)))))) + (ad-activate 'org-latex-keyword) +(ad-activate 'org-latex-link) @@ -176,8 +194,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 (equal (org-element-property :type link) "cite")) 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-element-property :path link) + "[ \t]*,[ \t]*") + ""))))) + (ad-activate 'org-html-keyword) (ad-activate 'org-html-latex-fragment) +(ad-activate 'org-html-link) ;;;; Filter -- 1.8.3.2 --=-=-=--