开发者

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

开发者 https://www.devze.com 2023-04-01 22:09 出处:网络
How to set up org-mode so it could include the result of \\cite LaTeX command in HTML export? Example:

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}

\pri开发者_开发问答ntbibliography

#+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>
...


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'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)))


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).


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]

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号