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: Tue, 09 Jul 2013 22:15:58 +0200 [thread overview]
Message-ID: <8738rn1och.fsf@gmail.com> (raw)
In-Reply-To: <871u77v76d.fsf@ucl.ac.uk> (Eric S. Fraga's message of "Tue, 9 Jul 2013 20:56:26 +0100")
[-- Attachment #1: Type: text/plain, Size: 349 bytes --]
Hello,
Eric S Fraga <e.fraga@ucl.ac.uk> 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
[-- 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: 5036 bytes --]
From 8556211564104f766dee3c21050fd5594378152a 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.
(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)))))
\f
@@ -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)
\f
@@ -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
next prev parent reply other threads:[~2013-07-09 20:15 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
2013-07-09 19:39 ` Eric S Fraga
2013-07-09 19:56 ` Eric S Fraga
2013-07-09 20:15 ` Nicolas Goaziou [this message]
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
List information: https://www.orgmode.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=8738rn1och.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 public inbox
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).