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