# RefTeX won't find my .bib file in local library tree

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 RefTex won't 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}

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

-
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 '12 at 6:57
Does putting the following in your .emacs help? (setq reftex-default-bibliography '("~/Library/texmf/bibtex/bib/master_bib.bib")) –  N.N. May 7 '12 at 7:49
@JosephWright, I tried \bibliography but RefTeX still does not find the .bib file. Wouldn't \bibliographystyle be BibTex syntax? –  Ricardo May 7 '12 at 16:21
@N.N., adding the default bibliography to my .emacs did not help either. –  Ricardo May 7 '12 at 16:52
@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 '12 at 18:41
show 1 more comment

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.


Both variables are documented in the manual.

-
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 '12 at 13:44
@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 '12 at 19:29
@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 '12 at 19:52
@N.N. Since setting reftex-bibliography-commands solved the issue, I don't see a reason to use the file variables. Please correct me in case I'm missing something. –  Dror Aug 15 '12 at 6:29
@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 '12 at 7:39

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.

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