Typevia
LaTeX Basics

Understanding the LaTeX Philosophy

LaTeX (pronounced "LAY-tek" or "LAH-tek") is a high-quality typesetting system designed for the production of technical and scientific documentation. Unlike Microsoft Word or Google Docs, which are WYSIWYG (What You See Is What You Get) editors, LaTeX follows a WYSIWYM (What You See Is What You Mean) philosophy.

In a standard word processor, you format text as you type by clicking buttons for bold, italics, or font sizes. In LaTeX, you write plain text interspersed with commands that describe the structure and meaning of the content. You then "compile" this source code to generate a professional PDF.

Why use LaTeX?

  • Professional Typography: LaTeX handles kerning, hyphenation, and justification better than almost any other tool.
  • Mathematical Excellence: It is the industry standard for typesetting complex equations.
  • Stability: Large documents (like a 300-page thesis) remain stable and manageable.
  • Automation: It automatically handles numbering for sections, figures, tables, and bibliographies.

Setting Up Your Environment

To start writing LaTeX, you need two things: a TeX Distribution (the "engine" that processes your code) and a LaTeX Editor (where you write your code).

The easiest way to start is using Typevia. It is a cloud-based LaTeX editor that requires no installation. It provides a side-by-side view of your code and the resulting PDF.

  • Pros: No setup, collaboration features, accessible from any computer.
  • Cons: Requires an internet connection.

Option 2: The Local Installation

If you prefer to work offline, you can install a distribution and an editor on your computer.

  • Distributions: MiKTeX (Windows) or TeX Live (Mac/Linux).
  • Editors: TeXstudio, VS Code (with the LaTeX Workshop extension), or Texmaker.

Note: For the purpose of this guide, the code examples will work identically whether you are using Typevia or a local installation.


The Anatomy of a LaTeX Document

Every LaTeX document consists of two main parts: the Preamble and the Body.

1. The Preamble

The preamble is everything that comes before the \begin{document} command. This is where you define the type of document you are creating and load "packages" (plugins that add extra functionality).

2. The Body

The body is the area between \begin{document} and \end{document}. This is where your actual content—text, images, and equations—lives.

Basic Syntax

A LaTeX command always starts with a backslash (\). Mandatory arguments are placed in curly braces {} and optional arguments are placed in square brackets [].

\commandname[optional]{mandatory}

Creating Your First Document

Let's look at a "Hello World" example. This code produces a simple document with a title and a single paragraph.

% This is the Preamble
\documentclass[12pt, a4paper]{article}

% Loading a package for better font encoding
\usepackage[T1]{fontenc}

% Document Metadata
\title{My First LaTeX Document}
\author{Jane Doe}
\date{\today}

% This starts the Body
\begin{document}

\maketitle % This command generates the title, author, and date

\section{Introduction}
This is my very first paragraph in \LaTeX. I am learning how to separate content 
from presentation. 

\section{Conclusion}
LaTeX makes document creation look professional and consistent.

\end{document}

Breaking Down the Code:

  • \documentclass{article}: Tells LaTeX to format this as a standard article. Other classes include report, book, and beamer (for presentations).
  • %: The percent sign is used for comments. Anything after it on the same line will be ignored by the compiler.
  • \maketitle: Uses the information provided in the preamble to create a formatted title block.
  • \section{...}: Automatically creates a numbered heading.

Basic Text Formatting and Structure

LaTeX handles spacing and formatting differently than what you might be used to.

Paragraphs and Spacing

In LaTeX, pressing "Enter" once does not start a new paragraph. It is treated as a simple space. To start a new paragraph, you must leave a completely blank line.

This is the first paragraph.

This is the second paragraph, separated by a blank line.

Common Text Styles

You can apply styles using the following commands:

  • \textit{Italic text} for Italic text
  • \textbf{Bold text} for Bold text
  • \texttt{Monospaced text} for Monospaced text

Creating Lists

LaTeX provides "environments" for lists. An environment starts with \begin{...} and ends with \end{...}.

Unordered (Bulleted) List:

\begin{itemize}
    \item First item
    \item Second item
\end{itemize}

Ordered (Numbered) List:

\begin{enumerate}
    \item First step
    \item Second step
\end{enumerate}

Best Practices and Common Pitfalls

As you begin your LaTeX journey, keep these tips in mind to avoid common errors.

1. Reserved Characters

Certain characters have special meanings in LaTeX. If you want to display them as text, you must use a backslash before them:

  • $ (starts math mode): Use \$
  • % (starts a comment): Use \%
  • & (used in tables): Use \&
  • _ (used for subscripts): Use \_

2. Organizing Your Code

Keep your preamble clean. As your documents grow, you might load many packages. Group them by function (e.g., math packages together, image packages together) to keep the code readable.

3. Error Messages

Don't panic when you see an error! Most errors are caused by:

  • Forgetting to close a brace {}.
  • Misspelling a command (e.g., \sectionn instead of \section).
  • Using a command that requires a package you haven't loaded in the preamble.

Tip: If you get stuck, look at the line number provided in the error log. The mistake is usually on that line or the one immediately preceding it.

4. Mathematical Notation

While math is a deep topic, remember that all math must be inside "math mode." Use single dollar signs $ ... $ for inline math and \[ ... \] for displayed equations.

The Pythagorean theorem is $a^2 + b^2 = c^2$.

By following this structure, you have moved from a blank page to a professionally typeset document. LaTeX has a learning curve, but the control and quality it offers make it an invaluable skill for any student, researcher, or professional.