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.

Tuesday, October 29, 2013

Installing and Running Gnuplot on Ubuntu

Gnuplot is simple to install and use on Ubuntu systems as the latest version is included in the Ubuntu repositories. One part that is not included by default is auto complete at the gnuplot command line. In order to install gnuplot and enable auto complete, simply open a terminal, and type the following command

sudo apt-get install gnuplot rlwrap

UPDATE On Ubuntu 12.04 and later you need to specify what version of gnuplot to install (qt or x11), so change the command above to

sudo apt-get install gnuplot-qt rlwrap

Then open your bash configuration file (if using the default bash shell)

gedit ~/.bashrc &

and add the following lines to the file somewhere near the bottom

# enable autocomplete in gnuplot
alias gnuplot="rlwrap -a -c -b\"\\\"\\\"\\\'\\\'\" gnuplot"

save the file and exit.

First we need some data for plotting, for instance the file

http://www.maths.manchester.ac.uk/~pjohnson/Gnuplot/testResults.dat

may be downloaded from my website.

Now open a new terminal and type gnuplot into the command line. You should see the following:

Now enter the following:

p 'te

and press the tab key. The filename should auto complete. If it does not appear press the tab key again as there might be multiple files beginning `te', and you might need to enter more letters to allow it to complete. If it is still not working, enter !ls and check that the file is present in your current working directory. Complete the gnuplot command to plot the file with lines and press return

p 'testResults.dat' w l

If it all works you should see: