User:Johannes Bo/draft:Bibtex

From Wikibooks, open books for an open world
Jump to navigation Jump to search

Title to be: Bibliographies with BibTeX

Learn how to create a bibliography using the stable BibTeX workflow - A short tutorial.


BibTeX has been developed in the 1980's to ease the creation and management of citations and bibliographies within LaTeX. The workflow is split in different parts.

  • The user provides a plain text database which includes the bibliographic information of the sources used.
  • The user also points the BibTeX system to a bibliographystyle file, a plain text file that defines the layout of the bibliography, including styling author lists, the appearance of titles as well as the order in which the information is output.
  • The user calls the BibTeX program, an external tool, which then grabs which citations are needed in the document, takes them from the database and formats them according to the chosen bibliographystyle. The result is a finished bibliography that can be read and typeset by LaTeX.

The database[edit | edit source]

Creating a bibliography using BibTeX means storing all of your available bibliographic information in a simple text-based database. The name should be as unique as possible, for example melanieMasters2018.bib. This is helpful when transferring files with your advisor, students or colleagues. The helper program BibTeX is used to deal with the database.

A sample database file could look like this:

@article{capybara2017,
	author  = {Carl Capybara and Walter Wombat},
	title   = {How hard would it be to build a spaceship from scrap -- A closer look at the expenses},
	journal = {Journal of Metal Detectors},
	year    = {2017},
	volume  = {8},
	number  = {12},
	pages   = {12-14},
}
@book{lion2010,
	author       = {Laura Lion and Peter Platypus and Eel, Emil},
	title        = {Finding Water on Mars},
	publisher    = {extraterrestrial publishing house},
	year         = {2010},
}
@misc{wikibook,
	title        = {Generating Bibliographies with BibTeX},
	organization = {Wikibooks},
	year         = {2018},
	note         = {accessed 2018-03-10},
	url          = {https://en.wikibooks.org/wiki/LaTeX/Bibliographies_with_BibTeX},
}

Every entry in the database starts with an @-sign followed by the entry type (book or article for example). More types are available. The bibliographic information for each entry are stored in a pair of braces, beginning with a unique keyword for every source item (bibkey). Least complicated way of presenting the data is every field type in a new line, the content in curly braces, followed by a comma. The order in which you give the information is not important.

Please have a close look at the authors, every individual author is separated by the keyword and.

A simple example - Step by Step[edit | edit source]

\documentclass{article}
\usepackage{url}
\begin{document}
I doubt that there is any useful information here~\cite{wikibook}.

Some research has been done on spaceships capable of going to Mars~\cite{capybara2017}.

Maybe a future journey will confirm the predictions of Lion et al.~\cite[9]{lion2010}.

\bibliographystyle{plain}
\bibliography{melanieMasters2017}

\end{document}

\cite is a command provided by LaTeX, it takes a key from the database (see above) as argument. Every time something is cited, a note is written for the BibTeX program in an auxiliary file. \bibliographystyle takes the name of the style you want the bibliography to have and is also written to the auxiliary file. \bibliography takes the name of the database (without the file extension). After the first LaTeX run, we see question marks instead of citation numbers and the log file tells us

LaTeX Warning: Citation `wikibook' on page 1 undefined on input line 4.

LaTeX Warning: Citation `capybara2017' on page 1 undefined on input line 6.

LaTeX Warning: Citation `lion2010' on page 1 undefined on input line 8.

No file melanieMasters2018Main.bbl.
[1{/usr/local/texlive/2017/texmf-var/fonts/map/pdftex/updmap/pdftex.map}]
(./bibtexWikibookTest.aux)

LaTeX Warning: There were undefined references.

If BibTeX was not run yet, you will get the infamous LaTeX Warning: There were undefined references. and see question marks instead of citation numbers.

All the citations are undefined and there is no bbl. Now, BibTeX is needed to get the needed citations and create the bibliography list. It needs to be run on the name of the main project file, but without the file extension. Your favourite LaTeX editor will have a button for that. The result is the following output in the terminal.

This is BibTeX, Version 0.99d (TeX Live 2017)
The top-level auxiliary file: melanieMasters2018Main.aux
The style file: plain.bst
Database file #1: melanieMasters2018.bib

BibTeX has read in three different files, the aforementioned auxiliary file (aux), the bibliographystyle file and the database and has generated two new files. One has the file ending blg and is the log file of BibTeX, the other on has the ending bbl. This is the file LaTeX was complaining about missing earlier.

Since this file is now available, LaTeX can be run again.

The bibliography is finished, but the text still shows question marks. LaTeX gives a hint: Warning: Label(s) may have changed. Rerun to get cross-references right.

The bibliography is done, but LaTeX still warns about undefined references but also gives a hint:

LaTeX Warning: Label(s) may have changed. Rerun to get cross-references right.

After another (few) LaTeX runs, all citations and cross references will be resolved.

The finished reference list is in alphabetical order with style plain.

The reference list is sorted by author names. A closer look shows us some mysterious results:

  • The names are formatted slightly differently in the first two entries, the second one having an Oxford comma.
  • The journal title of the first entry is italic, but it is the book title for the second
  • The title of the third entry lost its uppercased letters and the url is missing completely in the output

The order of elements and the formatting are defined in the bibliographystyle file. plain, which was introduced in 1984, does not support URLs.

Several other default styles are available.

bibliographystyle abbrv; first names are abbreviated
bibliographystyle alpha; the label is formed by the author names and the last digits of the year
bibliographystyle unsrt, the bibliography is sorted by appearance in the text
bibliographystyle acm; author names in small caps, first names abbreviated
bibliographystyle ieeetr; first names abbrevated, quotes around titles, commas between fields
bibliographystyle siam; author names in small caps, first names abbreviated


Splitting into different Topics[edit | edit source]

bibtopic


Bibliographies per Section or Chapter[edit | edit source]

You can have a bibliography for each chapter using the multibib package.


Back to main bibliography page