* ox-bibtex works well with \cite{} entries but not with cite: links @ 2013-07-08 13:21 Eric S Fraga 2013-07-08 13:57 ` Nicolas Goaziou 0 siblings, 1 reply; 8+ messages in thread From: Eric S Fraga @ 2013-07-08 13:21 UTC (permalink / raw) To: emacs-orgmode Hi, 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. I was wondering what would be required to get ox-bibtex to interpret cite: links? I tried adding html as a valid target above, e.g. by using : ((or (eq format 'latex) (eq format 'html)) but the expansion of links happens after the processing done by ox-bibtex and so any \cite{bibref} text gets passed through to the HTML export directly without processing. Any suggestions welcome and greatly appreciated. Thanks, eric -- : Eric S Fraga (0xFFFCF67D), Emacs 24.3.50.1, Org release_8.0.5-318-gfdaa99 ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: ox-bibtex works well with \cite{} entries but not with cite: links 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 0 siblings, 1 reply; 8+ messages in thread From: Nicolas Goaziou @ 2013-07-08 13:57 UTC (permalink / raw) To: emacs-orgmode [-- 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 ^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: ox-bibtex works well with \cite{} entries but not with cite: links 2013-07-08 13:57 ` Nicolas Goaziou @ 2013-07-09 19:39 ` Eric S Fraga 2013-07-09 19:56 ` Eric S Fraga 0 siblings, 1 reply; 8+ messages in thread From: Eric S Fraga @ 2013-07-09 19:39 UTC (permalink / raw) To: Nicolas Goaziou; +Cc: emacs-orgmode Nicolas Goaziou <n.goaziou@gmail.com> writes: > 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? Works really well for my test case. Thanks! -- : Eric S Fraga (0xFFFCF67D), Emacs 24.3.50.1, Org release_8.0.5-322-gd5c11e.dirty ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: ox-bibtex works well with \cite{} entries but not with cite: links 2013-07-09 19:39 ` Eric S Fraga @ 2013-07-09 19:56 ` Eric S Fraga 2013-07-09 20:15 ` Nicolas Goaziou 0 siblings, 1 reply; 8+ messages in thread From: Eric S Fraga @ 2013-07-09 19:56 UTC (permalink / raw) To: Nicolas Goaziou; +Cc: emacs-orgmode Eric S Fraga <e.fraga@ucl.ac.uk> writes: > Nicolas Goaziou <n.goaziou@gmail.com> writes: [...] >> Would the following patch work? > > Works really well for my test case. Thanks! Ooops, I spoke much too quickly. It works *if* the references cited by cite: links are also cited by \cite{} text if the option "limit:t" is set, as in #+bibliography: examplerefs plain limit:t If the limit:t option is not set, then a document with only cite: links works fine. 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? thanks again, eric -- : Eric S Fraga (0xFFFCF67D), Emacs 24.3.50.1, Org release_8.0.5-322-gd5c11e.dirty ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: ox-bibtex works well with \cite{} entries but not with cite: links 2013-07-09 19:56 ` Eric S Fraga @ 2013-07-09 20:15 ` Nicolas Goaziou 2013-07-09 22:24 ` Eric S Fraga 0 siblings, 1 reply; 8+ messages in thread From: Nicolas Goaziou @ 2013-07-09 20:15 UTC (permalink / raw) To: emacs-orgmode [-- 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 ^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: ox-bibtex works well with \cite{} entries but not with cite: links 2013-07-09 20:15 ` Nicolas Goaziou @ 2013-07-09 22:24 ` Eric S Fraga 2013-07-10 9:06 ` Nicolas Goaziou 0 siblings, 1 reply; 8+ messages in thread From: Eric S Fraga @ 2013-07-09 22:24 UTC (permalink / raw) To: Nicolas Goaziou; +Cc: emacs-orgmode Nicolas Goaziou <n.goaziou@gmail.com> writes: > 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)? Sure. This one works perfectly with my limit:t case! Thanks, eric -- : Eric S Fraga (0xFFFCF67D), Emacs 24.3.50.1, Org release_8.0.5-322-gd5c11e.dirty ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: ox-bibtex works well with \cite{} entries but not with cite: links 2013-07-09 22:24 ` Eric S Fraga @ 2013-07-10 9:06 ` Nicolas Goaziou 2013-07-10 9:46 ` Eric S Fraga 0 siblings, 1 reply; 8+ messages in thread From: Nicolas Goaziou @ 2013-07-10 9:06 UTC (permalink / raw) To: emacs-orgmode Hello, Eric S Fraga <e.fraga@ucl.ac.uk> writes: > Sure. This one works perfectly with my limit:t case! I applied the patch. Thank you for the feedback. Regards, -- Nicolas Goaziou ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: ox-bibtex works well with \cite{} entries but not with cite: links 2013-07-10 9:06 ` Nicolas Goaziou @ 2013-07-10 9:46 ` Eric S Fraga 0 siblings, 0 replies; 8+ messages in thread From: Eric S Fraga @ 2013-07-10 9:46 UTC (permalink / raw) To: Nicolas Goaziou; +Cc: emacs-orgmode Nicolas Goaziou <n.goaziou@gmail.com> writes: > Hello, > > Eric S Fraga <e.fraga@ucl.ac.uk> writes: > >> Sure. This one works perfectly with my limit:t case! > > I applied the patch. Thank you for the feedback. Thanks Nicolas for this! Very helpful. -- : Eric S Fraga (0xFFFCF67D), Emacs 24.3.50.1, Org release_8.0.5-322-gd5c11e.dirty ^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2013-07-10 9:47 UTC | newest] Thread overview: 8+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 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 2013-07-09 22:24 ` Eric S Fraga 2013-07-10 9:06 ` Nicolas Goaziou 2013-07-10 9:46 ` Eric S Fraga
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).