Wednesday, October 30, 2013

Using bibtex for referencing

I am going to give a quick description of bibtex here, but there is already a good guide on bibtex available on the university pages here. Using bibtex is fast and easy way to keep track of referencing within a document. It uses a plain text file containing a database of all your references, each of which must be given a unique keyword. A bibtex database entry looks something like this:

@article{myFirstBibItem,
  title={The Paper Title},
  author={Joe Black and Mary White},
  journal={The Journal of Something},
  pages={1--2},
  year={2000}
}

The syntax is quite straight forward, the @keyword is used to indicate the type of entry, be it an article, a book or an entry in a conference proceedings. Next you give the entry a unique keyword so that you can cite the entry in the text. Then follows a list of items found in your reference, each separated by a comma. If you are having problems check that all items in the list have a comma following them as this is quite easy to forget. In fact you don't even need to know this as most websites (such as google scholar) give the option to export a citation in this format (see later on).

Now we shall start assuming you have a working tex document. Go to the menu and open a new file. Now go to the menu and select the save as option, making sure the directory is the same as where you have saved your tex document, then enter the name myBib.bib for the filename and BibTeX for the file type. Click save.

Now open google scholar in your web browser and click on the settings option in the top banner of the web page. You should now see an option near the bottom of the screen to Show links to import citations into. Select this option and make sure the bibtex option is selected. Save your settings.
Now enter a search for famous reference, such as "Black Scholes option pricing". Underneath the listed items you should now see a link on each item to Import into Bibtex, click on the link. You should now see something like
Copy and paste the text into your bibtex file and save it.

Now we can cite the reference in our text. Add the following line in your text

My first citation is \cite{black1973pricing}.
where the keyword is the same as the one in your bib file entry. Finally add the lines
\bibliographystyle{plain}
\bibliography{myBib}
at the end of your document. Run pdfLatex, bibtex (the button with a B on it in winedt) and then pdfLatex again two or three times. It should look something like this:
There are many different styles of referencing that can be used and it is very easy to switch between the different styles simply by changing the bibliographystyle command.

One package included in latex that can make your referencing very nice is the natbib package. To use this package instead of the standard one include the line

\usepackage{natbib}.
at the top of your document and change your style to
\bibliographystyle{dcu}
and recompile your document.
Now we get a reference list without the numbers and the name and year quoted in the text. The style of your bibliography is optional but I feel that this is much cleaner and neater.

2 comments:

  1. Here is great article about bibliographical writing and some useful tips and tricks you can use in your work.

    ReplyDelete