Tag Archive | Windows

5 cool reasons to use LaTeX

TexPad on OSX

One of the differences between undergraduate level study and masters level study is the amount of report writing you do. I can only think of two times in my bachelors degree that I wrote a significantly sized report — and one of those was my dissertation. So far in my MSc I am yet to have handed in a coursework without a report.

During he early stages of my third year I discovered a tool (language?) called \LaTeX, however it would be yet another thing to learn alongside my 4 large modules and everything I needed to learn to do my dissertation, so I gave it a miss. This year I decided I would finally give it a go, see what all the fuss was about and see whether it could really replace a Microsoft Word shaped hole in my life.

It did. LaTeX offers a lot of advantages over Microsoft Word, LibreOffice and many other Word Processors, some of the more interesting ones I’ll talk about here. (Note: this isn’t a tutorial, just some observations — so if you don’t know anything about LaTeX I recommend you look it up online first)

1 – Better Source Control

\LaTeX produces full PDF output, including tables images and other complex objects, from declarations made in plain text. If you’re not quite sure how to think about \LaTeX sometimes it’s best to think of it like a Markup language — such as HTML — in which you tell it what you want in plain text and it creates the graphical representation.

Git Diff of LaTeX

Git Diff of LaTeX

Because all of the declarations are in plain text it makes source control really easy. Above you can see an image of a git diff in the Github application on OS X. Showing the difference between binary (.doc) word files is impossible, showing differences between Open Office XML files is difficult to decipher at best.

2 – Include code and automatically Syntax Highlight it

Using the listings package you can pull it code from other files on your system and automatically syntax highlight it using colours of your choice. No more copy and pasting code into your report over and over when you make changes.

First use the listings package, and load the programming language(s) you would like to include in your document. Optionally include the XColour package for some more interesting colours to use to syntax highlight your code.

% In your preamble
\usepackage{listings}
\usepackage[usenames,dvipsnames]{xcolor}
\lstloadlanguages{Ruby}

Then set up the colours you want keywords, comments and strings etc to appear as, as well as some basic settings such as line wrapping. You can redefine these at any point in your document if you need to change the colours for different bits of code for any reason:

\lstset{%
basicstyle=\ttfamily\color{black},
commentstyle = \ttfamily\color{Gray},
keywordstyle=\ttfamily\color{CornflowerBlue},
stringstyle=\color{SeaGreen},
identifierstyle=\color{Mahogany},
showstringspaces=false,
breaklines=true}

Now you can just include any code files…

\lstinputlisting[language=Ruby]{path/to/code.rb}

or any inline code snippets you like

\begin[language=Java]{lstlisting}
//This is a comment in Java
System.out.println("I love printing to stdio");
\end{lstlisting}

I personally prefer to include from files, so that I can edit the code that is being displayed in my preferred editor for that language. Additionally, if you are required to dump all of your source code in a report, as was required of me recently, this is a nice way to ensure any updates to that source code are displayed in your final document without any work on your behalf.

3 – Run a Script from inside your documents

If you run a Unix-like operating system with a bash shall, such as Linux or OS X, then you can compile your \LaTeX documents with the --shell-escape flag which allows you to embed bash scripts inside your document that get run when the document gets compiled.

I recently used this to run a bash script which counted the number of words inside the document that was being compiled, meaning I could have an always accurate word count printed inside the document. Handy.

I could also envisage this being useful to generate pretty PDF reports of services on a server or other systems. An guide on how to achieve something like this is available at CTAN.

4 – Easily cite other peoples work and change reference style

Using the Bibtex bibliography subsystem for \LaTeX you can write your references in a simple, almost JSON like, syntax — as shown below:

@online
{
	demes,
	author = {Vesselin K. Vassilev and Julian F. Miller and Terence C. Fogarty},
	title = {The Evolution of Computation in Co-evolving Demes of Non-uniform Cellular Automata for Global Synchronisation},
	year = 2007,
	url = {http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.33.9467&rep=rep1&type=ps},
	urldate = {2015-01-25}
}

When you come to cite this article in the body of your document you can just write \cite{demes} and it will print out the correct citation style as specified in your documents preamble, and print the full information about the article in the correct style in your bibliography. At York we use the IEEE citation system, and so the above is output like so:

Inline citation IEEE

Inline citation IEEE

Bibliography IEEE

Bibliography IEEE

However, if I change this one line in my preamble from:

\usepackage[backend=biber, style=harvard]{biblatex}

to

\usepackage[backend=biber, style=authoryear-ibid]{biblatex}

Then my references and citations show up in the Harvard style, as I used in my final year project at Hull. No retyping citations.

Harvard Style Reference

Harvard Style Reference

5 – Write and Read Anywhere

Because the ‘source files’ for \LaTeX are just plain text, and the output files are PDF files everyone, on any operating system, can make changes to and read the output of your documents. No more worrying about what version of word someone has, or whether or not they’ll have Calibri in their font library. Furthermore there is a LaTeX compiler available for almost any machine.

There is an abundance of editors for  \LaTeX including features such as syntax highlighting, autocomplete, automatic packing including and simplification of the PDF generation process. My personal favourite is TexPad.

 

I hope I will have convinced at least a few of you to try out LaTeX when you’re next writing a report for university of work. Let me know how it goes if you do!

Danny

Playing with Kinect on Windows

I’ve spent the last few days playing with a Kinect, which I’m borrowing from the Computer Science Department, hooked up to my Laptop which is now pretty easy to do thanks to the new release of the Kinect for Windows Platform.

I must say that when I first heard about Microsoft releasing a Natural User Interface device a few years ago I was a bit sceptical, and If I’m honest I don’t think the devices main role is that of a gaming device. Having said that it is great fun as I’m sure you can infer from the below image of James and Rob “Skeleton Fighting”.

As you can see, the device is pretty accurate (even with my head in the way of much of robs body) and it maintains a consistent frame rate of 30 – 31 frames per second even when providing highly detailed skeleton and joint information on the fly, I must say this is the most impressed I have been by any software or hardware in years.

Its not all play however, the plan is learn how to program using Kinect and its associated API’s and eventually (hopefully) get something ready for the 10th Microsoft Imagine Cup, the only problem is that so far the documentation for the latest release of the API (admittedly only a few weeks old) is pretty much non existent, or very high level. I’m sure we’ll figure it out eventually though.

Danny.