From mboxrd@z Thu Jan 1 00:00:00 1970 From: Thibault Marin Subject: Re: Multiple bibliography files with ox-bibtex and html export Date: Tue, 27 Sep 2016 22:50:16 -0500 Message-ID: <878tucznrb.fsf@dell-desktop.WORKGROUP> References: <87k2f6x0q6.fsf@dell-desktop.WORKGROUP> <87vay9v1h1.fsf@saiph.selenimh> <871t0wl6by.fsf@dell-desktop.WORKGROUP> <61fbf71f-3809-7460-5ead-265c8c9e6f66@gmail.com> <87lgz0e18i.fsf@dell-desktop.WORKGROUP> <49a92389-9eeb-84b9-fc5f-054aa6d7b2c2@gmail.com> Reply-To: thibault.marin@gmx.com Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:42977) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bp5t5-0007ab-04 for emacs-orgmode@gnu.org; Tue, 27 Sep 2016 23:50:28 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bp5t1-0004Qu-BL for emacs-orgmode@gnu.org; Tue, 27 Sep 2016 23:50:25 -0400 Received: from mout.gmx.net ([212.227.15.18]:62669) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bp5t1-0004Pr-1Z for emacs-orgmode@gnu.org; Tue, 27 Sep 2016 23:50:23 -0400 In-reply-to: <49a92389-9eeb-84b9-fc5f-054aa6d7b2c2@gmail.com> 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" To: =?utf-8?Q?Cl=C3=A9ment?= Pit--Claudel Cc: emacs-orgmode@gnu.org --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Hi, sorry for the delay, I was away for a while. > I'd suggest 2 :) But not that I don't use this feature. > > It should be easy to unify the code: something along the lines of start= ing the process, and then looping over bibtex files and sending them one = by one to bibtex2html's standard input. > > Cheers, > Cl=C3=A9ment. Please find attached a tentative patch using `process-send-string'. It s= eems to work on my test cases, but I don't know how to wait for the bibtex2html p= rocess to finish before processing the output. I am currently using a while loo= p (see l. 96 of the patch or l. 256 of the patched ox-bibtex.el) combined with a sentinel changing the while condition upon completion. This seems subopt= imal but I don't know how to achieve that more elegantly. I still have a few questions: 1. How can I wait on the subprocess to complete after all the bib files h= ave been passed via stdin? 2. Why is this approach preferred over concatenating bib files and delega= ting processing to the bibtex2html executable? Thanks for the help, thibault --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0001-ox-bibtex.el-Support-multiple-bib-files-in-HTML-expo.patch >From 66edb29f79ddcdf90a47cd8626fb9f04167f5997 Mon Sep 17 00:00:00 2001 From: thibault Date: Tue, 27 Sep 2016 22:36:57 -0500 Subject: [PATCH] ox-bibtex.el: Support multiple bib files in HTML export * contrib/lisp/ox-bibtex.el (org-bibtex-process-bib-files): Pass input bibliography files to asynchronous bibtex2html process. --- contrib/lisp/ox-bibtex.el | 69 +++++++++++++++++++++++++++++++++-------------- 1 file changed, 49 insertions(+), 20 deletions(-) diff --git a/contrib/lisp/ox-bibtex.el b/contrib/lisp/ox-bibtex.el index 56dec38..ca7839f 100644 --- a/contrib/lisp/ox-bibtex.el +++ b/contrib/lisp/ox-bibtex.el @@ -188,18 +188,26 @@ Return new parse tree." (lambda (keyword) (when (equal (org-element-property :key keyword) "BIBLIOGRAPHY") (let ((arguments (org-bibtex-get-arguments keyword)) - (file (org-bibtex-get-file keyword)) + (files (split-string (org-bibtex-get-file keyword) ",")) temp-file out-file) ;; Test if filename is given with .bib-extension and strip - ;; it off. Filenames with another extensions will be + ;; it off. Filenames with another extensions will be ;; untouched and will finally rise an error in bibtex2html. - (setq file (if (equal (file-name-extension file) "bib") - (file-name-sans-extension file) file)) - ;; Outpufiles of bibtex2html will be put into current working directory - ;; so define a variable for this. - (setq out-file (file-name-sans-extension - (file-name-nondirectory file))) + (setq files + (mapcar + (lambda (file) + (if (equal (file-name-extension file) "bib") + (file-name-sans-extension file) + file)) + files)) + ;; Output files of bibtex2html will be put into current + ;; working directory so define a variable for this. + (setq out-file + (if (> (length files) 1) + (concat (buffer-file-name) "-combined") + (file-name-sans-extension + (file-name-nondirectory (car files))))) ;; limit is set: collect citations throughout the document ;; in TEMP-FILE and pass it to "bibtex2html" as "-citefile" ;; argument. @@ -216,18 +224,39 @@ Return new parse tree." :options (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")) + ;; Call "bibtex2html" on specified files. + (let ((process-complete nil) + (bibtex2html-proc + (or + (apply + 'start-process + (append '("bibtex2html" "*bibtex2html-proc*") + '("bibtex2html" "-a" "-nodoc" + "-noheader" "-nofooter") + (let ((style + (org-not-nil + (org-bibtex-get-style keyword)))) + (and style (list "--style" style))) + (plist-get arguments :options) + `("-o" ,out-file))) + (error "Unable to start bibtex2html process")))) + (when bibtex2html-proc + (set-process-sentinel + bibtex2html-proc + (lambda (process event) + (when (equal event "finished\n") + (setq process-complete t)))) + (dolist (file files) + (let ((file-content + (with-temp-buffer + (insert-file-contents (concat file ".bib")) + (buffer-string)))) + (process-send-string bibtex2html-proc file-content))) + (process-send-eof bibtex2html-proc)) + ;; FIXME: How to wait for process to finish? + (while (not process-complete) + (accept-process-output bibtex2html-proc) + (sit-for 1))) (and temp-file (delete-file temp-file)) ;; Open produced HTML file, and collect Bibtex key names (with-temp-buffer -- 2.9.3 --=-=-=--