This lesson is in the early stages of development (Alpha version)

Introduction

Overview

Teaching: 10 min
Exercises: 5 min
Questions
  • What is LaTeX used for?

  • How can I create a new typeset document?

Objectives
  • How to create a new LaTeX project in Overleaf.

  • Become familiar with the Overleaf ecosystem.

  • Learn what the minimum requirements for a LaTeX document are.

  • Be able to identify an element’s role in a LaTeX document.

What is LaTeX

LaTeX is a typesetting language, useful for combining text with mathematical equations, figures, tables, and citations, among other things.

LaTeX is written like a mark-up language, meaning that formatting (including bold text, bullet points, and changes in font size) is indicated by the use of commands, special characters, or environments.

In order to produce the actual document, this mark-up text must be compiled. Errors in the mark-up can either be non-fatal, meaning the document will compile with some warnings; or fatal, meaning the document will fail to compile.

How do you say it?

Not like the rubbery substance - LAY-teks - it’s usually pronounced LAH-tekh or LAY-tekh.

Our first LaTeX document

We’ll start by creating a new, ‘blank’, file in Overleaf. You’ll notice that its idea of a blank file is not actually an empty one.

  1. Sign in to Overleaf.com.
  2. Go to New Project > and select “Blank Project.”
  3. Name your project “LaTeX workshop”.

Overleaf fills in a lot of things by default, which is one of the benefits to using it; it makes it very easy to get up-and-running in LaTeX.

There are three parts to the Overleaf window: the file navigator, the text editor, and the preview pane.

In the text editor for our ‘blank’ document, we can see all of the elements necessary to create a minimally-compilable document in LaTeX (and then some).

\documentclass{article}
\usepackage{graphicx} % Required for inserting images

\title{LaTeX Workshop}
\author{Your Name}
\date{August 2022}

\begin{document}

\maketitle

\section{Introduction}

\end{document}

Commands in LaTeX are distinguished from regular text through use of a backslash \. Some commands take options and/or arguments. Arguments are placed inside curly braces {}. Options go in square brackets [].

The \begin{} and \end{} commands delineate an environment. We’ll see more about environments in later episodes; for now, I’ll say that environments each have their own set of formatting rules and purpose.

Looking at our document

If we look at the different parts of this document, starting at the top, we see:

  1. The document class declaration. This document is an article.
  2. The preamble
    • A package import statement. The graphicx package is used to allow us to add images to our document, which the comment (beginning with the % symbol) tells us.
    • Some metadata. This includes the title and author.
  3. The document body
    • The document environment \begin{} statement
    • The \maketitle command
    • A section heading
    • The document environment \end{} statement

Some of these are absolutely necessary:

Without these, the document will not compile.

Let’s make this document a bit more interesting

Now we’re going to add in some dummy text to get a sense of what a more-complete document would look like.

We’ll do this using the lipsum package, which provides sample text blocks. We’ll need to add a new \usepackage{} command to the document preamble and the \lipsum command underneath our section title.

\documentclass{article}
\usepackage{graphicx} % Required for inserting images
\usepackage{lipsum}

\title{Let's do Science!}
\author{Your Name}

\begin{document}

\maketitle

\section{Abstract}
\lipsum

\section{Introduction}
\lipsum

\end{document}

Once you’ve updated the main.tex file, select the “Recompile” button in Overleaf to update the preview of your file.

Challenge 1

Look at the following LaTeX code and decide if it will compile as written. If you say no, decide why not.

\documentclass{article}
\usepackage{graphicx} % Required for inserting images

\title{The Playboy of the Western World}
\author{JM Synge}

\begin{document}

\maketitle

\section{Introduction}

Answer

This code will not compile as written (or, if it does, it will throw some warnings). It is missing the \end{document} statement.

Challenge 2

Which of these lines should not go in the document preamble?

  1. \maketitle
  2. \title{R.U.R.}
  3. \usepackage{graphicx}

Answer

\maketitle does not belong in the preamble. \title{R.U.R.} does, because this command stores metadata about the file.

Challenge 3

Which of these lines is optional?

  1. \begin{document}
  2. \maketitle
  3. \documentclass{book}

Answer

\maketitle is optional.

Key Points

  • Typesetting is used in many domains to convey information in a more readable format.

  • Creating a new, minimal document requires a document declaration, a preamble, and a document body.

  • LaTeX documents consist of commands, environments, and regular text. Commands may take arguments and/or options.