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: Thu, 08 Sep 2016 22:55:06 -0500 Message-ID: <87wpilbucl.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> Reply-To: thibault.marin.us@ieee.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:37440) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1biCuG-0006zZ-HU for emacs-orgmode@gnu.org; Thu, 08 Sep 2016 23:55:13 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1biCuD-0004Zf-Bw for emacs-orgmode@gnu.org; Thu, 08 Sep 2016 23:55:12 -0400 Received: from mail-yw0-x233.google.com ([2607:f8b0:4002:c05::233]:36298) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1biCuD-0004ZI-5L for emacs-orgmode@gnu.org; Thu, 08 Sep 2016 23:55:09 -0400 Received: by mail-yw0-x233.google.com with SMTP id u124so27882151ywg.3 for ; Thu, 08 Sep 2016 20:55:08 -0700 (PDT) In-reply-to: <61fbf71f-3809-7460-5ead-265c8c9e6f66@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: 8bit Clément Pit--Claudel writes: > On 2016-09-06 23:46, Thibault Marin wrote: >>>> I am attaching a patch which allows me to use multiple files with html >>>> export. It creates a combined bibliography file and call bibtex2html on >>>> it. I am not sure this is the best way to address this, so any >>>> suggestion would be welcome. > > Sorry for the late comment. bibtex2html can read from standard input; maybe that would be cleaner? > > Clément. That may be a good idea, it would prevent potential name clashing with the created bib file. Currently, the function creates a -combined.bib file with the content of all bibliography files, then bibtex2html creates -combined.html and -combined_bib.html. Passing the contents via stdin would skip the -combined.bib. We could achieve the same by simply deleting -combined.bib after calling bibtex2html. I personally don't mind leaving the .bib file after processing, but if there is a consensus to limit the side effect, we can do that. As far as the implementation goes, I am not sure what is the best way to get this to work with stdin. In the attached patch (which does *not* work) I tried to use `call-process-region' and dump the bibliography files into a temporary buffer. This complicates the code a little. Alternatively, we could use the `INFILE' parameter from `call-process', but it looks that this would require a file, so it would not change much from the previous patch. Any thoughts? --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0002-contrib-lisp-ox-bibtex.el-org-bibtex-process-bib-fil.patch >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 --=-=-=--