Skip to Main Content

LaTeX for Publications: Writing LaTeX: The Basics

Document Properties: The Preamble

The preamble of a LaTeX document is where the document is document type is defined. It is also the location where packages are loaded. It can be thought of as the "setup" section of the document. The preamble consists of everything "above" the \begin{document} line.

Comments (Optional but Useful)
To add notes for yourself or other editors in a LaTeX document, use comments. Insert a percent symbol (%), and everything after the symbol—in that line—will be ignored by LaTeX. Comments can add a lot of clarity to a LaTeX document. They are used in some of the examples in this guide.

Document Class
Use the \documentclass command to tell LaTeX what kind of document you are creating. There are several classes available, but here are some of the most common:
article - for articles intended for publication in journals, academic research papers, etc.
proc - based on the article class, it is for paper intended for conference proceedings.
report - for longer documents containing multiple chapters, or for short books or theses.
book - for actual books. This class is often used to write textbooks
letter - for correspondence ("snailmail").

Setting Font Size in Document Class
The default font size in LaTeX is 10 points. If you want to change it, do so in square brackets in the \documentclass command:
 
\documentclass[11pt]{article} % Setting font size to 11pts


Packages
Packages in LaTeX are macros, which are loaded in the preamble. The simple \usepackage command is all that's needed to make the features of a package available in your document.

Enabling three packages in a LaTeX document:

\usepackage{graphicx} % Required for inserting images
\usepackage{geometry} % For paper size, margins
\usepackage{hyperref} % Enables hyperlinks


Some Useful Packages

amsmath - Optional, but very useful for mathematical equations.
bpchem - Allows chemical formulas to be used.
graphicx - Enables the use of images in the document.
geometry - Needed for correcting paper size and setting margins.
hyperref - Needed for hyperlinks
 

Setting Paper Size and Margins
The default paper size in LaTeX is the widely-used European A4 standard, which is 8.3 x 11.7 inches (210 x 297 mm). If you are creating a document to print on North American letter size (8.5 x 11 inches), you must set this in the preamble. The geometry package is needed, along with a short command in the preamble.

Let's set the paper size to US standard and margins to 1 inch:
\usepackage{geometry} % For paper size, margins
\geometry{letterpaper, margin=1in} 


Setting Paragraph Spacing and/or First-Line Indentation (Optional)
By default in LaTeX, there's no blank line between paragraphs, and the first line of each paragraph is indented. If you need to change either or both of these, it can be done in the preamble with the \setlength command:

\setlength{\parindent}{0pt} % First-line indent is 0 points
\setlength{\parskip}{11pt} % Paragraph spacing is 11 points

Note: The above example uses points (pt) as the unit of measure. A point is approximately 1/72 of an inch. You can also use inches (in), centimeters (cm), millimeters (mm), ex's (ex - the width of a lower-case x in the current font), or em's (em - the width of an uppercase M in the current font).

How to Edit LaTeX Documents

The Basic Rules
Everything between the \begin{document} and the \end{document} commands is the LaTeX document. There are a few things to know about LaTeX documents:
  • The default paper size is A4—an international standard outside North America (8.3 x 11.7 inches). The paper size can be corrected to US letter size with the geometry package.
  • The margins can easily be set with the geometry package. There are examples on this page. The default LaTeX margins are:
    • 1.5 inches on 12pt documents
    • 1.75 inches on 11pt documents
    • 1.875 inches on 10pt documents
  • There is just one space between words, no matter how many times you hit the spacebar.
  • There is no space between paragraphs. This can be modified with the \setlength command.
  • The first line of each paragraph is indented. This can be modified with the \setlength command.

Starting a New Paragraph
To begin a new paragraph, hit the [Enter] key twice, leaving a blank line between paragraphs in your editor. LaTeX will interpret this as a command to start a new paragraph.

Inserting a Line Break
To move down a single line (insert a line break), just type two backslashes (\\) at the end of the line. You do not have to hit the [Enter] key, though it may make your document easier for you to edit later.

Putting It All Together: A Basic Document

Here is a basic document as a sample:
\documentclass[11pt]{article} % Set font size and doc type
\usepackage{graphicx} % Required for inserting graphics
\usepackage{geometry} % Correct the paper size, set margins
\geometry{letterpaper, margin=1in} % Set paper size, margins

\title{My First LaTeX Document}
\author{Juanita Doe}
\date{January 2024}

\begin{document}

\maketitle % Inserts title, author and date

This is my first LaTeX document! I'm using Overleaf to keep things simple.

\end{document}
Staff LADR