Using BibTex in LATEX documents

Rob MacLeod

BibTex is a program that reads entries from a database of citations based on the output of LATEX and then makes a bibliography file that LATEX can insert into the document. There is lots to say about BibTex (and some good manuals that do it well) but here are some essentials I have found useful and not covered in the books. (There is a lot to say and learn about LATEX too).

Finding the material for a BibTex database is a chapter of its own, covered at least briefly at http://www.sci.utah.edu/~macleod/litbase

There is a repository of bibtex files available for use at the SCI Institute.

Quick Links:

  1. Usage Conventions
  2. Teaching Bibtex to find your bibtex files
  3. BibTex, PMCID, and the NIH
  4. Editing BibTex files
  5. Additional BibTex tools

1 Usage Conventions

There are a suggestions when using BibTex:

  1. The standard way to show citations in the text is as ``[N]'' where N is the reference number in the bibliography. We often use a style and a package called as \usepackage[super]{cite} in the LaTeX file that writes them as superscripted numbers. This style is also smart enough to find sequences of numbers and compress them, e.g., text1,2,3,4,5,9 becomes text1-5,9.
  2. Enter refs as you go and do not leave them all to the last minute! This makes for unnecessary stress when we need it least. Give us your refs in whatever form you have and we can get them entered now.
  3. If you are part of SCI (or otherwise smart and organized), please note the key naming conventions we use. You can find these in the SCI Bibtex tips web page.

2 Teaching Bibtex to find your bibtex files

The default location for the Bibtex files for a document are in the same directory as that document. A slightly better solution is to have a directory that holds all your Bibtex files and then hard-wire the commands in LateX to find those files.

A better way (the best way?) is to store all your Bibtex files in one place in your computer, ideally managed through a system like Subversion, and then to tell the Bibtex program where to look. How this works depends on the operating system and the Bibtex application, of course, but here are some typical examples. I found a lot of this information at this web site by Julien Dutant .

3 BibTex, PMCID, and the NIH

NIH requires public disclosure of journal articles supported by NIH funding and all such articles receive a code called the PMCID as part of the PubMed system. As an NIH funded researcher, you MUST include this code every time you cite such a reference, especially in progress reports, proposals, and biosketches.

To support this code in BibTeX, I have created a slightly modified version of one of the most common BibTeX style files (.bst), which is available here.

To use this new style file,

  1. Add a field called "pmcid" to each BibTeX reference that contains the PMCID string, which you can locate by searching for the papers in the PubMed system.
  2. Modify your \bibiographystyle command to look (something) like this:
       \bibliography{strings,biglit,crj,rtw,jgs,md,cdh,dhb,jaw,crb,sci}
       \bibliographystyle{nihunsrt}
    

4 Editing BibTex files

To edit a BibTex file, you can use any editor but emacs has lots of great support for this process. The ones I like are Nelson Beebe's emacs tools found at www.math.utah.edu/pub/emacs/, in particular bibtools and bibtex-support.

Here is what my .emacs contains to access these:

;;; Add bibtex mode unconditionally; it is already bound to text-mode
;;; and we can do better than that.
(delq (assoc "\\.bib$" auto-mode-alist) auto-mode-alist)
(setq auto-mode-alist
      (cons (cons "\\.bib$" 'bibtex-mode) auto-mode-alist))
(autoload 'bibtex-mode  "~/emacs/lisp/bibtex/bibtex"
;(autoload 'bibtex-mode  "bibtex"
  "Enter BibTeX mode for bibliography editing." t nil)

(setq bibtex-mode-hook '(lambda ()
                          (setq comment-end "")
                          (setq comment-start "%% ")
                          (setq comment-start-skip "%+ *")
                          (setq bibtex-include-OPTcrossref nil)
                          (setq bibtex-include-OPTkey nil)
                          (setq bibtex-include-OPTannote nil)
                          (setq bibtex-include-robnote t)
                          (load "~/emacs/lisp/bibtex/bibtex-support")
                          (load "~/emacs/lisp/bibtex/bibtools")
                          ))

Note that these commands assume a subdirectory called emacs/lisp in which the require lisp code (.el or .elc files) is available.

5 Additional BibTex tools

There are some other fun software tools that can make life easier with BibTex. Most are in the public domain in one form or another and I have included links where I had them--if the links fail, use Google and please let me know (macleod@sci.utah.edu).

5.1 EndNote

EndNote is not really a program that works on BibTexfiles but it does manage citations well and it has some support for BibTex that can make it useful.

See endnote.html for more details on how to convert between Endnote and BibTex.

5.2 bibclean

The goal of bibclean is to clean up syntax and layout errors in BibTex files so that all entries have a nice, clean look that is consistent. The program will also reveal some errors in the file, which can be very helpful! To get bibclean, surf on over to
www.math.utah.edu/pub/bibclean/ and thank Nelson Beebe for making this available.

Here are some direct links that might be helpful

One of the many arguments to bibclean essential for SCI databases, if only because it is the convention we had adopted:

    bibclean -no-fix-names
which I actually alias to bibclean so that I don't forget!

5.3 Mendeley

The free literature databased program Meddeley has support for Bibtex output.

5.4 Converting from Word bibliography to BibTex

This is truly amazing! There is a website called hubmed.org that will convert from Word document text that you copy to the web page into Bibtex files! It actually works.

This program is some sort of search engine interface to Pubmed and it manages to parse the text and propose matches for each entry in the bibliography. I am really impressed with this tool!

5.5 Testing a BibTex file

There is a simple way to test a BibTex file for completeness using LATEX and the bibtex commands from your own computer. Testing is a good plan, especially if you do it after editing the file and not when you are in a hurry and have to build a document using the file.

To test a BibTex file, make a LaTeX file, call it testbib.tex with the following contents:

    \documentclass[]{article}
    \begin{document}

    Some text.
     \nocite{*}

    \bibliography{sci}
    \bibliographystyle{unsrt}

    \end{document}
where ``sci'' is the name of the BibTex file to test.

Then run

    latex testbib
    bibtex testbib
and the output will list all the errors or warnings resulting from trying to parse the file sci.bib. Some of the output will be warnings that you can ignore but other errors can be fatal the next time you use the file.

5.5 BibDesk

BibDesk is a Mac OSX program to edit and manage your bibliography. It will keep track of both the bibliographic information and the associated files or web links for you. Read more at bibdesk.sourceforge.net/.

5.6 JabRef

JabRef is a new cross platform, open source program to edit and manage your bibliography. It performs searches and downloads articles (assuming they are open access) and seems to have a lot of customlization options. It claims to integrate well with many LaTeX systems/editors, including eXstudio, LyX, Kile, LatexEditor, Emacs, Vim, and WinEdt.


Last modified: Sat Mar 25 08:37:38 MDT 2017