# Department of Engineering

## IT Services

LaTeX was designed with technical reports very much in mind. The associated bibtex program makes citations and bibliographies relatively painless. With bibtex you can use the same bibliography database file for various documents. Also it's easy to change styles, which you'll appreciate when you become aware of the vast diversity of periodical requirements.

## Simple Use

You need to have a bibliography file with an entry for each item. Details on how to do this are in the next section but put the following into testbib.bib to get you started.

@BOOK
{KandR,
AUTHOR  = "Kernighan, Brian W. and Ritchie, Dennis M.",
TITLE   = "{The C Programming Language Second Edition}",
PUBLISHER = "Prentice-Hall, Inc.",
YEAR = 1988
}


The first field (in this case KandR) is the tag used when you \cite the item. How this citation appears in the text depends on the packages used and the bibliography style.

The AUTHOR field should be in the following format
Surname1, Forename1 and Surname2, Forename2 and Surname3, Forename3 ...
- this information will be reformatted in the document.

In your main latex document you need \bibliographystyle{plain} at the top to set the style and \bibliography{testbib} where you want the bibliography to appear, and to specify the bibtex file. Only cited items will appear in the bibliography. As a test, put the following in test.tex

\documentclass{article}
\bibliographystyle{plain}
\begin{document}
See \cite{KandR} for details.
\bibliography{testbib}
\end{document}


Initially you have to run latex test, bibtex test, latex test and latex test again on your document before everything appears. After that, you only have to run latex (unless you change the bibliography file).

## Creating bibliography files

bibtex offers many types of entries, each with different optional and compulsory fields - described in the bibtex handout - so you can use any editor to create the files. If you have a recent version of emacs you'll find that new menus appear when you edit *.bib files. These provide template entries, sorting facilities etc. Alternatives include

• bibview - a dedicated program with more database facilities. Runs with X windows
• JabRef - a Java application (pointed out to me by Ged Ridgway)

## Customising

Some organisations (e.g. IEEE) provide bibliographic style files for authors. If you have do to your own customization, there are various approaches

• An alternative to the plain style used in the above example is unsrt which lists references in citation order rather than author order. If you want multiple citations sorted, use the citesort package. If you want citations superscripted, use the overcite package.
• If you find that you need to make more changes than this (for instance, if you want the citations to mention the author and date), it's time to use the natbib package (see the natbib reference sheet for the essentials). Just change test.tex to the following to try it
\documentclass{article}
\usepackage{natbib}
\bibliographystyle{plainnat} % note the change here
\begin{document}
See \cite{KandR} for details.
\bibliography{testbib}
\end{document}

Now it's easy to add features. For instance, to have superscripted, sorted citations, use
...
\usepackage[super,sort]{natbib}
...

natbib offers variants like \citep, \citet and gives control over punctuation, vertical space between bibliography items, etc.
• If none of the supplied styles is adequate, then the custom-bib package can be used by typing latex makebst.tex from the command line to customise your own style - it's self-documenting; just accept the offered defaults if you have doubts.


The tocbibind package helps add bibliographies to contents pages.

## BSTINPUTS

Bibliography style definitions are stored in *.bst files. bibtex looks for these in several places. On linux systems you can find out which places by typing

   kpsewhich -var-value BSTINPUTS


The output needs decyphering. On my machine I get

.:{/users/s/tpl/texmf,!!/etc/texmf,!!/var/lib/texmf,!!/usr/lib/texmf,!!/usr/local/share/texmf,
!!/usr/share/texmf}/bibtex/{bst,csf}//



which means bibtex looks in "." (the current folder), /users/s/tpl/texmf/bibtex/bst, /users/s/tpl/texmf/bibtex/csf, /etc/texmf/bst, /etc/texmf/csf, etc.

## Multiple bibliographies

To have references at the end of each chapter, use chapterbib or bibunits. After \usepackage{chapterbib} each included file can have \bibliography and \bibliographystyle commands. bibtex has to be run on each file.

To have a section of References (items cited) and a Bibliography (which may contain items not cited) in a single-file article you can do the following - add \usepackage{bibunits} to your latex document and create your references in the usual way. Then add

\renewcommand\refname{Bibliography}
\begin{bibunit}[plain]
\nocite{*}
\putbib[testbib]
\end{bibunit}


to the file (called test.tex say). Then run latex test, bibtex test, bibtex bu1 (and bibtex bu2 if you have 2 bibunits, etc), latex test and finally latex test.

To have a single bibliography sectioned by chapters, use chapterbib - see the chapterbib.sty file for details. Here's a short example: in your main document (called test.tex say), use the information in test.bib

\documentclass{book}
\bibliographystyle{plain}
\usepackage[gather]{chapterbib}

\begin{document}
\include{One}
\include{Two}
\include{Three}

\bibliography{test}
\end{document}


Each included file can be something like this

\chapter{One}
\bibliographystyle{plain}
\cite{KP78}
\cite{H90}
\bibliography{test}


Then process as follows

  latex test
bibtex One
bibtex Two
bibtex Three
latex test
latex test


If you want multiple bibliographies and you're using natbib, check the natbib documentation.

To split a bibliography into several categories/subcategories try splitbib