[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: |
Mon, 08 Jul 2013 15:57:54 +0200 |
Hello,
Eric S Fraga <address@hidden> 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
>From fb23a30ba89ad34eb5f4cbdad7c0ffbb2f9e16b6 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.
---
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 "[<a href=\"#%s\">%s</a>]"
+ 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
- [O] ox-bibtex works well with \cite{} entries but not with cite: links, Eric S Fraga, 2013/07/08
- Re: [O] ox-bibtex works well with \cite{} entries but not with cite: links,
Nicolas Goaziou <=
- Re: [O] ox-bibtex works well with \cite{} entries but not with cite: links, Eric S Fraga, 2013/07/09
- Re: [O] ox-bibtex works well with \cite{} entries but not with cite: links, Eric S Fraga, 2013/07/09
- Re: [O] ox-bibtex works well with \cite{} entries but not with cite: links, Nicolas Goaziou, 2013/07/09
- Re: [O] ox-bibtex works well with \cite{} entries but not with cite: links, Eric S Fraga, 2013/07/09
- Re: [O] ox-bibtex works well with \cite{} entries but not with cite: links, Nicolas Goaziou, 2013/07/10
- Re: [O] ox-bibtex works well with \cite{} entries but not with cite: links, Eric S Fraga, 2013/07/10