From: Nicolas Goaziou <n.goaziou@gmail.com>
To: emacs-orgmode@gnu.org
Subject: Re: ox-bibtex works well with \cite{} entries but not with cite: links
Date: Mon, 08 Jul 2013 15:57:54 +0200 [thread overview]
Message-ID: <87li5hduhp.fsf@gmail.com> (raw)
In-Reply-To: <87li5hmbkg.fsf@pinto.chemeng.ucl.ac.uk> (Eric S. Fraga's message of "Mon, 8 Jul 2013 14:21:51 +0100")
[-- Attachment #1: Type: text/plain, Size: 869 bytes --]
Hello,
Eric S Fraga <e.fraga@ucl.ac.uk> 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
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-ox-bibtex-Add-cite-.-links-support.patch --]
[-- Type: text/x-diff, Size: 2628 bytes --]
From fb23a30ba89ad34eb5f4cbdad7c0ffbb2f9e16b6 Mon Sep 17 00:00:00 2001
From: Nicolas Goaziou <n.goaziou@gmail.com>
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)
\f
@@ -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
next prev parent reply other threads:[~2013-07-08 13:57 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-07-08 13:21 ox-bibtex works well with \cite{} entries but not with cite: links Eric S Fraga
2013-07-08 13:57 ` Nicolas Goaziou [this message]
2013-07-09 19:39 ` Eric S Fraga
2013-07-09 19:56 ` Eric S Fraga
2013-07-09 20:15 ` Nicolas Goaziou
2013-07-09 22:24 ` Eric S Fraga
2013-07-10 9:06 ` Nicolas Goaziou
2013-07-10 9:46 ` Eric S Fraga
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87li5hduhp.fsf@gmail.com \
--to=n.goaziou@gmail.com \
--cc=emacs-orgmode@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.