From mboxrd@z Thu Jan 1 00:00:00 1970 From: Nicolas Goaziou Subject: Re: Bibliography Date: Tue, 07 May 2013 18:48:03 +0200 Message-ID: <87ehdid9do.fsf@gmail.com> References: <20130506145017.GF20172@kuru.dyndns-at-home.com> <87wqrcdjs4.fsf@gmail.com> <87li7sdjdj.fsf@gmail.com> <20130507053752.GA14940@panahar> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from eggs.gnu.org ([208.118.235.92]:49789) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UZl3j-0005T5-4W for emacs-orgmode@gnu.org; Tue, 07 May 2013 12:48:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UZl3c-0004J8-QB for emacs-orgmode@gnu.org; Tue, 07 May 2013 12:48:11 -0400 Received: from mail-we0-x235.google.com ([2a00:1450:400c:c03::235]:53706) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UZl3c-0004Hx-Ge for emacs-orgmode@gnu.org; Tue, 07 May 2013 12:48:04 -0400 Received: by mail-we0-f181.google.com with SMTP id q55so736573wes.26 for ; Tue, 07 May 2013 09:48:03 -0700 (PDT) Received: from selenimh ([91.224.148.150]) by mx.google.com with ESMTPSA id e8sm3913763wic.5.2013.05.07.09.48.01 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Tue, 07 May 2013 09:48:02 -0700 (PDT) In-Reply-To: <20130507053752.GA14940@panahar> (Vikas Rawal's message of "Tue, 7 May 2013 11:07:53 +0530") List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org --=-=-= Content-Type: text/plain Hello, Vikas Rawal writes: >> My only concern is about users expecting the keyword to be >> recognized in other back-ends. > > Yes please. I am waiting for something that will export bibtex to > html. With the old exporter, org-exp-bibtex used bibtex2html to > achieve it. But nothing similar is possible with the new exporter. I attach a port of org-exp-bibtex.el (renamed ox-bibtex.el) for the new export framework. Would you mind testing it? Thank you. Regards, -- Nicolas Goaziou --=-=-= Content-Type: application/emacs-lisp Content-Disposition: attachment; filename=ox-bibtex.el Content-Transfer-Encoding: quoted-printable ;;; ox-bibtex.el --- Export bibtex fragments ;; Copyright (C) 2009-2013 Taru Karttunen ;; Author: Taru Karttunen ;; This file is not currently part of GNU Emacs. ;; This program is free software; you can redistribute it and/or ;; modify it under the terms of the GNU General Public License as ;; published by the Free Software Foundation; either version 2, or (at ;; your option) any later version. ;; This program is distributed in the hope that it will be useful, but ;; WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ;; General Public License for more details. ;; You should have received a copy of the GNU General Public License ;; along with this program ; see the file COPYING. If not, write to ;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330, ;; Boston, MA 02111-1307, USA. ;;; Commentary: ;; ;; This is an utility to handle BibTeX export to both LaTeX and html ;; exports. It uses the bibtex2html software from ;; http://www.lri.fr/~filliatr/bibtex2html/ ;; ;; The usage is as follows: ;; #+BIBLIOGRAPHY: bibfilebasename stylename optional-options ;; e.g. given foo.bib and using style plain: ;; #+BIBLIOGRAPHY: foo plain option:-d ;; ;; Optional options are of the form: ;; ;; option:-foobar pass '-foobar' to bibtex2html ;; e.g. ;; option:-d sort by date. ;; option:-a sort as BibTeX (usually by author) *default* ;; option:-u unsorted i.e. same order as in .bib file ;; option:-r reverse the sort. ;; see the bibtex2html man page for more. Multiple options can be combined = like: ;; option:-d option:-r ;; ;; Limiting to only the entries cited in the document: ;; limit:t ;; For LaTeX export this simply inserts the lines ;; \bibliographystyle{plain} ;; \bibliography{foo} ;; into the tex-file when exporting. ;; For HTML export it: ;; 1) converts all \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 (require 'ox) (defun org-export-bibtex-preprocess (backend) "Export all BibTeX." (interactive) (let ((cite-alist '()) (map-cites (lambda (f) ;; Call function F with point on each "\cite{...}" ;; construct in the current buffer. Function F is called ;; with one argument: the contents of the "\cite" macro. (save-excursion (save-match-data (goto-char (point-min)) (while (re-search-forward "\\\\cite{\\([^}\n]+\\)}" nil t) (when (eq (org-element-type (save-match-data (org-element-context))) 'latex-fragment) (funcall f (match-string 1))))))))) ;; Convert #+BIBLIOGRAPHY: name style. (goto-char (point-min)) (while (re-search-forward "^[ \t]*#\\+BIBLIOGRAPHY:" nil t) (let* ((element (org-element-at-point)) (value (org-element-property :value element))) (when (and (eq (org-element-type element) 'keyword) value (string-match "\\(\\S-+\\)[ \t]+\\(\\S-+\\)\\(.*\\)" value)) (let ((ind (make-string (org-get-indentation) ?\s)) (file (match-string 1 value)) (style (match-string 2 value)) (opt (mapcar (lambda (o) (let ((s (split-string o ":"))) (cons (car s) (nth 1 s)))) (split-string (match-string 3 value) nil t)))) ;; Remove keyword. (delete-region (org-element-property :begin element) (progn (goto-char (org-element-property :end element)) (skip-chars-backward " \r\t\n") (line-end-position))) (insert (case backend ;; LaTeX export. (latex (concat ind "#+LATEX: \\bibliographystyle{" style "}\n" ind "#+LATEX: \\bibliography{" file "}")) ;; HTML export. (html (let (extra-args cite-list end-hook tmp-files) (dolist (elt opt) (when (equal "option" (car elt)) (push (cdr elt) extra-args))) (when (assoc "limit" opt) ;; Limit is true: collect references. (funcall map-cites (lambda (cite) (dolist (c (org-split-string cite ",")) (add-to-list 'cite-list c)))) (let ((tmp (make-temp-file "org-exp-bibtex"))) (with-temp-file tmp (dolist (i cite-list) (insert (concat i "\n")))) (push tmp tmp-files) (setq extra-args (append extra-args `("-citefile" ,tmp))))) (save-window-excursion (unless (eq 0 (apply 'call-process (append '("bibtex2html" nil nil ni= l) `("-a" "--nodoc" "--style= " ,style "--no-header") extra-args (list (concat file ".bib")= )))) (error "Executing bibtex2html failed"))) (dolist (f tmp-files) (delete-file f))) (with-temp-buffer (save-match-data (insert-file-contents (concat file ".html")) (goto-char (point-min)) (let ((link-re (org-re "a name=3D\"\\([-_[:word:]]+\\)\= ">\\([[:word:]]+\\)"))) (while (re-search-forward link-re nil t) (push (cons (match-string 1) (match-string 2)) cite-alist))) (goto-char (point-min)) (while (search-forward "
" nil t) (replace-match "
" t t)) (concat ind "#+BEGIN_HTML\n" "
\n

References\n" (buffer-string) "\n" "

\n" ind "#+END_HTML")))))))))) ;; Convert cites to links in HTML. (when (eq backend 'html) ;; Split citation commands with multiple keys. (funcall map-cites (lambda (cite) (let ((keys (save-match-data (org-split-string cite ",")))) (when (cdr keys) (replace-match (mapconcat (lambda (k) (format "\\cite{%s}" k)) keys "") t t))))) ;; Replace the citation commands with links. (funcall map-cites (lambda (cite) (let ((cv (assoc cite cite-alist))) (replace-match (format "[[#%s][%s]]" cite (if cv (cdr cv) cite)) t t))))))) (add-hook 'org-export-before-processing-hook 'org-export-bibtex-preprocess) (provide 'ox-bibtex) ;;; ox-bibtex.el ends here --=-=-=--