20

How do I setup RefTeX with biblatex's citation commands? In Workflow for managing references? Seamus describes a workflow with RefTeX and mentions that

it wouldn't be too tricky to add \autocite and friends to aucTeX's cite insertion mechanism.

The biblatex citation commands I'd like to use with RefTeX is \autocite, \smartcite and \textcite. Also, I'd like RefTeX to work with csquotes' \blockcquote.

Note that I am not asking for anything that has to do with compilation (like Customising emacs to use biblatex-biber instead of bibtex).

3 Answers 3

23

The variable you need to hook into is reftex-cite-format. Somewhere in my Emacs init file, I have this code:

(eval-after-load 'reftex-vars
  '(progn
     ;; (also some other reftex-related customizations)
     (setq reftex-cite-format
           '((?\C-m . "\\cite[]{%l}")
             (?f . "\\footcite[][]{%l}")
             (?t . "\\textcite[]{%l}")
             (?p . "\\parencite[]{%l}")
             (?o . "\\citepr[]{%l}")
             (?n . "\\nocite{%l}")))))

You should to add your desired commands to this list. The first element in each pair is the letter you want to press after C-c [ to select the given citation format. The empty square brackets denote optional arguments; RefTeX has variables to control whether it prompts your for those. And %l is where the cite key goes.

(You could also set this variable via M-x customize-variable, but I loathe that particular feature of Emacs.)

I'm not sure what the syntax of \blockcquote is...if it has more non-optional arguments than just a cite key, RefTeX might not be able to fully support it (i.e., it inserts the command but you then have to move backwards to fill out other arguments).

5
  • What's the line ;; ... for?
    – N.N.
    Oct 19, 2011 at 6:29
  • @N.N., just to indicate that other reftex-related customizations go there. I've edited to clarify.
    – Aaron
    Oct 29, 2011 at 2:41
  • Why is eval-after-load used here? gnu.org/software/emacs/manual/html_node/elisp/… says "Normally, well-designed Lisp programs should not use eval-after-load."
    – N.N.
    Jan 16, 2012 at 11:23
  • 1
    @N.N., your link also says "But it is OK to use eval-after-load in your personal customizations if you don't feel that they must meet the design standards [...] for wider use." Since this code is run at emacs startup, I use eval-after-load to defer loading the reftex-vars library (until the first TeX file is opened), which cuts down on startup time – drastically, if you use eval-after-load consistently. It's a fairly common .emacs idiom AFAIK. It's also possible to use the M-x customize interface for deferred variable setting, but I dislike it (and it can't really be copy/pasted).
    – Aaron
    Jan 17, 2012 at 0:51
  • 1
    It was quite easy to use the loathed customize-variable also. M-x customize-set-value, enter customize-set-value, enter reftex-cite-format, enter format string, enter \autocite[]{%l}. (Should I add this as another answer?)
    – trmdttr
    Jun 2, 2016 at 16:59
10

Another way to integrate biblatex and csquotes with RefTeX is via YASnippet.

You make a snippet for every citation macro you want to use and have the snippets call reftex-citation.

I use a setup where I type "ct" and press Tab and then I get to choose between the two following snippets.

For \auctocite:

# -*- mode: snippet -*-
# name: autocite \autocite
# key: ct
# --
\autocite[$3]{${2:label$(unless yas/modified-p (reftex-citation 'dont-insert))}}$0

For \textcite:

# -*- mode: snippet -*-
# name: textcite \textcite
# key: ct
# --
\textcite[$3]{${2:label$(unless yas/modified-p (reftex-citation 'dont-insert))}}$0

biblatex citations called via YASnippet

I also use the following for \blockcquote:

# -*- mode: snippet -*-
# name: Formal blockquote \blockcquote
# key: fbq
# expand-env: ((yas/indent-line 'fixed))
# --
\blockcquote[$2]{${1:label$(unless yas/modified-p (reftex-citation 'dont-insert))}}{%
$0%
}

For a collection of snippets for citing with biblatex see https://github.com/Sleft/yasnippet-latex-mode/tree/master/cite.

4

To get RefTeX to work with csquotes package I use this in my .emacs:

(eval-after-load "tex"
 '(TeX-add-style-hook "csquotes"
   (lambda ()
    (TeX-add-symbols
     '("textcquote" [ "pre-note (post-note if alone)" ] [ "post-note" ] TeX-arg-cite  [ "Punctuation" ] t ignore ignore)
     '("blockcquote" [ "pre-note (post-note if alone)" ] [ "post-note" ] TeX-arg-cite  [ "Punctuation" ] t ignore ignore)
     '("foreigntextcquote"  "Language"  [ "pre-note (post-note if alone)" ] [ "post-note" ] TeX-arg-cite  [ "Punctuation" ] t ignore ignore)
     '("foreignblockcquote" "Language" [ "pre-note (post-note if alone)" ] [ "post-note" ] TeX-arg-cite  [ "Punctuation" ] t ignore ignore)
     ))))

This way when you run C-c C-m blockcquote it will prompt you for the correct arguments and you will get the RefTeX-dialog for choosing a citation label.

I have taken this from somewhere but don't remember where. The important part if you need to edit it is invoking TeX-arg-cite for the correct argument (citation label) of the macros.

1
  • I tried this but it says C-c m is undefined.
    – N.N.
    Sep 18, 2012 at 18:47

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .