从一个Emacs的中文提供文件自动完成Pandoc式引用 [英] Autocomplete Pandoc-style citations from a Bibtex file in Emacs

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

问题描述

Pandoc式引用

Pandoc 使用支持使用按键从的BibTeX文件的自动引用一个Markdown格式。的格式的一些例子是:

等等等等[@ doe99]

等等等等[@ doe99,第33页]

等等等等[见@ doe99,页33-35。还@ smith04,CH。 1]。

Emacs和Pandoc /降价

有用于与通过的Emacs Pandoc其可以结合交互的 Pandoc模式 < A HREF =htt​​p://jblev​​ins.org/projects/markdown-mode/>降价模式。 Pandoc模式和降价模式不支持引用自动完成从中文提供文件。有这种支持的TeX文件的方式是 Reftex 。我正在寻找一种方式编辑减价文件时获得Reftex式的自动完成。

自动完成在其他编辑

有是TextMate的一个解决方案:自动完成pandoc式引用从中文提供文件的TextMate

该功能也是 VIM-Pandoc


  

自动完成是通过在乳胶Box的劈砍而去实施
  实施读者预约完成的,即便结果
  不看很像原始的。


如何获得pandoc式引用自动完成从中文提供文件在Emacs?


解决方案

要做到这一点,你可以使用 reftex引

设置

启用RefTeX

您必须启用您正在编辑可以通过的Mx reftex模式或通过设置的 这样的文件变量添加 - * - 模式:reftex; - * - 来的文件的第一行

告诉RefTeX,你参考书目

您需要告诉RefTeX 您的书目文件。这可以通过(根据您的设​​置和编辑路径)添加以下到您的.emacs完成:

;;这样RefTeX发现我的书目
(setq reftex默认-书目(路径/要/ bibfile.bib))

注意 reftex默认-书目是一个列表,这样你就可以添加多个路径给它。

如果您使用不同的书目为不同的文件可能是preferable告诉每个文件的书目RefTeX。恐怕我只知道一个丑陋的方式做到这一点。我们的想法是,既然RefTeX可以由乳胶宏提取正确的书目可以在注释中嵌入乳胶宏。因此,你可以沿着添加这样的评论与书目以Pandoc规格:

 书目:: bibliography_name.bib
&LT;! - \\ {书目} bibliography_name这样RefTeX知道参考书目 - &GT;

告诉RefTeX如何格式化引用

要获得 reftex引在使用Pandoc你必须自定义<一的格式插入href=\"http://www.gnu.org/software/auctex/manual/reftex/reftex_60.html\"><$c$c>reftex-cite-format比如插入以下到您的.emacs:

(EVAL-后负荷'reftex - 瓦尔
  (progn这个
     (setq reftex-引用格式((?\\ C-M。[@%L])))))

您可以婉包括其他格式了。有关如何做到这一点看 http://tex.stackexchange.com/a/31992/5701说明。请注意,此设置是全局设置,因此如果您还使用RefTeX为LaTeX的它也将受到影响。

使用

要插入引文要么做的Mx reftex引抄送[然后preSS <大骨节病>输入和你被允许插入一个检索词在你的书目搜索。那么RefTeX将插入你Pandoc格式选择的书目项目的关键。

Pandoc-style citations

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 [see @doe99, pp. 33-35; also @smith04, ch. 1].

Emacs and Pandoc/Markdown

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.

Autocompletion in other editors

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

The feature is also in Vim-Pandoc:

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.

How can I get autocompletion for pandoc-style citations from a bibtex file in Emacs?

解决方案

To do this you can use reftex-citation.

Setup

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

Tell RefTeX where you bibliography is

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

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

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

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

You may wan to include other formats too. For instructions on how to do this see http://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.

Use

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的中文提供文件自动完成Pandoc式引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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