emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [O] ox-bibtex works well with \cite{} entries but not with cite: lin


From: Nicolas Goaziou
Subject: Re: [O] ox-bibtex works well with \cite{} entries but not with cite: links
Date: Tue, 09 Jul 2013 22:15:58 +0200

Hello,

Eric S Fraga <address@hidden> 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
>From 8556211564104f766dee3c21050fd5594378152a Mon Sep 17 00:00:00 2001
From: Nicolas Goaziou <address@hidden>
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 "[<a href=\"#%s\">%s</a>]"
+                      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


reply via email to

[Prev in Thread] Current Thread [Next in Thread]