Dear all,

Welcome to MLaRPiS. In this course you will learn a great deal about presenting and structuring your research. We start doing so with \(\LaTeX\), an environment for typesetting documents that is particularly useful for complex displays, such as graphics, tables and equations. The result of a LaTeX document is a perfectly typeset pdf that adheres to a set of predefined rules. Many journals in our field require LaTeX documents. This is why you have to learn it. The resulting flexibility and customizability when using LaTeX is why you should learn it.

I will take you through the basics of the scientific LaTeX family in a couple of exercises. In these exercises we will treat:

  1. the introduction to LaTeX (this document)
  2. managing references with BibTex (also week 1)
  3. creating slides with BEAMER and including equations (week 2)
  4. creating tables and displaying figures (week 3)
  5. Setting up a reproducable workflow in R with Markdown

Mastering a new programming environment is not done by simple exercises, but requires practice and repetition. Don’t worry, the documents you will have to produce during this course will require you to repeat the LaTeX process over and over again. However, you should work together with others and share your insights, findings and documents.

For example, you have to upload your work documents on a regular basis. There is a specific folder in the SurfDrive for uploading your work (\Documents by students). Create a folder with your name, and create subfolders for the exercises you have to hand in. This will make it easier for your classmates and your teachers to identify your work. When you place an finished exercise file in the SurfDrive, make sure to include all code files that are necessary to compile that finished file (i.e. your .tex file and/or your references in .bib format). This allows one of your classmates who has identified something interesting or useful in your work (e.g. when peer-reviewing your documents or watching your presentation) to explore your solution in depth.

Of course you will run into problems and/or difficulties. In general: the internet is your friend. Chances are that someone else encountered the same issue and, most likely, a solution has been posed by an expert user. If, however, you seem stuck; please contact me. Make sure to look in the How to contact Gerko file on the course page for instruction on how to contact me when time is of the essence. I will troubleshoot your problem and help you reach a solution. If you contact me outside of class hours, I would be just as happy to help you, but an answer may take longer as I have other duties.

I will post the solution to the exercises and all relevant code that generates the documents on the course page the day the exercise is due.

LaTeX is extremely flexible and allows you to typeset documents with ‘surgical precision’. There are however languages that allow you to create basic documents much quicker, but without the level of detail that LaTeX offers. One such a language is Markdown. This document is created with rMarkdown, an implementation of Markdown within RStudio. Of course it is required that you learn LaTeX, but since rMarkdown allows for direct integration of LaTeX and Html5, it can be a very valuable tool. Therefore, I will give you all the rMarkdown files that I present. You can recognize them by the .Rmd extension.

One request: do not run the LaTeX files in the SurfDrive. Everyone will get very annoyed by the frequent updates and the SurfDrive size may become ridiculously large. Only upload your pdf and tex file.

Enough general intro. Let us start,

Gerko


1 The Tex framework

Tex’s structure bares close resemblance to that of the R-project. The core functionality can easily be expanded by users by means of packages. These packages are stored in a centralized location called the Comprehensive Tex Archive Network (CTAN). The TexLive and MacTex distributions contain an image of all the available packages, meaning that you will have all functionality available at all times (even offline).

Just like with R, Tex is a software implementation that requires an editor to work with. LaTeX is a set of macros that make Tex easier for the users. From this moment on, if I speak about Tex, I am refering to LaTeX.

Tex is widely used by publishers as it give the user full control about the appearance of the document. It is designed to write in such a way that a minimum of attention is required by the user to typeset the document (as opposed to e.g. MS Word).


1.1 Installing a Tex framework

If you are on Windows or Linux, I suggest you install the easy to install ProTeXt distribution or the TexLive distribution. If you are on a Mac, the MacTex distribution will give you everything you need. If you use the default installation parameters, everything you might ever need is included in these distributions. Both distributions come with an excellent editor (Texworks in Texlive and TexShop in MacTex), but if you want to go the fancy way: TexStudio and TexItEasy are very good alternatives. See this page for a comprehensive overview of all Tex editors.


1.2 The MLRPS \(\LaTeX\) template

Open the file LaTeX_template.tex from the course page. This file is a template that you may use for your documents in this course. The file LaTeX_template.pdf (also on the course page) is the typeset version of this document (the output result). We will go through the document line-by-line:

\documentclass[10pt, fullpage, a4paper, titlepage]{article}

This is the line that tells Tex what the class of the document is and how it should be interpreted dimension-wise. In this situation, we use a 10 point font size (options are 10, 11 and 12 point), use the full page, use A4 paper size (as opposed to e.g. US letter format) and require a titlepage. The class of the document is set to be article. There are many deviations from the defaults. A simple online search usually gets you the option you desire.

\usepackage{graphicx, latexsym}
\usepackage{setspace}
\usepackage{apalike}
\usepackage{amssymb, amsmath, amsthm}
\usepackage{bm}
\usepackage{epstopdf}
\usepackage[]{hyperref}

We load these packages by default, because they sum up pretty much everything needed to begin working with LaTeX as a statistician. They govern devices such as graphics, mathematical notation (normal and bold face), and so on. Package hyperref is particularly interesting, because it allows you to set the meta-info for your document and it allows you to specify the way links and references in your document are treated. Meta-info is needed to make your documents indexable and, hence, more visible to you and everyone on the internet (if your document is on the internet).

\hypersetup{
pdftitle={title of the pdf},
pdfauthor={your name},
pdfsubject={cool stuff},
pdfkeywords={koala, chuck norris},
bookmarksnumbered=true,     
bookmarksopen=true,         
bookmarksopenlevel=1,       
colorlinks=true,            
pdfstartview=Fit,           
pdfpagemode=UseOutlines,      
pdfpagelayout=TwoPageRight
}

These are the options set for package hyperref. You can specify the document and author information and add keywords. The other options are also relevant, but we will not discuss them now.

%\singlespacing
%\onehalfspacing
\doublespacing

If you like to have a single-spaced document (commented out by %, so not executed), a one-and-a-half-spaced document (commented out by %, so also not executed) or a double-spaced document (not commented out by %, so executed), these options from package setspace are very handy.

\title{title of your paper\\ \small subtitle of your paper}
\author{name}
%\date{\today}
\date{}

Give titlepage information. We have set a title and a smaller subtitle. A line-break in tex is denoted by \\, although most of the times you won’t need to use this as tex takes care of this for you in most situations. The \small command tells tex that the remainder of this textbox is to be printed in a smaller font. All functions in tex are preceded by \. So, \author{} is the function for author, \date{} the function for the date and \today the function that prints todays date.

Up until now, we have not done anything. No code is executed. We have just been considering the preample of a tex document. To start a document, we use \begin{document}.

\begin{document}

We can then tell tex to print the titlepage information that we assigned (title, author, date)

\maketitle

and continue the document on a new page:

\newpage

We start the first section, labelled abstract:

\section*{Abstract}
text of abstract

Then a section called Introduction:

\section{Introduction}
text introduction

With a subsection called sub introduction:

\subsection{sub introduction}
text text text

And we end the document by the \end{} command.

\end{document}

2 Exercise

We are going to get acquainted with the tex classes. A class is a clear definition of the type of document. There are classes for books, articles, letters, resumes, and so on. There are even classes for journals and bookseries by publishers, such as Springer, Elsevier, CRC and Sage.

Classes are usually linked to style files, the files that define the looks of a document. Have a look at the LaTeX background folder - in this week’s tab on the course page - if you’d like to know more about how classes and styles make documents look different. Notice that not every document by default accomodates for the type of content. This can however always be corrected.


Create five documents:

  1. An article with 12 point font size on US letter paper.
  2. A book with 10 point font size on A4 paper.
  3. A book with 10 point font size on A5 paper.
  4. A minimal document with 12 point font size on A5 paper.
  5. A letter with 12 point font size on A5 paper.

Use the Virgil - Aeneid.rtf file as the content of the document. Specify the paragraphs correctly. Upload the documents to SurfDrive before the second lecture.