From mboxrd@z Thu Jan 1 00:00:00 1970 From: Taru Karttunen Subject: org-exp-bibtex.el - add support to citing bibtex in both html and latex exports Date: Sun, 22 Feb 2009 14:05:46 +0200 Message-ID: <20090222120546.GA21017@taruti.net> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=_courier-14660-1235304346-0001-2" Return-path: Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1LbD5j-00061k-CI for emacs-orgmode@gnu.org; Sun, 22 Feb 2009 07:05:51 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1LbD5i-00061R-NO for emacs-orgmode@gnu.org; Sun, 22 Feb 2009 07:05:50 -0500 Received: from [199.232.76.173] (port=51416 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LbD5i-00061N-Hg for emacs-orgmode@gnu.org; Sun, 22 Feb 2009 07:05:50 -0500 Received: from courier.cs.helsinki.fi ([128.214.9.1]:36636 helo=mail.cs.helsinki.fi) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1LbD5h-0007cE-TA for emacs-orgmode@gnu.org; Sun, 22 Feb 2009 07:05:50 -0500 Content-Disposition: inline List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Org-mode ml This is a MIME-formatted message. If you see this text it means that your E-mail software does not support MIME-formatted messages. --=_courier-14660-1235304346-0001-2 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Content-Disposition: inline Hello Motivated by the discussion on exporting BibTeX to html and LaTeX when using org-mode I created an extension that does this. The html export uses bibtex2html from http://www.lri.fr/~filliatr/bibtex2html/ also packaged in e.g. Debian. This works by a #+BIBLIOGRAPHY: bibfilebasename stylename e.g. given foo.bib and using style plain: #+BIBLIOGRAPHY: foo plain 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{bar} 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 Code attached. - Taru Karttunen --=_courier-14660-1235304346-0001-2 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="org-exp-bibtex.el" ;;; org-exp-bibtex.el --- Export bibtex fragments ;; Copyright (C) 2009 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 ;; e.g. given foo.bib and using style plain: ;; #+BIBLIOGRAPHY: foo plain ;; 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 (defun org-export-bibtex-preprocess () "Export all BibTeX." (interactive) (save-window-excursion (setq oebp-cite-plist '()) ;; Convert #+BIBLIOGRAPHY: name style (goto-char (point-min)) (while (re-search-forward "^#\\+BIBLIOGRAPHY:\\s-+\\(\\w+\\)\\s-+\\(\\w+\\)" nil t) (let ((file (match-string 1)) (style (match-string 2))) (replace-match (cond (htmlp ;; We are exporting to HTML (call-process "bibtex2html" nil nil nil "--nodoc" "--style" style "--no-header" (concat file ".bib")) (with-temp-buffer (save-match-data (insert-file-contents (concat file ".html")) (goto-char (point-min)) (while (re-search-forward "a name=\"\\(\\w+\\)\">\\(\\w+\\)" nil t) (setq oebp-cite-plist (cons (cons (match-string 1) (match-string 2)) oebp-cite-plist))) (goto-char (point-min)) (while (re-search-forward "
" nil t) (replace-match "
")) (concat "\n#+BEGIN_HTML\n
\n" (buffer-string) "\n
\n#+END_HTML\n")))) (latexp ;; Latex export (concat "\n#+LATEX: \\\\bibliographystyle{" style "}" "\n#+LATEX: \\\\bibliography{" file "}\n")))))) ;; Convert cites to links in html (goto-char (point-min)) (when htmlp (while (re-search-forward "\\\\cite{\\(\\w+\\)}" nil t) (let* ((cn (match-string 1)) (cv (assoc cn oebp-cite-plist))) (replace-match (concat "\[_{}[[" cn "][" (if cv (cdr cv) cn) "]]\]"))))))) (add-hook 'org-export-preprocess-hook 'org-export-bibtex-preprocess) (provide 'org-exp-bibtex) ;;; org-exp-bibtex.el ends here --=_courier-14660-1235304346-0001-2 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Emacs-orgmode mailing list Remember: use `Reply All' to send replies to the list. Emacs-orgmode@gnu.org http://lists.gnu.org/mailman/listinfo/emacs-orgmode --=_courier-14660-1235304346-0001-2--