Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Emacs: unifying citations between html and latex in org-mode

Tags:

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>
...
like image 840
Anton Tarasenko Avatar asked Sep 01 '11 10:09

Anton Tarasenko


1 Answers

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.

like image 193
e3bo Avatar answered Nov 24 '22 07:11

e3bo