Autocomplete Pandoc-style citations from a Bibtex file in Emacs

前端 未结 1 1899
自闭症患者
自闭症患者 2021-02-05 14:23

Pandoc-style citations

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

Bl

1条回答
  •  暖寄归人
    2021-02-05 14:46

    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
    
    

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

    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.

    0 讨论(0)
提交回复
热议问题