>From 85369923cdd7540467a615ca92cf486fd6d08708 Mon Sep 17 00:00:00 2001 From: thibault Date: Thu, 8 Sep 2016 22:06:21 -0500 Subject: [PATCH 2/2] * contrib/lisp/ox-bibtex.el (org-bibtex-process-bib-files): (WIP) Add support for multiple bibliography files with html export. Pass multiple bibliography files (comma separated) to bibtex2html. --- contrib/lisp/ox-bibtex.el | 82 ++++++++++++++++++++++++++++++----------------- 1 file changed, 53 insertions(+), 29 deletions(-) diff --git a/contrib/lisp/ox-bibtex.el b/contrib/lisp/ox-bibtex.el index b46cb76..38c0957 100644 --- a/contrib/lisp/ox-bibtex.el +++ b/contrib/lisp/ox-bibtex.el @@ -187,24 +187,20 @@ Return new parse tree." (org-element-map tree 'keyword (lambda (keyword) (when (equal (org-element-property :key keyword) "BIBLIOGRAPHY") - (let ((arguments (org-bibtex-get-arguments keyword)) - (file (org-bibtex-get-file keyword)) - temp-file - out-file) - (let ((files (split-string file ","))) - (when (< 1 (length files)) - (let ((combined-bib-file - (concat - (file-name-sans-extension - (file-name-nondirectory - (buffer-file-name))) "-combined.bib"))) - (with-temp-file combined-bib-file - (dolist (bib files) - (insert-file-contents - (if (equal (file-name-extension bib) "bib") - bib - (concat bib ".bib"))))) - (setq file combined-bib-file)))) + (let* ((arguments (org-bibtex-get-arguments keyword)) + (file (org-bibtex-get-file keyword)) + temp-file + out-file + (multiple-bib-files (split-string file ",")) + (multiple-bib-p (< 1 (length multiple-bib-files))) + multiple-bib-file) + (when multiple-bib-p + (setq multiple-bib-file + (concat + (file-name-sans-extension + (file-name-nondirectory + (buffer-file-name))) "-combined.bib")) + (setq file multiple-bib-file)) ;; Test if filename is given with .bib-extension and strip ;; it off. Filenames with another extensions will be ;; untouched and will finally rise an error in bibtex2html. @@ -231,17 +227,45 @@ Return new parse tree." (append (plist-get arguments :options) (list "-citefile" temp-file)))))) ;; Call "bibtex2html" on specified file. - (unless (eq 0 (apply - 'call-process - (append '("bibtex2html" nil nil nil) - '("-a" "-nodoc" "-noheader" "-nofooter") - (let ((style - (org-not-nil - (org-bibtex-get-style keyword)))) - (and style (list "--style" style))) - (plist-get arguments :options) - (list (concat file ".bib"))))) - (error "Executing bibtex2html failed")) + (let* ((bibtex2html-cmd '("bibtex2html" nil nil nil)) + (bibtex2html-args-default '("-a" "-nodoc" "-noheader" + "-nofooter")) + (bibtex2html-style + (let ((style + (org-not-nil + (org-bibtex-get-style keyword)))) + (and style (list "--style" style)))) + (bibtex2html-opts (plist-get arguments :options))) + (message "mf=%s file=%s" multiple-bib-file multiple-bib-files) + (if multiple-bib-p + (with-temp-buffer + multiple-bib-file + (dolist (bib multiple-bib-files) + (insert-file-contents + (if (equal (file-name-extension bib) "bib") + bib + (concat bib ".bib")))) + (unless + (eq 0 + (apply + 'call-process-region + (append `(,(point-min) ,(point-max)) + bibtex2html-cmd + bibtex2html-args-default + bibtex2html-style + bibtex2html-opts + `("-o" ,file))))) + (error "Executing bibtex2html failed")) + (unless + (eq 0 + (apply + 'call-process + (append bibtex2html-cmd + bibtex2html-args-default + bibtex2html-style + bibtex2html-opts + (list (concat file ".bib"))))) + (error "Executing bibtex2html failed")))) (and temp-file (delete-file temp-file)) ;; Open produced HTML file, and collect Bibtex key names (with-temp-buffer -- 2.8.1