From mboxrd@z Thu Jan 1 00:00:00 1970 From: Konrad Herbst Subject: [PATCH] ox-bibtex.el: Extend to use bibtex files not in current, working directory Date: Wed, 09 Jul 2014 19:10:47 +0200 Message-ID: <53BD7797.7060002@stud.uni-heidelberg.de> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------020007010800050404010904" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:49214) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X4vOt-0001nL-Ml for emacs-orgmode@gnu.org; Wed, 09 Jul 2014 13:11:31 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1X4vOe-000422-L4 for emacs-orgmode@gnu.org; Wed, 09 Jul 2014 13:11:23 -0400 Received: from relay2.uni-heidelberg.de ([129.206.210.211]:33538) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X4vOe-00041Z-Bp for emacs-orgmode@gnu.org; Wed, 09 Jul 2014 13:11:08 -0400 Received: from ix.urz.uni-heidelberg.de (cyrus-portal.urz.uni-heidelberg.de [129.206.100.176]) by relay2.uni-heidelberg.de (8.13.8/8.13.8) with ESMTP id s69HB3H6030483 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Wed, 9 Jul 2014 19:11:04 +0200 Received: from extmail.urz.uni-heidelberg.de (extmail.urz.uni-heidelberg.de [129.206.100.140]) by ix.urz.uni-heidelberg.de (8.13.8/8.13.8) with ESMTP id s69HB3oG010014 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 9 Jul 2014 19:11:03 +0200 Received: from [192.168.2.194] (dslb-092-074-018-215.pools.arcor-ip.net [92.74.18.215]) (authenticated bits=0) by extmail.urz.uni-heidelberg.de (8.13.4/8.13.1) with ESMTP id s69HAlJn013016 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-SHA bits=128 verify=NO) for ; Wed, 9 Jul 2014 19:11:02 +0200 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-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org This is a multi-part message in MIME format. --------------020007010800050404010904 Content-Type: text/plain; charset=ISO-8859-15; format=flowed Content-Transfer-Encoding: 7bit Hello everybody, I would like to provide a patch for the ox-bibtex.el module which can now handle bibtexfile destinations of the form: #+BIBLIOGRAPHY: /home/user/Literature/foo.bib plain option:-d but still accepts bibfiles in the working directory. I really like this module as it makes on-the-fly literature referencing so easy, but I really missed the "feature" to use include global bib-files for example. As I recognized other users had the same feeling, as these threads on the list show: - problem of path in using ox-bibtex, Joseph Vidal-Rosset, 2014-01-05 08:35:58 GMT - [O] ox-bibtex: How to use Bib file in a different directory?, Richard Stanton, 2014-02-17 11:09:39 -8:00. As motivation I think this solution is more convenient than creating symbolic links or changing environment variables/config-files. I used functions like 'file-name-base`, so in principle this implementation should be OS-independent but I did not test this, maybe this should be tried for MS-OS paths for example. Hope this is of any use. Best, Konrad Herbst --------------020007010800050404010904 Content-Type: text/x-patch; name="0001-ox-bibtex.el-Extend-to-use-bibtex-files-not-in-curre.patch" Content-Disposition: attachment; filename*0="0001-ox-bibtex.el-Extend-to-use-bibtex-files-not-in-curre.pa"; filename*1="tch" Content-Transfer-Encoding: quoted-printable X-MIME-Autoconverted: from 8bit to quoted-printable by relay2.uni-heidelberg.de id s69HB3H6030483 >From 9c17d3df2de6a39229970461da80fb6d04bb6467 Mon Sep 17 00:00:00 2001 From: Konrad Herbst Date: Wed, 9 Jul 2014 15:26:10 +0200 Subject: [PATCH] ox-bibtex.el: Extend to use bibtex files not in current working directory * contrib/lisp/ox-bibtex.el (org-bibtex-process-bib-files): Process bibte= xfilename so that it does not have to be in the same directory. --- contrib/lisp/ox-bibtex.el | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/contrib/lisp/ox-bibtex.el b/contrib/lisp/ox-bibtex.el index 7caa2e2..7cb8972 100644 --- a/contrib/lisp/ox-bibtex.el +++ b/contrib/lisp/ox-bibtex.el @@ -36,7 +36,7 @@ ;; ;; The usage is as follows: ;; -;; #+BIBLIOGRAPHY: bibfilebasename stylename optional-options +;; #+BIBLIOGRAPHY: bibfilename stylename optional-options ;; ;; e.g. given foo.bib and using style plain: ;; @@ -44,6 +44,10 @@ ;; ;; "stylename" can also be "nil", in which case no style will be used. ;; +;; Full filepaths are also possible: +;; +;; #+BIBLIOGRAPHY: /home/user/Literature/foo.bib plain option:-d +;; ;; Optional options are of the form: ;; ;; option:-foobar pass '-foobar' to bibtex2html @@ -187,7 +191,16 @@ Return new parse tree." (when (equal (org-element-property :key keyword) "BIBLIOGRAPHY") (let ((arguments (org-bibtex-get-arguments keyword)) (file (org-bibtex-get-file keyword)) - temp-file) + temp-file + out-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 direc= tory + ;; so define a variable for this. + (setq out-file (file-name-base file)) ;; limit is set: collect citations throughout the document ;; in TEMP-FILE and pass it to "bibtex2html" as "-citefile" ;; argument. @@ -219,7 +232,7 @@ Return new parse tree." (and temp-file (delete-file temp-file)) ;; Open produced HTML file, and collect Bibtex key names (with-temp-buffer - (insert-file-contents (concat file ".html")) + (insert-file-contents (concat out-file ".html")) ;; Update `org-bibtex-html-entries-alist'. (goto-char (point-min)) (while (re-search-forward @@ -233,14 +246,14 @@ Return new parse tree." ((org-export-derived-backend-p backend 'html) (insert (format "
\n

%s

\n" (org-export-translate "References" :html info))) - (insert-file-contents (concat file ".html")) + (insert-file-contents (concat out-file ".html")) (insert "\n
")) ((org-export-derived-backend-p backend 'ascii) ;; convert HTML references to text w/pandoc (unless (eq 0 (call-process "pandoc" nil nil nil - (concat file ".html") + (concat out-file ".html") "-o" - (concat file ".txt"))) + (concat out-file ".txt"))) (error "Executing pandoc failed")) (insert (format @@ -249,7 +262,7 @@ Return new parse tree." "References" (intern (format ":%s" (plist-get info :ascii-charset))) info))) - (insert-file-contents (concat file ".txt")) + (insert-file-contents (concat out-file ".txt")) (goto-char (point-min)) (while (re-search-forward "\\[=C2=A0\\[bib\\][^=C2=A0]+=C2=A0\\(\\]\\||[\n\r]\\)" nil t) --=20 2.0.0 --------------020007010800050404010904--