The basic way to use BibTeX is to put your bibliography file in the same folder as your Tex document. You are then able to refer to it simply by its name. For instance, if your bibliography file is mybooks.bib, you need only insert the following line in your TeX document in order to use it:

\bibliography{mybooks}

(The .bib extension is not needed. Cf. here for a complete example.)

However, doing that forces you into one of two evils: either your put all your TeX documents in a same folder, which is clumsy, or you have serveral copies of your bibliography around, which is clumsy. Typically, you will have many documents that would need to be sorted out in different folders, while you have only one or two bibliography files that you keep updated.

So the best way to go is to keep your bibliography file(s) in one single place, but to have your TeX documents in different folders. At least that is what I wanted to do. But using a bibliography file from a different folder can be quite tricky, especially under Windows. Here are two ways to do it:

Solution 1: full path name

Suppose the location of your BibTeX file is F:\SomeFolder\BibTeX\mybooks.bib. You can call it in your TeX document by using the full path:

\bibliography{F:/SomeFolder/BibTeX/mybooks}

But be careful:

  • The path names in Windows use anti-slashes (as in F:\folder\subfolder). However, these create errors under LaTeX and you should simply replace them by slashes (e.g. F:/folder/subfolder).
  • You cannot have spaces in your path name. For instance, \bibliography{F:/My Documents/mybooks.bib} won't work.

That is the simplest solution. However:

  • As noted, you cannot put your bibliography in a folder whose path includes a space, such as My Documents.
  • The TeX document is less portable. You need to update the bibliography name if you put it on a different computer. More importantly, you cannot move your bibliography file without all your TeX documents loosing it.
  • I have read (Andrew Schulman, here) that the LaTeX documentation recommends against specifying extra path components within \include's, \input's, and \bibliography's, because TeX has a limited amount of storage for filenames. In a large document you could conceivably use up all of that space.

Solution 2: set up the bibtex command

A nicer solution involves altering the BibTeX command. Let me first give the idea. When you run BibTeX for your TeX document, something like the following commands is executed:

bibtex MyTeXDocument
bibtex F:\My Stuff\texdocs\MyTeXDocument

Now you can tell BibTeX to lookup for the bibliography file in a different folder by using the --include-directory option:

bibtex --include-directory="F:\My Documents\mybibliographyfolder" MyTexDocument

If your Tex document includes \bibliography{MyBooks}, the command above will search for MyBooks.bib in F:\My Documents\mybibliographyfolder as well as in the Tex document's folder. (If there's a .bib file of that name in both folder, I don't know which one will be used - you try it! But there shouldn't be one in the first place!)

Now you probably don't run BibTeX by yourself, but through a TeX editor like Emacs with AUCTex, TeXnic, WinEdt or some other. So you have to find how to alter the command in the editor's options. Here's how to do with the three just listed:

Emacs with AUCTex.

In short: in the tex-command-list option, there's an entry for the bibtex command that you can alter. In detail: Menu > Options > Customize Emacs > Browse Customization Groups. A new buffer opens in which you can browse the various Emacs settings. Go to: Wp > Tex > AUCTeX > TexCommand > Tex Command List. Open it: the buffer shows a list of entries of the TeX commands that AUCTeX launches. Find the command named "BibTeX", and replace the command field:

bibtex $s

by:

bibtex --include-directory="F:\my bibliography folder" $s

Don't forget to save the new setting (at the top of the buffer, clic on "Save for future sessions").

TeXnic.

Menu > Build > Define Output Profile. A windows opens with the settings for each output profile (tex => dvi, tex => pdf, etc.). Each profile has a bibtex section. Change the field "Command line arguments to pass to BibTeX" from:

"%bm"

to

--include-directory="D:\bib test" "%bm"

Do the same for all outprofiles you use.

TeXworks

gsk (comment #10 below) recommends:

bibtex --include-directory="F:\my bibliography folder" %s

WinEdt

Menu > Options > Executions Modes... A window opens with several tabs. In the "Console Applications" tab, you find a list of commands. Select bibtex, and add to the "Switches" field:

--include-directory="F:\my bibliography folder"

And that's it.

(Note, if something goes wrong in WinEdt, it might be useful to look at the output of LaTeX and BibTeX (by default, the console outputs windows close just after the execution of LaTeX/BibTeX is finished. In order to read the output, go back to the Execution modes dialog box, and in the Console Attributes section click "Pause if OK".)

Notes and links

The comp.text.tex mailing list had a thread in 2001 which suggested adding a customized config file for MikTeX, but that is not possible in later versions of MikTeX: the -personal switch of initexmf has been removed.

I found the way to modify AUCTeX on the GNU AUCTeX list here. Note that changing the Tex-Run options will not work when you use AUCTeX.