Skip to main content
It looks like you're using Internet Explorer 11 or older. This website works best with modern browsers such as the latest versions of Chrome, Firefox, Safari, and Edge. If you continue with this browser, you may see unexpected results.
Caltech Library logo

LaTeX Authoring With Overleaf: Workshop Syllabus

Before The Class

Before the workshop, please make sure you have completed the following:

  1. You are able to log into Overleaf through Caltech's institutional portal:
    1. Log into Overleaf here using your @caltech.edu email here: https://www.overleaf.com/institutional-login
    2. You will then be asked to enter your access.caltech credentials (if you haven’t already entered them in your current browser session).
    3. You should then be at the main Overleaf account page.
  2. You have downloaded the following four files (right-click and select "Save As"):
    1. latex_workshop.tex
    2. latex_workshop_tips.tex
    3. latex_workshop_bib_file.bib
    4. workshop_image.png
  3. You have uploaded the files to your Overleaf account in a new project:
    1. Click “New Project” at the top of the left menu.
    2. Select “Blank Project”.
    3. Enter a name for the project (i.e. 2021-02-24-Workshop).
    4. This will create a new project with a default “main.tex” file.
    5. Upload the four files downloaded above to the project by clicking the “Upload” button in the upper left:
    6. You can delete the “main.tex” file if you wish by clicking the three dots to the right of the filename and  selecting “Delete”.

Creating A Document

LaTeX Structures

Commands

Commands are a vital structure for creating any kind of document in LaTeX.  Commands have many uses such as changing document/text formatting, creating equations, delineating sections of a document, and inputting symbols.  To use a command a back slash is placed before the command.  For example \pi is the command to insert the symbol π and \begin{matrix} is one of the commands needed to input a matrix.  Generally commands have the format \command[optional argument]{required argument}. Multiple arguments can be used with some commands by separating each argument with a comma, for example \hypersetup{colorlinks=true, linkcolor=blue, urlcolor=blue} sets the font color of certain hyperlinks in a document.  Some commands such as \pi have neither a optional nor required argument.  Others such as \begin{} will only work with a recognized required argument.  Some commands can also accept an optional argument which is used to specify what action the command will take, for example \documentclass[11pt, twocolumn]{article} tells LaTeX that the current project is an article with 11pt font and should be formatted with two columns, leaving out the optional argument, \documentclass{article}, will cause LaTeX to use the defaults associated with this command  Lastly, some commands may have more than one required argument for example \frac{numerator}{denominator} creates a faction where the first argument is the numerator and the second argument is the denominator.  A list of common commands can be seen in the Common Commands section of this page, there are also links to several useful websites with lists of commands in the resources tab.

Packages

Packages are used to supplement the standard features of LaTeX.  If you are trying to use a command and find that it is generating an error one of the most common issues is that you have not included the needed package in your document.  The command \usepackage{} with the package name as the argument will tell LaTeX to include a certain package in your document. Packages should be placed in the document preamble (see Document Structure below).  If you would like to include multiple packages in your document you can either include the \usepackage{} command multiple times or use it once and separate each package name with a comma i.e.:

\usepackage{geometry}

\usepackage{amsmath}                                  \usepackage{geometry, amsmath, graphicx}

\usepackage{graphicx}

It is better to list the packages separately if you intend to use an optional argument with any package, otherwise it just comes down to personal preference.  Many standard packages come with a MikTex or MacTex download, but you can also install new ones if needed.  Some instruction for installing new packages can be found online.  See the Common Packages part of this page for a list of some useful packages.

Text

Writing text in a LaTeX document is easy.  Once you are inside the body of the document, as described in the Document Structure section of this page, all you have to do is start typing.  When you compile the code LaTeX will take care of all the text formatting based on any commands and packages used.  

Math

Incorporating mathematical symbols and equations is one of the most popular features of LaTeX.  There are a number of ways to include math in a LaTeX document, for more information see the Document Structure section of this page.

‚ÄčComments

Anything that follows a % in a line of code will be treated as a comment and ignored by compiler.  If you want to include a percentage symbol in your text use the command \% for example of you want to write 100% in LaTeX you would write 100\%


Document Structure

To create PDFs with LaTeX the user must generate a .tex file. The .tex file will consist of the code that is compiled by the back end LaTeX software to generate the end result PDF document. With LaTeX installed .tex files can be created in notepad or textedit on Windows or OS X computers respectively, though it is strongly recommenced to generate these files directly in a LaTeX text editor.

A LaTeX document consists of two main pieces, the preamble and the body, the bibliography can be considered a third piece depending on how you structure it. It is recommended that the user creates a new folder on their computer for each LaTeX document they are working on.  When LaTeX compiles a .tex file it generates several files in order to create the PDF having a folder for the each individual document you are working on will help keep all of the files generated organized.  Additionally, it possible the user will want to insert images, figures, or other objects into their document (BibTex files for example), it is much simpler to insert items into the document when they are located in the same folder as the .tex file.

Preamble

The preamble to a LaTeX document is all the information that occurs before the document begins.  The preamble starts with the command \documentclass{} and ends with the command \begin{document}.  Below is an image of a document preamble:

Image of LaTeX code showing the preamble of a document.

Different objects are placed in the preamble between the commands \documentclass{} and \begin{document}.  The most common of these items is the command \usepackage{}.  A more detailed explanation of what packages are can be found under the LaTeX Structures heading on this page, but briefly a package informs the compiler of certain commands that will be used and certain procedures to take while generating the final document.  Any number of packages can be included in the preamble, and one of the most common mistakes made by the new LaTeX user is to include a command in their document without including the proper package in the preamble.  Other commands such as \title\author, and \date are included in the preamble and than may be incorporated within the document.  Lastly, new commands can be created in the preamble that will only be used in the current document.

Body

The body of a LaTeX document is where all of the text, equations, figures, tables, etc... will be placed.  The body of the document begins with the command \begin{document} and ends with the command \end{document}.  A very simple sample code and its output can be seen below.  The code contains both the preamble and body of the document.

Image showing the body of a LaTeX document

Image of a document produced by LaTeX.

Writing Math

One of the most popular features of LaTeX is its ability to easily incorporate and format mathematical equations and symbols.  There are two important things to remember to ensure LaTeX handles mathematical formula properly.  

First is to make sure that you have included all necessary packages.  The most common package for using mathematical formulas in a document is "amsmath", though this package allows the use of a multitude of mathematical symbols and commands it does not include everything.  If you try to compile a document and an error occurs related to a mathematical object you have included you will want to check if there is an additional package you need, for example if you try to include bold lettering in a mathematical equation without the package "bm" an error will occur.

Second is to entire math mode.  Math mode lets LaTeX know that something should be formatted as math and not regular text, there are also some symbols and commands that can not be used outside of math mode.  The image below shows the same text, f(x) = 2x+5, first not using math mode and second using it.  There is a very clear difference between how the equation is formatted inside and outside of math mode. 

Image comparing mathematics written in and out of LaTeX's math mode

There are several different ways to enter math mode.  If you would like to write mathematical expression inside a line of text all the mathematical text should be book ended by $.  For example writing $x+3$ would tell LaTeX to write x+3 as math. If you want math to appear on its own line it what is called display mode you can use either the command $$ on both sides of the math, or \[ and \].  The previous example would look like this: $$x+3$$ or \[x+3\].  Finally, some commands will automatically place the user in math mode for example any text appearing between the commands \begin{equation} and \end{equation} will be written in math mode.  Go to the exercises tab for some questions to let you practice using math mode. 


Common Commands

Here is a list of some useful and common commands for LaTeX.  Links to more exhaustive lists can be found on the resources tab of this guide.  If you are looking for specific mathematical symbols check the links on the resources tab.  If you are interested in more information about a specific command a simple Google search will often provide great results.   

Preamble commands:

\documentclass{}

The first command in any document.  Used to specify what type of document is being made.  Some common arguments are article (common for scientific journals), book, IEEEtran (for IEEE transaction format), slides, beamer (for presentations).

\usepackage{}

This command imports a package into the LaTeX document.  This is important for including any commands that are not standard in LaTeX.

\title{}

The intended title of the document should be used as the argument

\author{}

The author of the document should be used as the argument, for multiple authors use \and to separate authors name or use the authblk package.  For the authblk package uses the following format where \affil is used to entire the affiliation of the author and the optional argument denotes the whatever symbol should be used after the author's name:

\author[1]{1st Author} 
\author[1]{2nd Author} 
\author[1]{3rd Author} 
\author[2]{Nth Author}
\affil[1]{Institute 1}
\affil[2]{Institute 2} 

\date{}

The argument is the date associated with the document.  Note that leaving the argument empty will create a blank date in the title, and not including the command will default the title to the date compiled.

 

Body commands:

\maketitle

Creates a title based on the \title\author, and \date provided.

\tableofcontents\listoffigures\listoftables

Creates a table of content, list of figures, and/or list of tables.

\newpage{}

Creates a new page

\\

Creates a line break

\begin{} and \end{}

Whenever there is a \begin{} it must be paired with an \end{} with the same argument at some point later in the document.  The \begin{} command tells LaTeX to entire a certain environment while the \end{} command concludes that environment.  \begin{document} will start the body of the document (end the preamble) and \end{document} will end the document.  Other common arguments are equationaligntabular, and figure

\section{}

Denotes a new section.  The title section should be used as the argument.  Sections will be automatically included in the table of contents. Use the commands \subsection{} and \subsubsection{} to create sections within sections.


Common Packages

Packages allow for additional features to be used within a LaTeX document. Both MikTex and MacTex come pre-installed with a large number of standard packages and instructions for installing new packages. Overleaf also comes with standard packages based on TeX Live 2020. To use a package include the command \usepackage{} where the argument is the package name i.e. \usepackage{amsmath}. Below is a brief list of some useful LaTeX packages:

amsmath

This package allows for more complicated mathematical structures within a document such as matrices.

geometry

This package is for the more advanced user.  It allows the user to better control the formatting of the document.

graphicx

This package allows graphics to be integrated into a document.

hyperref

This package allows for hyperlinks inside a document.  Use the command \hypersetup{} to control different link colors.

booktabs

A useful package if you are having trouble with spacing inside of tables.

BibTeX

Introduction

Since LaTeX is often used to create academic works that will cite many different sources it is important to know how to create a bibliography in LaTeX. With a little practice and the help of a citation management creating LaTeX bibliographies can be very easy. 

It is strongly recommend that you use a citation management tool, not only to help create LaTeX bibliographies, but to help organize and track articles, books, and other documents throughout your academic career. Caltech offers training and support for Zotero, and more information can be found on our Zotero guide.

Important note: When creating a bibliography you will need to compile the document twice in order to create properly formatted references.


Creating a Bibliography

There are two parts to creating a bibliography in a LaTeX document.

Part one is the creation of a separate .bib file. This file contains all of the citation information (i.e. title, author, publication date, publisher, etc...), as will as, a bibID for each citation.  It is strongly recommended to use a citation management tool to create your .bib files.  Those tools will greatly speed up the process and help keep the file organized, generate automatic bibIDs (which can be edited if desired), and auto fill all relevant data fields which will prevent typos or bugs within the file.  Below is an example of the .bib format for four different common references if you choose to entire them yourself.  Note that not all fields are required and any unused field should be deleted.  The bibID is what is used in the main LaTeX document to create in-line references as well as completed bibliographies.  When creating the final bibliography LaTeX will only include citations that were referenced in the document, so its ok to have unused citations in your .bibfile.

Article Book Online Resource Conference Proceeding
@article{bibID,
    author = {author},
    title = {title},
    journaltitle = {journaltitle},
    date = {date},
    OPTtranslator = {translator},
    OPTannotator = {annotator},
    OPTcommentator = {commentator},
    OPTsubtitle = {subtitle},
    OPTtitleaddon = {titleaddon},
    OPTeditor = {editor},
    OPTeditora = {editora},
    OPTeditorb = {editorb},
    OPTeditorc = {editorc},
    OPTjournalsubtitle = {journalsubtitle},
    OPTissuetitle = {issuetitle},
    OPTissuesubtitle = {issuesubtitle},
    OPTlanguage = {language},
    OPToriglanguage = {origlanguage},
    OPTseries = {series},
    OPTvolume = {volume},
    OPTnumber = {number},
    OPTeid = {eid},
    OPTissue = {issue},
    OPTmonth = {month},
    OPTpages = {pages},
    OPTversion = {version},
    OPTnote = {note},
    OPTissn = {issn},
    OPTaddendum = {addendum},
    OPTpubstate = {pubstate},
    OPTdoi = {doi},
    OPTeprint = {eprint},
    OPTeprintclass = {eprintclass},
    OPTeprinttype = {eprinttype},
    OPTurl = {url},
    OPTurldate = {urldate},
}
@book{bibID,
    author = {author},
    title = {title},
    date = {date},
    OPTeditor = {editor},
    OPTeditora = {editora},
    OPTeditorb = {editorb},
    OPTeditorc = {editorc},
    OPTtranslator = {translator},
    OPTannotator = {annotator},
    OPTcommentator = {commentator},
    OPTintroduction = {introduction},
    OPTforeword = {foreword},
    OPTafterword = {afterword},
    OPTsubtitle = {subtitle},
    OPTtitleaddon = {titleaddon},
    OPTmaintitle = {maintitle},
    OPTmainsubtitle = {mainsubtitle},
    OPTmaintitleaddon = {maintitleaddon},
    OPTlanguage = {language},
    OPToriglanguage = {origlanguage},
    OPTvolume = {volume},
    OPTpart = {part},
    OPTedition = {edition},
    OPTvolumes = {volumes},
    OPTseries = {series},
    OPTnumber = {number},
    OPTnote = {note},
    OPTpublisher = {publisher},
    OPTlocation = {location},
    OPTisbn = {isbn},
    OPTchapter = {chapter},
    OPTpages = {pages},
    OPTpagetotal = {pagetotal},
    OPTaddendum = {addendum},
    OPTpubstate = {pubstate},
    OPTdoi = {doi},
    OPTeprint = {eprint},
    OPTeprintclass = {eprintclass},
    OPTeprinttype = {eprinttype},
    OPTurl = {url},
    OPTurldate = {urldate},
}
@online{bibID,
    ALTauthor = {author},
    ALTeditor = {editor},
    title = {title},
    date = {date},
    url = {url},
    OPTsubtitle = {subtitle},
    OPTtitleaddon = {titleaddon},
    OPTlanguage = {language},
    OPTversion = {version},
    OPTnote = {note},
    OPTorganization = {organization},
    OPTdate = {date},
    OPTmonth = {month},
    OPTyear = {year},
    OPTaddendum = {addendum},
    OPTpubstate = {pubstate},
    OPTurldate = {urldate},
}
@proceedings{bibID,
    editor = {editor},
    title = {title},
    date = {date},
    OPTsubtitle = {subtitle},
    OPTtitleaddon = {titleaddon},
    OPTmaintitle = {maintitle},
    OPTmainsubtitle = {mainsubtitle},
    OPTmaintitleaddon = {maintitleaddon},
    OPTeventtitle = {eventtitle},
    OPTeventdate = {eventdate},
    OPTvenue = {venue},
    OPTlanguage = {language},
    OPTvolume = {volume},
    OPTpart = {part},
    OPTvolumes = {volumes},
    OPTseries = {series},
    OPTnumber = {number},
    OPTnote = {note},
    OPTorganization = {organization},
    OPTpublisher = {publisher},
    OPTlocation = {location},
    OPTmonth = {month},
    OPTisbn = {isbn},
    OPTchapter = {chapter},
    OPTpages = {pages},
    OPTpagetotal = {pagetotal},
    OPTaddendum = {addendum},
    OPTpubstate = {pubstate},
    OPTdoi = {doi},
    OPTeprint = {eprint},
    OPTeprintclass = {eprintclass},
    OPTeprinttype = {eprinttype},
    OPTurl = {url},
    OPTurldate = {urldate},
}

 

Part two is integrating the information from the.bib file into your main LaTeX document.  The three ways for doing so are using BibTexBibTex with natbib, or BibLaTeX.  The hyperlinks will take you to explanation of each method from sharelatex.com.  Both BibTex with natbib and BibLaTeX have the advantage of optional arguments because they require a \usepackage[]{} command.  These optional arguments can be used to fine tune how references appear throughout the document and the formatting of the bibliography.  Below is a table that highlights some of the important difference for each method.  

BibTex BibTex with natbib BibLaTeX
Packages Needed None natbib biblatex

In document

command 

for citation

\cite{bibID} \cite{bibID} \cite{bibID}

Bibliography

styles

Use command (place in body):

\biblographystyle{stylename}

Common Stylenames:

abbrv    
acm
alpha
apalike    
ieeetr    
plain    
siam    
unsrt

Use command (place in preamble): 

\biblographystyle{stylename}

Common Stylenames:

dinat
humannat    
plainnat    
abbrvnat    
unsrtnat    
rusnat    
ksfh_nat

Optional Argument

of \usepackage:

\usepackage[
style=stylename,
]{biblatex}

Common Stylenames:

numeric    
alphabetic    
authoryear    
authortitle    
verbose    
reading    
draft    

Print bibliography

command

\bibliography{bibfilename}

DO NOT INCLUDE .bib

\bibliography{bibfilename}

DO NOT INCLUDE .bib

\printbibliography