Get Better: LaTeX and Overleaf

As part of the series on development of early career researchers in the lab, we spent a session (with homework) to learn how to write a document in LaTeX.

Like the R session, we spent an hour or so in a room with laptops writing a document and then homework was set, to be completed for the following week.

There’s a mix of TeX abilities in the lab. Many have not used TeX and have no idea about markup languages or markdown, instead they’ve used Microscoft Word or equivalent WYSIWYG editor. A couple of people have written papers in TeX with me using Overleaf as a collaborative writing tool. So we needed to start from the basics.

We did the steps below, feel free to use the materials. The group needs to be led by someone who knows what they are doing in LaTeX.

Step one: sign up to Overleaf

Overleaf is a collaborative TeX writing resource (previous post here). Sign-up is free. Our University is in the process of acquiring a licence, which will give more space and other features, but for our purposes a free account was OK.

Step two: share a document

My idea was to share a document with everyone so that we could edit together in real time. I hadn’t tested this, and it turns out that there is a user limit, which we were in excess of. So, instead everyone created a new document in their own account and we built parallel documents together in the room.

Step three: make a simple document

Our lab has a manuscript template (here – modified from one that Ricardo Henriques built). It is too confusing and daunting to start with that so we started with a blank template. We gradually added to it as shown below.

\documentclass{article}
\begin{document}
  Hello World!
\end{document}

and then making a title

\documentclass{article}


\title{My first document}
\date{2013-09-01}
\author{John Doe}


\begin{document}
  \maketitle
  \newpage


  Hello World!
\end{document}

followed by page numbering

\documentclass{article}


\title{My first document}
\date{2013-09-01}
\author{John Doe}


\begin{document}
  \pagenumbering{gobble}
  \maketitle
  \newpage
  \pagenumbering{arabic}


  Hello World!
\end{document}

then sections and subsections.

This part is useful for highlighting the benefits of LaTeX for writing a thesis. Comparing to Word is good to remind people why we are doing this.

\documentclass{article}


\title{Title of my document}
\date{2013-09-01}
\author{John Doe}


\begin{document}


\maketitle
\pagenumbering{gobble}
\newpage
\pagenumbering{arabic}


\section{Section}


Hello World!


\subsection{Subsection}


Structuring a document is easy!


\end{document}

Some math

\documentclass{article}


\usepackage{amsmath}


\begin{document}


\begin{equation*}
  f(x) = x^2
\end{equation*}

Adding some graphics and figure call-outs.

\documentclass{article}


\usepackage{graphicx}


\begin{document}


\begin{figure}
  \includegraphics[width=\linewidth]{boat.jpg}
  \caption{A boat.}
  \label{fig:boat1}
\end{figure}


Figure \ref{fig:boat1} shows a boat.


\end{document}

We talked about floats and then we put together a short document.

We had some fun because this document was shared with some (but not all) people in the group. The people who could edit enjoyed typing funny stuff in the sections.

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[margin=2cm]{geometry}
\usepackage{graphicx}
\usepackage{amsmath}

\title{Our training session}
\author{John Lennon}
\date{October 2019}

\begin{document}
\pagenumbering{gobble}

\maketitle

\newpage
\pagenumbering{arabic}

\section*{Introduction}

James likes beer.

\subsection*{Beer choice}

It is warm flat lager. See Equation \ref{eqn:einstein}. \textless 1

\begin{equation}
   1 + 2 = 3
\label{eqn:simple}
\end{equation}

\begin{equation}
    e = mc^2
\label{eqn:einstein}
\end{equation}

\subsubsection*{Glass choice}
From a mug.

\begin{figure}[!htp]
    \centering
    \includegraphics[width=0.5\linewidth]{fig.png}
    \caption{My amazing graph}
    \label{fig:my_label}
\end{figure}

\end{document}

The figure we used is here:

fig.png

At the end of the session, everyone had this funny document in their Overleaf dashboard.

We had some time free at the end so I showed everybody a manuscript that we were working on. This allowed me to show them the manuscript template, how easy it is to use referencing/bibliography and how switching styles is really simple. This allowed everyone to see the point of the session. The example document we’d made was pretty basic and so seeing how the finished product is only a few more steps away is important.

Homework

The task was to recreate a document from scratch and share it back with via Overleaf so that I could check the code. I supplied everyone with a PDF version via our Slack workspace. The PDF is here.

I said “The challenge is to do as much as possible from scratch. You can use the training project for inspiration but don’t copy-paste as you won’t learn much that way. For the picture, you can download it from the training document and upload it into your new project or you can share it between the two projects. If you need to search for help – feel free to ask me on Slack or look up stuff here: https://en.wikibooks.org/wiki/LaTeX

The real code used to generate the PDF is here

What happened?

Everyone in the lab managed to recreate the document. There were little things that people struggled with, such as the siunitx package. But on the whole, everyone did a good job. I feel like the level was right for the group. More advanced stuff would probably have alienated some people. Using Overleaf lowers the energy barrier a lot. Seeing the edits in real time helps a lot. Downloading a standalone TeX package would definitely have put some people off.

The post title comes from Get Better by The New Fast Automatic Daffodils. The version I have is on a compilation of Martin Hannett produced tracks called “And Here Is The Young Man”

One thought on “Get Better: LaTeX and Overleaf

Comments are closed.