从Emacs中的Bibtex文件自动完成潘多克式引用 [英] Autocomplete Pandoc-style citations from a Bibtex file in Emacs

查看:209
本文介绍了从Emacs中的Bibtex文件自动完成潘多克式引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Pandoc 使用Markdown格式它支持使用BibTeX文件中的键自动引用。格式的一些示例是:

Pandoc uses a Markdown format that supports automatic citations using keys from BibTeX files. Some examples for the format are:

Blah blah [@ doe99]

Blah blah [@ doe99,p.33]

Blah blah [见@ doe99,pp。33-35;也@ smith04,ch。 1]。

有一个 Pandoc-Mode ,通过Emacs与Pandoc进行交互,可以与Markdown-Mode 。 Pandoc模式和Markdown模式不支持从bibtex文件自动完成引用。对TeX文件有这种支持的模式是 Reftex 。我正在寻找一种在编辑Markdown文件时获得Reftex-style自动完成的方法。

There is a Pandoc-Mode for interacting with Pandoc through Emacs which can be combined with Markdown-Mode. Pandoc-Mode and Markdown-Mode don't support autocompletion of citations from bibtex files. A mode that has this kind of support for TeX files is Reftex. I am looking for a way to get Reftex-style autocompletion when editing Markdown files.

Textmate有一个解决方案:从文本中的bibtex文件自动完成泛型引用

There is a solution for Textmate: Autocomplete pandoc-style citations from a bibtex file in textmate.

此功能还在 Vim-Pandoc 中:


自动完成是通过 LaTeX Box的
执行bibtex引用完成,即使结果
看起来不像原来的那样。

Autocompletion was implemented by hacking away at LaTeX Box's implementation of bibtex citation completion, even if the results don't look much like the original.



如何从Emacs中的bibtex文件获取pandoc样式引用的自动填充?


推荐答案

要做到这一点可以使用 reftex-citation

To do this you can use reftex-citation.

您必须为您正在编辑的文件启用RefTeX,该文件可以通过 Mx reftex-mode 或通过设置文件变量,例如添加 - * - mode :reftex; - * - 到文件的第一行。

You have to enable RefTeX for the file you are editing which can be done via M-x reftex-mode or by setting a file variable such as adding -*- mode: reftex; -*- to the first line of the file.

您需要告知RefTeX 您的参考书目档案在哪里。这可以通过将以下内容添加到.emacs中(并根据您的设置编辑路径):

You need to tell RefTeX where your bibliography file is. This can be done by adding the following to your .emacs (and editing the path according to your setup):

;; So that RefTeX finds my bibliography
(setq reftex-default-bibliography '("path/to/bibfile.bib"))

请注意, reftex-default-bibliography 是一个列表,因此您可以添加几条路径。

Note that reftex-default-bibliography is a list, so you can add several paths to it.

如果您为不同的文件使用不同的参考书目,最好从每个文件中提取参考书目的RefTeX。恐怕我只知道这样做的丑陋的方式。这个想法是,由于RefTeX可以从LaTeX宏中提取正确的参考书目,您可以在注释中嵌入LaTeX宏。因此,您可以将这样的评论与参考书目的规范一起添加到Pandoc中:

If you use different bibliographies for different files it might be preferable to tell RefTeX of the bibliography from each file. I am afraid I only know of an ugly way to do this. The idea is that since RefTeX can extract the correct bibliography from LaTeX macros you can embed a LaTeX macro in a comment. Thus, you can add such a comment along with the specification of bibliography to Pandoc:

bibliography::bibliography_name.bib
<!-- \bibliography{bibliography_name} So that RefTeX knows about the bibliography -->



告诉RefTeX如何格式化引用



要获取 reftex-citation 以Pandoc使用的格式插入,您必须自定义 reftex-cite-format ,例如将以下内容插入到.emacs中:

Tell RefTeX how to format citations

To get reftex-citation to insert in the format used by Pandoc you have to customize reftex-cite-format such as inserting the following into your .emacs:

(eval-after-load 'reftex-vars
  '(progn 
     (setq reftex-cite-format '((?\C-m . "[@%l]")))))

你也可能会包括其他格式。有关如何执行此操作的说明,请参阅 https://tex.stackexchange.com/a/31992/5701 。请注意,此设置是全局的,因此如果您还使用RefTeX for LaTeX,它也将受到影响。

You may wan to include other formats too. For instructions on how to do this see https://tex.stackexchange.com/a/31992/5701. Note that this setting is global so that if you also use RefTeX for LaTeX it will also be affected.

要插入引文,请执行 Mx reftex-citation Cc [然后按输入,并且您可以在您的参考书目中插入搜索词来搜索。 RefTeX然后将插入您所选择的参考书目项目的关键字Pandoc格式。

To insert a citation either do M-x reftex-citation or C-c [ then press Enter and you are allowed to insert a search term for searching in your bibliography. RefTeX will then insert the key of the bibliography item you selected in Pandoc format.

这篇关于从Emacs中的Bibtex文件自动完成潘多克式引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆