emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
blob a2051ff09007e6e88dd6e7bdc316aa1e3ca2b547 3185 bytes (raw)
name: contrib/lisp/org-exp-bibtex.el 	 # note: path name is non-authoritative(*)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
 
;;; 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 "-a" "--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/>" t t))
	      (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"))) t t)))
    ;; 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) "]]\]") t t))))))


(add-hook 'org-export-preprocess-hook 'org-export-bibtex-preprocess)

(provide 'org-exp-bibtex)

;;; org-exp-bibtex.el ends here

debug log:

solving a2051ff ...
found a2051ff in https://list.orgmode.org/orgmode/86myc0dleu.fsf@portan.ibr.cs.tu-bs.de/
found d27fd59 in https://git.savannah.gnu.org/cgit/emacs/org-mode.git
preparing index
index prepared:
100644 d27fd5951d077d0d0186b5d5d6b3253b03f010b7	contrib/lisp/org-exp-bibtex.el

applying [1/1] https://list.orgmode.org/orgmode/86myc0dleu.fsf@portan.ibr.cs.tu-bs.de/
diff --git a/contrib/lisp/org-exp-bibtex.el b/contrib/lisp/org-exp-bibtex.el
index d27fd59..a2051ff 100644

Checking patch contrib/lisp/org-exp-bibtex.el...
Applied patch contrib/lisp/org-exp-bibtex.el cleanly.

index at:
100644 a2051ff09007e6e88dd6e7bdc316aa1e3ca2b547	contrib/lisp/org-exp-bibtex.el

(*) Git path names are given by the tree(s) the blob belongs to.
    Blobs themselves have no identifier aside from the hash of its contents.^

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).