Typevia
LaTeX Basics

Introduction to Special Characters

In standard word processors, what you type is usually what you see. However, LaTeX uses several characters as "control characters" to perform specific functions like formatting, defining macros, or creating mathematical environments.

Because these characters have special meanings, you cannot simply type them into your editor and expect them to appear in the final PDF. If you try to use them literally, LaTeX will either perform a command you didn't intend or, more likely, throw an error.

In this guide, you will learn how to identify these reserved characters, how to "escape" them so they display correctly, and how to access the vast library of symbols available in LaTeX.

The Ten Reserved Characters

LaTeX has ten characters that are reserved for specific programming tasks. If you want these characters to appear in your text, you must use a special command.

CharacterPurpose in LaTeXHow to Display It
%Comments (ignored by compiler)\%
$Starts/ends inline math mode\$
&Alignment tab (used in tables)\&
#Parameter for macros\#
_Subscript in math mode\_
{Start of a group/argument\{
}End of a group/argument\}
~Non-breaking space\textasciitilde
^Superscript in math mode\textasciicircum
\Starts a LaTeX command\textbackslash

Why Escaping Matters

When you place a backslash (\) before a symbol, you are "escaping" it. This tells LaTeX: "Treat the next character as literal text, not as a command."

% This is a comment and won't show up in the PDF.
The cost is $10.00 and the tax is 5%. % This will cause an error!

% Correct way:
The cost is \$10.00 and the tax is 5\%.
The symbol for "and" is \&.

Note: The backslash \ is unique. You cannot escape it with \\ because \\ is the command for a new line. To print a backslash, you must use the command \textbackslash.

Accents and Foreign Language Characters

LaTeX makes it easy to typeset non-English characters and accents. These are created by using a specific command (usually a symbol) followed by the letter you want to accent.

Common Accents

Here are the most frequently used accent commands:

Accent NameInputResult
Grave\`{o}ò
Acute\'{o}ó
Circumflex\^{o}ô
Umlaut/Diaeresis\"{o}ö
Tilde\~{n}ñ
Cedilla\c{c}ç

Example Usage

\documentclass{article}
\begin{document}
The résumé of the café owner was impressive. 
In French, we use the cedilla: garçon. 
The German word for "practice" is Übung.
\end{document}

Quotation Marks, Dashes, and Spacing

Beginners often make the mistake of using the standard double-quote key (") on their keyboard. In professional typesetting, however, opening and closing quotes are different shapes.

Smart Quotes

To get "proper" curly quotes in LaTeX:

  • Use two backticks (`) for the opening quotes.
  • Use two single apostrophes (') for the closing quotes.

Dashes

LaTeX provides three different lengths of dashes for different grammatical purposes:

  1. Hyphen (-): Used for compound words (e.g., "mother-in-law").
  2. En-dash (--): Used for ranges of numbers (e.g., "pages 5--10").
  3. Em-dash (---): Used for breaks in a sentence---like this.
\documentclass{article}
\begin{document}

"This is wrong" (straight quotes). \\
``This is correct'' (curly quotes).

Hyphen: daughter-in-law \\
En-dash: 1990--2000 \\
Em-dash: The weather was cold---freezing, actually.

\end{document}

Mathematical Symbols

One of LaTeX's greatest strengths is its ability to handle complex mathematical symbols. To use these, you must be in Math Mode, which is triggered by surrounding your text with dollar signs $ ... $.

Basic Math and Greek Letters

Greek letters are produced by typing the name of the letter preceded by a backslash.

TypeInputResult
Greek (Lower)$\alpha, \beta, \gamma$α, β, γ
Greek (Upper)$\Gamma, \Delta, \Omega$Γ, Δ, Ω
Operators$\times, \div, \pm$×, ÷, ±
Relations$\leq, \geq, \neq$≤, ≥, ≠
Logic$\forall, \exists, \infty$∀, ∃, ∞

Example Math Block

\documentclass{article}
\usepackage{amsmath} % Recommended for advanced math
\begin{document}

The area of a circle is $A = \pi r^2$.
The quadratic formula is:
\[ x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a} \]

\end{document}

Tip: If you can't remember the name of a symbol, use Detexify. It is a web-based tool where you can draw the symbol with your mouse, and it will provide the corresponding LaTeX command.

Best Practices and Common Pitfalls

To keep your documents clean and error-free, follow these best practices:

  1. Always Close Your Environments: If you start a math environment with $, make sure you end it with $. A missing closing sign will cause LaTeX to treat the rest of your document as math, leading to strange formatting and errors.
  2. Use the amsmath and amssymb Packages: Always include \usepackage{amsmath, amssymb} in your preamble. These packages provide a much wider array of symbols and better formatting for equations.
  3. Check for "Invisible" Errors: A common mistake is using an underscore _ in a filename or a URL without escaping it. Since _ is a math command for subscripts, it will cause an "Incomplete math group" error.
  4. Avoid the Double Backslash for Space: While \\ creates a new line, it is not the correct way to end a paragraph. Use a blank line in your code instead.
  5. Grouping with Braces: When using superscripts (^) or subscripts (_), if the content is more than one character, you must wrap it in curly braces.
    • $e^i\pi$ will result in $e^i \pi$ (only the $i$ is raised).
    • $e^{i\pi}$ will result in $e^{i\pi}$ (the whole group is raised).

Summary of Best Practice Example

\documentclass{article}
\usepackage[utf8]{inputenc} % Allows direct input of some special chars
\usepackage{amsmath, amssymb}

\begin{document}

% Good practice: Using braces for clarity even for single characters
The sequence is defined as $a_{n} = 2^{n} + 1$.

% Good practice: Escaping symbols in text
The price decreased by 10\% (from \$50 to \$45).

% Good practice: Proper dashes for ranges
Please read chapters 1--4.

\end{document}