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
<name-of-org-file>-combined.bib file with the content of all
bibliography files, then bibtex2html creates
<name-of-org-file>-combined.html and
<name-of-org-file>-combined_bib.html.  Passing the contents via stdin
would skip the <name-of-org-file>-combined.bib.  We could achieve the
same by simply deleting <name-of-org-file>-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?

>From 85369923cdd7540467a615ca92cf486fd6d08708 Mon Sep 17 00:00:00 2001
From: thibault <thibault@dell-desktop.WORKGROUP>
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

Reply via email to