44

RefTeX gives out the following error when trying to insert a citation:

  No valid bibliography in this document, and no default available

I keep a master .bib file in ~/Library/texmf/bibtex/bib/master_bib.bib. Biblatex-biber recognize the file when I run it, so a bibliography is generated. The problem is that RefTeX does not recognize the file and yields the above error. I have also placed the .bib file in the same directory as the .tex file, with the same results.

This post seemed promising https://tex.stackexchange.com/questions/23780/reftex-wont-detect-my-bib-file but that one self-resolved automagically.

The RefTeX manual (p.20) says that

If you do not use BibTEX, but the document contains an explicit thebibliography environment, RefTEX will collect its information from there.

however, I don't see where or how I could include this.

How can I get this to work?

Here's a MWE:

\documentclass{article}

\usepackage[
    backend=biber, 
    style=authoryear, 
    maxcitenames=2, 
    sorting=nyt,
    backref=true
    ]{biblatex}
    \addbibresource{master_bib.bib}

\begin{document}
    Some text. \parencite{Mays:2005, Chow:1998}

\printbibliography
\end{document}

%%% Local Variables: 
%%% mode: latex
%%% TeX-engine: xetex
%%% End:

I'm running Emacs 24, with AUCTeX 11.86, TeX Live 2011 from MacTeX.

6
  • 3
    Have you tried using \bibliography instead of \addbibresource? I suspect that RefTeX is looking for that (or maybe \bibliographystyle) to work, so it may be worth a try.
    – Joseph Wright
    May 7, 2012 at 6:57
  • 2
    Does putting the following in your .emacs help? (setq reftex-default-bibliography '("~/Library/texmf/bibtex/bib/master_bib.bib"))
    – N.N.
    May 7, 2012 at 7:49
  • 2
    @JosephWright, I tried \bibliography but RefTeX still does not find the .bib file. Wouldn't \bibliographystyle be BibTex syntax?
    – Ricardo
    May 7, 2012 at 16:21
  • @N.N., adding the default bibliography to my .emacs did not help either.
    – Ricardo
    May 7, 2012 at 16:52
  • 2
    @N.N., I take it back: I had a typo and that's why it didn't work. Would you post it as an answer so I can mark it? Without that line, RefTeX would only recognize .bib files in the same directory as the .tex file. Also, once it failed to work once, it would keep failing to work unless I restarted Emacs. Reopening the buffer after setting the correct .bib file did not change that it didn't work.
    – Ricardo
    May 7, 2012 at 18:41

5 Answers 5

46

There are two ways to make RefTeX find your bibliography. I suggest to use both approaches for robustness.

  • To make RefTeX recognize your bibliography you can add it to the list reftex-default-bibliography. To do this add the following to your .emacs:

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

    and replace path/to/bibfile.bib with the path to your bib file. Note that it is a list so that it can contain several paths if you want to point it to several bibliographies. This approach is good for accessing your .bib file via RefTeX in Org-mode.

  • Another way to make RefTeX recognize the bibliography in \addbibresource you can add it to the variable reftex-bibliography-commands by adding the following to your .emacs:

    ;; So that RefTeX also recognizes \addbibresource. Note that you
    ;; can't use $HOME in path for \addbibresource but that "~"
    ;; works.
    (setq reftex-bibliography-commands '("bibliography" "nobibliography" "addbibresource"))
    

Both variables are documented in the manual.

7
  • 1
    A related issue is that biber looks for your .bib using kpsewhich too so it will find it if it's in your tex tree somewhere. RefTeX can also do this but you have to configure it. It's in the RefTeX manual somewhere.
    – PLK
    May 8, 2012 at 13:44
  • 1
    @N.N. w.r.t. the first alternative you offered: Given that different documents have different .bib files, are you suggesting to add for each such instance an entry in the global scale (i.e. the .emacs setting)? The second suggestion solved the problem for me.
    – Dror
    Aug 14, 2012 at 19:29
  • 1
    @Dror Indeed, reftex-default-bibliography is a list so it can take several paths to bib files. If you have a bib file you only use for one or few documents I am guessing you could set it with a file variable instead of adding it to the variable in your .emacs.
    – N.N.
    Aug 14, 2012 at 19:52
  • 1
    @Dror reftex-default-bibliography are good for those cases where you have not yet added a addbibresources or similar to your document and also for when using RefTeX in Org-mode.
    – N.N.
    Aug 15, 2012 at 7:39
  • 1
    "Note that it is a list so that it can contain several paths if you want to point it to several bibliographies. This approach is good for accessing your .bib file via RefTeX in Org-mode." @N.N. Does this actually work for you? I've had no luck using multiple default bibliographies. There seems to be a bug in RefTex which has not been fixed: lists.gnu.org/archive/html/bug-auctex/2013-05/msg00005.html
    – Brian Z
    Mar 3, 2015 at 14:24
17

Adding

%%% reftex-default-bibliography: ("path/to/bibfile.bib")

at the end of my file with other commands related to the file looks better to me.

1
  • 1
    A local variable at the end of every file is another possible way to go about it. However, the question referred to a master bibliography that could be used by any file, new and existing. Going the local-variable way would force me to add that line on every new file, whereas modifying the .emacs would give me a permanent solution with just one input.
    – Ricardo
    Feb 1, 2013 at 20:06
7

I solved this problem by inserting '(reftex-use-external-file-finders t) into my emacs init file.

It makes RefTeX use the appropriate command from reftex-external-file-finders to find the file. In my case that is kpsewhich -format=.bib %f. The default is looking in the folders specified in the environment variables BIBINPUT and TEXINPUT.

I prefer this variant mainly because I expect that emacs and latex will use the same method for determining what bib file to use. It also feels more flexible, as you do not need to modify it if you create another central biblography.

2
  • What does this answer add to the one provided by m42?
    – giordano
    Nov 25, 2014 at 13:35
  • The value in that m42 change does not have an effect if you do not change set reftex-use-external-file-finders to true. In addition m42's entries are already included in the variable and are therefore redundant(I expect this to hold for later auctex versions).
    – Mixopteryx
    Nov 26, 2014 at 12:53
4

I've seen people suggest that there's a fault in RefTeX, corrected by inserting

(setq reftex-external-file-finders
'(("tex" . "/path/to/kpsewhich -format=.tex %f")
  ("bib" . "/path/to/kpsewhich -format=.bib %f")))

This is not necessary for me.

1

Sometimes the issue may just be that the file has not been parsed. This has happened to me a few times eventhough it should've been parsed when opened (especially when I have multiple latex projects open at the same time).

In such situations (supposing your reftex-bibliography-commands contains addbibresource already), the quickest fix is just M-x reftex-parse-all.

You must log in to answer this question.

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