emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Taru Karttunen <taruti@taruti.net>
To: Org-mode ml <emacs-orgmode@gnu.org>
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	[thread overview]
Message-ID: <20090222120546.GA21017@taruti.net> (raw)

[-- Attachment #1: Type: text/plain, Size: 710 bytes --]

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

[-- Attachment #2: org-exp-bibtex.el --]
[-- Type: text/plain, Size: 3169 bytes --]

;;; org-exp-bibtex.el --- Export bibtex fragments

;; Copyright (C) 2009 Taru Karttunen

;; Author: Taru Karttunen <taruti@taruti.net >

;; 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 "<hr>" nil t)
		(replace-match "<hr/>"))
	      (concat "\n#+BEGIN_HTML\n<div class=\"bibliography\">\n" (buffer-string) "\n</div>\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

[-- Attachment #3: Type: text/plain, Size: 204 bytes --]

_______________________________________________
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

             reply	other threads:[~2009-02-22 12:05 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-02-22 12:05 Taru Karttunen [this message]
2009-02-22 14:17 ` org-exp-bibtex.el - add support to citing bibtex in both html and latex exports Sebastian Rose
2009-02-22 18:15   ` Taru Karttunen
2009-02-22 15:04 ` Carsten Dominik
2009-02-24  5:52 ` Carsten Dominik
2009-02-24  7:43 ` Carsten Dominik
     [not found] ` <D0D50C5D-9E40-41CF-A042-475938430B9E@uva.nl>
2009-03-01 10:57   ` Taru Karttunen
2009-03-02 16:40     ` William Henney
2009-03-03  6:33       ` Taru Karttunen
2009-03-03  7:37         ` Sebastian Rose
2009-03-03  9:34         ` Carsten Dominik
2009-03-04 23:08           ` William Henney
2009-03-05  9:37             ` Carsten Dominik
2009-03-05 12:32               ` Chris Gray
2009-03-05 13:25                 ` Carsten Dominik
2010-10-19 21:57     ` Lingyu Ma
2010-10-19 22:56       ` Nick Dokos

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=20090222120546.GA21017@taruti.net \
    --to=taruti@taruti.net \
    --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).