# LaTeX

Firstly, LaTeX ("lay tech", not "lay-tecs") is sort of a version of TeX ("tech"). It's TeX "plus macros" if that means anything to you. If not, don't worry: just know that TeX is often used a verb, which refers to the act of using LaTeX/TeX to write stuff ("I'm going to go TeX up my homework"). Anyway, some explanation here (a useful site in general).

## Set it up

### Online version

Somehow I was guided to this site before ever really using LaTeX:

www.sharelatex.com

I find it extremely useful as a LaTeX editor, compiler and previewer. No need to download anything, it autosaves your work, and it has pretty much all LaTeX packages on it. Obviously the huge caveat is that it requires an internet connection. I generally just code on some basic text editor if I'm without a connection, and throw it up on ShareLaTeX when I'm back online.

They also have a really fantastic Learn page. I will reference links from here on this page a few times.

### Offline version

If you're smarter than I am, you may want an offline version. Firstly, you need a DISTRIBUTION, i.e. the program that actually complies (makes) the files. For Mac, you might already have one (it might come pre-installed?) but MacTeX is the one you want otherwise. For Windows, it's MiKTeX. For Linux, you already have one, but you can update it if you want, from TeX Live I believe.

Then you need an EDITOR, somewhere to actually write your LaTeX files. I think all the above distributions come with editors, but not necessarily the best ones (for you). Editor choice can be quite personal, but I have to recommend Texmaker. It works on all OSs, and it's a great editor too. There are others that are very popular too (TeXShop for Mac, TeXworks for all) that function similarly, in that they provide a full "environment" in which to make documents. Another common route is to use Vim or Emacs with some LaTeX-specific add-ons to make life easy.

## Learn to TeX

One of the best websites to learn most TeX related things is:

http://en.wikibooks.org/wiki/LaTeX/

The best starter pages are probably the one on Basics and the one on Document Structure. Alternatively, you can just follow the sequence outlined on that site. ShareLaTeX's Learn page (as reference before) is also great.

I think (as is often the case) the best way to learn is to basically dive in, and try to write a document, on anything. Every time you need to do something, just find out how: online or otherwise. Quick tip: learning to input tables is a bit of a nightmare.

## Presentation: Beamer

Beamer isn't the only package capable of making presentations with LaTeX but it's a very popular way. Basically you create slides, like you would in PowerPoint. I found the learning curve here to be very low: you basically just choose what to want in each slide, and use a \begin{frame} ... \end{frame} structure to make it. Add bullet points and you're 90% there. In the past, I've made slides by starting with a full document, adding frames and simply editing down each slide.

ShareLaTeX's Beamer page is great, as is the wikibook's Beamer page. I think it's a bit messy, but I've used this pdf a couple of times too.

## R (or any language) in your document: Knitr

R as in the statistical language of course. So yes, you can write and run R code directly in your LaTeX document! You use a package called Knitr - follow the link to learn more about it and how to implement it. It's essentially an extension of Sweave (don't worry if that doesn't mean anything to you). Knitr is very easy to implement in ShareLatex (basically you name your file .Rtex instead of .tex). On the author Yihui Xie's site, he also explains how to use it on Texmaker and even RStudio. In fact you can use Knitr with any document writing language (e.g. markdown).

It's not always sensible to do things this way, but it makes document reproducibility so easy.

## Graphics / Figures

It's more annoying than you might think to input a simple image/graphic into your document. Both the wikibooks site and ShareLaTeX's site have solid primers on it. Not all file formats are supported, but you'll have to check that yourself.

One huge irritation is where graphics and figures actually go in your document. They generally do not go where you had them in your .tex file, but instead they go somewhere "sensible" so as not to waste space on the page. In many ways, this is actually good practice, but most of the time I simply want the figure to go where I wrote it. To do this, instead of just \begin{figure}, you modify it with [H], i.e. \begin{figure}[H]. You need the float package to do this.

If you wish to CREATE YOUR OWN PLOTS, one option is to use PGF/TikZ, which is basically two languages that work together. There's a learning curve here, but it's not so bad. Again, ShareLaTeX and the wikibook have solid info on these. I also found a pdf written by Jacques Crémer here to be very helpful, especially as a starter page.

A lot of my graphs come straight from R, and so generally these are the graphs that make it into my documents (as opposed to using the data output from R to draw TikZ graphs). I simply use Knitr to stick them in.