【问题标题】:Emacs: unifying citations between html and latex in org-modeEmacs:在 org-mode 中统一 html 和 latex 之间的引用
【发布时间】:2011-09-01 10:03:37
【问题描述】:

如何设置 org-mode 以便在 HTML 导出中包含\cite LaTeX 命令的结果

例子:

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 导出非常棒。但是 HTML 预期会产生所有引用,因为它们在源中。但是如何实现这样的输出:

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

【问题讨论】:

    标签: html emacs latex org-mode


    【解决方案1】:

    org-mode contributed packageorg-exp-bibtex.el 使用bibtex2html 生成 HTML 参考书目,然后在导出为 HTML 时将引用命令转换为参考书目项目的链接。 org-exp-bibtex.el 中有一些文档。

    我将提供一些额外的信息来帮助我让这个功能在我的系统上运行。 org-exp-bibtex.el 文件似乎带有最新版本的 org 模式。因此,如果您评估(require 'org-exp-bibtex),例如,将其放入您的~/.emacs,然后将#+BIBLIOGRAPHY: classics plain 之类的东西放入源文件中代替您的LaTeX \bibliographystyle\bibliography 命令,则导出可能会起作用。我发现我的系统需要以下org-exp-bibtex.el 的补丁。

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

    如果您收到错误“符号的函数定义为无效:flet”,第一个更改会有所帮助,我了解到here。第二个更改只是调用 bibtex2html 并将 TMPDIR 设置为当前目录。 bibtex2html homepage 建议解决 bibtex2html 在某些 TeX 安装中遇到的问题。

    【讨论】:

    • 您介意用diff -u 而不是diff 重新生成这个补丁吗?
    • @Zack,刚刚按要求重新生成了补丁。
    • 谢谢!更容易理解您以这种方式所做的更改。
    • @Anton,在我进行补丁中的第二次更改之前,我遇到了同样的错误。正如您在补丁中看到的那样,当 bibtex2html 命令失败时会出现此错误,因此您可能想看看是否可以在命令行上自行运行 bibtex2html。
    • 请注意,包更改了名称,现在称为ox-bibtexorgmode.org/worg/org-contrib原始文件:orgmode.org/w/?p=org-mode.git;a=blob_plain;f=contrib/lisp/…
    【解决方案2】:

    e3bo 的回答非常好,涵盖了原始问题所要求的所有内容。但是,我无法从发布的补丁中获得所需的结果。我收到了 Anton 在 cmets 中对 e3bo 的回答指出的 Args out of range 错误。下面是从a separate, unrelated, question on SO 的答案之一派生的 e3bo 补丁的不同实现。我不能说我知道为什么这个补丁对我有用而 e3bo 的不行。它们彼此并没有特别的不同。无论如何,我已经发布了补丁,希望它可以解决用户无法通过其他方式正确获取bibtex2html的问题。

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

    【讨论】:

    • 谢谢!我也让 Args 超出范围......这有帮助!
    【解决方案3】:

    e3bo 的答案中提到的贡献包已将其名称更改为ox-bibtex.el(另请参阅list of Org mode's contributed packages 中的条目)。用法保持不变。但是,现在插入~/.emacs 的行必须是(require 'ox-bibtex)

    【讨论】:

      【解决方案4】:

      最近在 org-mode 中支持 ebib,在撰写此回复时,它至少适用于其开发版本。

      步骤:

      1. 确保在您的文档中正确设置 ebib-preload-bib-files,以便在 ebib 启动时由 ebib 加载您的 .bib 文件

      2. 将以下内容添加到您的 .emacs:(org-add-link-type "ebib" 'ebib)

      3. 在您的文档中插入 ebib 链接,如下所示:[ebib:Jones1998][some paper title]

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-07-20
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-06-11
        相关资源
        最近更新 更多