all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Thibault Marin <thibault.marin@gmx.com>
To: "Clément Pit--Claudel" <clement.pit@gmail.com>,
	"Nicolas Goaziou" <mail@nicolasgoaziou.fr>
Cc: emacs-orgmode@gnu.org
Subject: Re: Multiple bibliography files with ox-bibtex and html export
Date: Tue, 15 Nov 2016 23:31:33 -0600	[thread overview]
Message-ID: <87h978j8i2.fsf@dell-desktop.WORKGROUP> (raw)
In-Reply-To: <878tucznrb.fsf@dell-desktop.WORKGROUP>

[-- Attachment #1: Type: text/plain, Size: 992 bytes --]


Hi,

I am trying to get back to the multiple bibliography issue discussed
some time ago.

I have two patches proposing two slightly different approaches (from
earlier suggestions):

- 0001-contrib-lisp-ox-bibtex.el-org-bibtex-process-bib-fil.patch creates a
  new bibliography file, a concatenation of all the input files, before calling
  bibtex2html.

- 0001-ox-bibtex.el-Support-multiple-bib-files-in-HTML-expo.patch use
  `start-process' to start the bibtex2html process, then feeds it the input
  bibliography files via stdin.  Once all files are sent it uses a while loop to
  wait for the process to complete (I don't know if there is a better way to do
  that without busy waiting).
  #+BEGIN_SRC emacs-lisp
;; FIXME: How to wait for process to finish?
(while (not process-complete)
  (accept-process-output bibtex2html-proc)
  (sit-for 1)))
  #+END_SRC

Could you please let me know which direction would be preferred, and if changes
should be made to the patch?

Thanks

thibault


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-contrib-lisp-ox-bibtex.el-org-bibtex-process-bib-fil.patch --]
[-- Type: text/x-diff, Size: 1987 bytes --]

From f093490a3631d4e9de0b18dc5e129eb8049975bc Mon Sep 17 00:00:00 2001
From: thibault <thibault.marin@gmx.com>
Date: Tue, 6 Sep 2016 22:42:39 -0500
Subject: [PATCH] * contrib/lisp/ox-bibtex.el (org-bibtex-process-bib-files):
 Add support for multiple bibliography files with html export.

Combine comma-separated bibliography files into a single one and process
it using bibtex2html.  This matches the behavior already present for
latex export.
---
 contrib/lisp/ox-bibtex.el | 18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)

diff --git a/contrib/lisp/ox-bibtex.el b/contrib/lisp/ox-bibtex.el
index 56dec38..b46cb76 100644
--- a/contrib/lisp/ox-bibtex.el
+++ b/contrib/lisp/ox-bibtex.el
@@ -191,13 +191,27 @@ Return new parse tree."
 		(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))))
 	    ;; 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.
 	    (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.
+	    ;; Output files 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)))
 	    ;; limit is set: collect citations throughout the document
-- 
2.9.3


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #3: 0001-ox-bibtex.el-Support-multiple-bib-files-in-HTML-expo.patch --]
[-- Type: text/x-diff, Size: 4023 bytes --]

From c3056a453efb8bdd39e1dfd6fe4f75090cd1a584 Mon Sep 17 00:00:00 2001
From: thibault <thibault.marin@gmx.com>
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


      reply	other threads:[~2016-11-16  5:31 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-24  4:14 Multiple bibliography files with ox-bibtex and html export Thibault Marin
2016-09-06  9:09 ` Nicolas Goaziou
2016-09-07  3:46   ` Thibault Marin
2016-09-07  4:11     ` Clément Pit--Claudel
2016-09-09  3:55       ` Thibault Marin
2016-09-10  6:07       ` Thibault Marin
2016-09-10 16:31         ` Clément Pit--Claudel
2016-09-28  3:50           ` Thibault Marin
2016-11-16  5:31             ` Thibault Marin [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87h978j8i2.fsf@dell-desktop.WORKGROUP \
    --to=thibault.marin@gmx.com \
    --cc=clement.pit@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    --cc=mail@nicolasgoaziou.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.