Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Introduction to LaTeX Workshop

LaTeX Basics

Introduction

LaTeX is a typesetting system that allows you to focus on your content instead of formatting - formatting is done separately from entry.

You tell LaTeX “what it is” not “how it looks.”

LaTeX using Overleaf

Example

Look at the template below to get a sense of how Overleaf works. On the left side, the content is written in LaTeX. On the right side, the rendered document.

two panel view of Overleaf platform

Structure of a document

TermDescriptionExample
CommandControl sequence which performs an action\newpage
PreambleBlock of commands that define the type of document you are writing, the language you are writing in, the packages you would like to use. Comes before \begin{document}\documentclass{article}
PackageEnable you to create bibliographies, insert images and figures, and write formulas.\usepackage{amsmath}
EnvironmentBlock of code with specific behavior depending on its type\begin{} & \end{}
BodyContent of document enclosed inside an environment\begin{document}

Basic Commands

Font typefaces: Change font designations in preamble. More information about fonts and typefaces: https://v2.overleaf.com/learn/Font_typefaces

Make Title

The simplest option for making a title is to use the \maketitle command which draws from the following declarations within the preamble: \author \date \thanks \title

Lists

Use the \begin{itemize}...\end{itemize} environment to create unnumbered lists.

Use the \begin{enumerate}...\end{enumerate} environment to create numbered lists.

Accessible PDFs

Take steps to create an accessible PDF when you initiate a new project. The main considerations:

In this section, we introduce the text below to enable tagging essential for an accessible PDF. More content-specific information follows in later sections.

\DocumentMetadata{tagging=on,
    tagging-setup={math/setup=mathml-SE},
    pdfstandard=ua-2,
    lang=en-US
}

Read more:

Exercise

Mathematics and Equations

Simple Operators, Subscripts, Superscripts & More

To render simple equations, you also need to know syntax and commands for operators, relations, subscripts, superscripts, and fractions.

Operators & Relations:

+, -, =, >, < work as expected. Here are some other commands:

CommandDisplay
\times×\times
\div÷\div
\geq\geq
\neq\neq
\pm±
\leq\leq
\cdot\cdot
\approx\approx

Basic Math

To display math inline with text, place formula or symbol in between $:

$x + y = z$ renders inline: x+y=zx + y = z

Display mode \[ x + y = z \] or $$ x + y = z $$ will center the equation on its own line:

x+y=zx + y = z

Subscript: use the underscore (_) / Superscript: use the carret (^)

If the subscript or superscript includes more than one character, enclose it in curly brackets--otherwise the command applies only to the first character.

Example: $x^n+1$ gives xn+1x^n+1 but $x^{n+1}$ gives xn+1x^{n+1}

Fractions:

To display a fraction, use the command \frac followed by the numerator and denominator in curly brackets.

Example: \frac{1}{x} gives 1x\frac{1}{x}

Next Steps: Greek Letters, Integrals & More

Greek Letters

Many equations and formulas use Greek letters. The command is simple - just the backslash and the name of the letter. Capitalize the command to get the capital letter. Here are some examples:

CommandDisplayCommandDisplayCommandDisplay
\alphaα\alpha\lambdaλ\lambda\rhoρ\rho
\betaβ\beta\LambdaΛ\Lambda\sigmaσ\sigma
\GammaΓ\Gamma\muμ\mu\\hiΦ\Phi
\deltaδ\delta\piπ\pi\omegaω\omega
\DeltaΔ\Delta\OmegaΩ\Omega

Greek letters that are the same in English are an exception, for example, use A for Alpha, B for Beta, Z for Zeta. For more commands, see the Overleaf list of Greek letters.

Limits & Integrals

There are also commands for common operations that take upper and lower bounds:

Limits:

\[
lim_{x \to \infty} f(x) 
\]

results in

limxf(x)lim_{x \to \infty} f(x)

Integrals:

\[  
\int_{a}^{b} x^2 dx 
\]  

results in

abx2dx\int_{a}^{b} x^2 dx

More Advanced: Math Packages

amsmath & amssymb Packages

LaTeX has many packages that you can use to extend its capabilities. The amsmath and amssymb packages provide you with additional symbols and commands for structuring equations.

To include them, add these commands to the preamble of your LaTeX document: \usepackage{amsmath}
\usepackage{amssymb}

amsmath: Equations Environment

Use the \begin{equation}...\end{equation} command to include a numbered equation in display mode.

\begin{equation}
\frac{\partial Q}{\partial t} = \frac{\partial s}{\partial t}
\end{equation}

results in

Qt=st\frac{\partial Q}{\partial t} = \frac{\partial s}{\partial t}

Exercise

Creating Bibliographies in LaTeX

Objective: Learn the basic commands to create and edit in-text citations and bibliographies

Getting started with a .bib file

In order to include in-text citations and a bibliography, the document needs to refer to a .bib file. There are three ways to include a .bib file in a project in Overleaf.

  1. Upload your own .bib file that you create or export from a citation manager.

  2. Link to a URL (.bib).

  3. Sync your Overleaf account with Zotero.

If you are working in a traditional LaTeX editor, locate the .bib file in the directory.

What does a citation in a .bib file look like?

@article{drachen2016sharing,
  title = {Sharing data increases citations},
  author={Drachen, Thean and Ellegaard, Ole and Larsen,
  Asger and Dorch, S{\o}ren},
  journal={Liber Quarterly},
  volume={26},
  number={2},
  year={2016},
  url={https://doi.org/10.18352/lq.10149},
}

@misc{fsci2021,
  author={Teplitzky, Samantha, and Tranfield, Wynn},
  title={Introduction to Open and Reproducible Practices in 
  {Earth Sciences}},
  maintitle={Case Studies in the {Earth Sciences: Current} 
  Approaches to publishing, data and computation},
  eventtitle={{Force 11 Scholary Communication Institute (FSCI)}},
  venue={Virtual},
  eventdate={2021-07-27/2021-08-03},
}

Key: The citation key is the internal label inside the \cite{} command used to call in a citation or reference a source.

Example: To cite Drachen 2016 within your text, type \cite{drachen2016sharing}

Bibliography Packages

We will use the biblatex package to generate in-text citations and bibliographies. Biblatex is a flexible package for generating citations.

When adding a bibligraphy, you will need to add commands to the preamble.

Commands required for the preamble:

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

\addbibresource{example.bib}

The above command calls in the .bib file, which has the citation information for in-text citations and the bibliography.

In an article or book chapter, the command \printbibliography inserts the bibliography, which will contain citations referenced in the text.

Find more information visit the Overleaf page on bibliography management.

In-text citations

CommandDescription
\cite{}bare citation command (according to style)
\parencite{}parenthetical citation
\citeauthor{}prints author name(s)
\textcite{}prints authors followed by a citation label enclosed in ()
\nocite{*}prints publication in bibliography without a citation
\citeyear{}prints only the year field

Examples

CommandResult
\cite{knyazeva_duplex_2013}Knyazeva and Pohl 2013
\parencite{singh_2013}(Singh et al. 2013)
\citeauthor{campbell_how_2011}Campbell and Cabrera
\textcite{elsabbagh_microstructure_2014}Elsabbagh, Hamouda, and Taha (2014)

Exercise

Figures and Images

Uploading a figure or images

Incorporating images and figures into your Overleaf project is best accomplished by creating your figures, particularly graphs and plots, outside of Overleaf and then importing them into Overleaf.

Click on the “upload” icon and navigate to the location of your figure.

Overleaf menu to upload images

Image Placement

Images and figures require a graphics package.

  1. Include \usepackage{graphicx} in the preamble of your document.

  2. Within the text, place the image using the command \includegraphics{filename.jpg}.

Image Description and Alt text

Additional specifiers can be added to resize image and to add descriptive text.

  1. Express size a proportion of linewidth: width=0.25\linewidth

  2. Add description: alt={image of cat typing on computer}

  3. Put it all together: \includegraphics[width=0.25\linewidth,alt={image of cat typing on computer}]{filename.jpg}

Exercise

Compare your LaTeX code to the solutions at: https://www.overleaf.com/read/hsjrcdzkndvd to troubleshoot.