20

How to set up org-mode so it could include the result of \cite LaTeX command in HTML export?

Example:

Gulliver's Travels

My father had a small estate in Nottinghamshire: I was
the third of five sons.\cite{swift1726}

\printbibliography

#+LaTeX_HEADER: \usepackage{biblatex}
#+LaTeX_HEADER: \bibliography{classics}

LaTeX export is absolutely great. But HTML expectantly produce all citations as they are in source. But how to achieve an output like this:

...
<title>Gulliver's Travels</title>
...
<p>My father had a small estate in Nottinghamshire: I was
the third of five sons.[<a href="#swift1726">1</a>]</p>
...
<p id="swift1726">[1] J. Swift. <i>Gulliver's Travels</i>. 1726.</p>
...
Anton Tarasenko
  • 8,099
  • 11
  • 66
  • 91

4 Answers4

11

The org-mode contributed package org-exp-bibtex.el produces an HTML bibliography using bibtex2html and then turns cite commands into links to bibliography items when you export to HTML. There is some documentation in org-exp-bibtex.el.

I will include some additional information that helped me get this feature to work on my system. The file org-exp-bibtex.el seems to come with recent versions of org mode. So export may just work if you evaluate (require 'org-exp-bibtex) by, for instance, putting it in your ~/.emacs and then put something like #+BIBLIOGRAPHY: classics plain in your source file in the place of your LaTeX \bibliographystyle and \bibliography commands. I found the following patch to org-exp-bibtex.el was needed for my system though.

--- /usr/share/emacs/site-lisp/org_contrib/lisp/org-exp-bibtex.el   2011-08-09  7:39:35.000000000 -0500
+++ /home/who/.emacs.d/site-lisp/org-exp-bibtex.el  2011-09-06 20:34:55.000000000 -0500
@@ -56,6 +56,7 @@
 ;; 2) creates a foo.html and foo_bib.html
 ;; 3) includes the contents of foo.html in the exported html file

+(require 'cl)
 (require 'org)
 (require 'org-exp)

@@ -90,11 +91,13 @@
        (setq tmp-files   (cons tmp tmp-files))
        (setq extra-args (append extra-args `("-citefile" ,tmp)))))

-       (when (not (eq 0 (apply 'call-process  (append '("bibtex2html" nil nil nil)
+            (let ((process-environment (copy-alist process-environment)))
+              (setenv "TMPDIR" ".")
+             (when (not (eq 0 (apply 'call-process  (append '("bibtex2html" nil nil nil)
                               `("-a" "--nodoc"  "--style" ,style "--no-header")
                               extra-args
                               (list (concat file ".bib"))))))
-         (error "Executing bibtex2html failed"))
+         (error "Executing bibtex2html failed")))

            (dolist (f tmp-files) (delete-file f)))

The first change helps if you get the error "Symbol's function definition is void: flet", I learned here. The second change just calls bibtex2html with TMPDIR set to the current directory. The bibtex2html homepage suggests such a workaround for a problem that bibtex2html has with some TeX installations.

e3bo
  • 1,663
  • 1
  • 14
  • 9
  • Would you mind regenerating this patch with `diff -u` instead of just `diff`? – zwol Sep 07 '11 at 03:04
  • @Zack, just regenerated the patch as requested. – e3bo Sep 07 '11 at 03:24
  • Thanks! Much easier to understand the change you made this way. – zwol Sep 07 '11 at 03:26
  • Thanks for the solution. I hope it will be helpful for others. I just get `progn: Executing bibtex2html failed` error. – Anton Tarasenko Sep 07 '11 at 14:05
  • 1
    @Anton, I was getting the same error before I made the second change that is in the patch. As you can see in the patch, this error comes up when the bibtex2html command fails, so you may want to see if you can run bibtex2html by itself on the command line. – e3bo Sep 07 '11 at 21:45
  • @e3bo, I do get `Forbidden to open for writing` from bibtex2html in command line but `setenv` seems to be not very helpful in Windows. I also rewrote `("-a" "-nodoc" "-s" ,style "-noheader")` (according to `bibtex2html.exe -h`) and still without success. – Anton Tarasenko Sep 08 '11 at 05:18
  • I found that `bibtex2html` for Windows just ignores `TMPDIR`. It prefers `TEMP` environment. When this environment is set to `.` in System Properties and `org-exp-bibtex.el` has not been modified, bibtex2html does its job. With `setenv` modifications (rewritten to `(setenv "TEMP" ".")`, Emacs says `let: Args out of range: 0, 5`. The second point is that ODT export doesn't work with `org-exp-bibtex` (`let: Wrong type argument: stringp, nil`). – Anton Tarasenko Sep 08 '11 at 11:27
  • If you tried the patch above but no luck, maybe simply using `#+BIBLIOGRAPHY: classics` or `#+BIBLIOGRAPHY: plain` can eliminate your error. At least this works for my case. – asksw0rder Oct 25 '12 at 22:29
  • 1
    Note that the package changed name and is now calld `ox-bibtex` http://orgmode.org/worg/org-contrib/ Raw file: http://orgmode.org/w/?p=org-mode.git;a=blob_plain;f=contrib/lisp/ox-bibtex.el;hb=HEAD – Geeklhem Apr 23 '15 at 03:30
3

e3bo's answer is excellent and covers all of what the original question asks for. I, however, was unable to obtain the desired results from the patch posted. I receive the Args out of range error noted by Anton in the comments to e3bo's answer. Below is a different implementation of e3bo's patch derived from one of the answers to a separate, unrelated, question on SO. I can't say I know why this patch works for me and e3bo's doesn't; they're not particularly different from each other. At any rate, I've posted the patch in the hopes that it may solve problems experienced by users unable to get bibtex2html properly through other means.

--- org-exp-bibtex.el.orig      2013-01-05 15:00:53.000000000 -0600
+++ org-exp-bibtex.el   2013-01-05 16:34:54.000000000 -0600
@@ -89,12 +89,13 @@
                (with-temp-file tmp (dolist (i cite-list) (insert (concat i "\n"))))
                (setq tmp-files   (cons tmp tmp-files))
                (setq extra-args (append extra-args `("-citefile" ,tmp)))))
-
-           (when (not (eq 0 (apply 'call-process  (append '("bibtex2html" nil nil nil)
+           
+           (let ((process-environment (cons "TMPDIR=." process-environment)))
+             (when (not (eq 0 (apply 'call-process  (append '("bibtex2html" nil nil nil)
                                                           `("-a" "--nodoc"  "--style" ,style "--no-header")
                                                           extra-args
                                                           (list (concat file ".bib"))))))
-             (error "Executing bibtex2html failed"))
+             (error "Executing bibtex2html failed")))

            (dolist (f tmp-files) (delete-file f)))
Community
  • 1
  • 1
3

The contributed package referred to in e3bo's answer has changed its name to ox-bibtex.el (see also its entry in the list of Org mode's contributed packages). Usage remains the same. However, now the line inserted in ~/.emacs must be (require 'ox-bibtex).

Michael Fiedler
  • 191
  • 1
  • 2
1

There is recent support now for ebib in org-mode which works at least with its development version at the time of writing this reply.

Steps:

  1. make sure ebib-preload-bib-files is set properly in your document so that your .bib file is loaded by ebib when ebib starts

  2. add the following to your .emacs: (org-add-link-type "ebib" 'ebib)

  3. insert ebib links in your documents like this: [ebib:Jones1998][some paper title]

Jaromil
  • 76
  • 5