Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

LaTeX Introduction

LaTeX Introduction

LaTeX is a typesetting system based on TeX, widely used to produce high-quality scientific and mathematical documents, developed by American computer scientist Leslie Lamport in the 1980s.

TeX is a low-level typesetting engine developed by Donald Knuth, mainly used for handling complex mathematical formulas and high-quality typesetting.

LaTeX provides a higher level of abstraction on top of TeX, allowing users to focus more on content without worrying too much about typesetting details.

Unlike common word processors (such as Microsoft Word), LaTeX uses plain text files to describe the structure and content of a document and generates the final PDF through compilation. LaTeX is especially suitable for handling complex math formulas, references, and cross-references.

LaTeX was originally designed to facilitate the typesetting of academic papers and technical documents, especially in fields such as mathematics, physics, and computer science. Over time, LaTeX gradually became one of the standard tools in academia and publishing.


LaTeX Features


How Does LaTeX Work?


Why Use LaTeX?


LaTeX vs. Word

Feature LaTeX Microsoft Word
Typesetting Quality Professional-grade typesetting, especially good at complex formulas and long documents. Suitable for simple documents; complex typesetting needs manual adjustment.
Learning curve Requires learning basic syntax; harder to pick up at first. WYSIWYG, easy to get started.
Degree of Automation Automatically handles numbering, cross-references, table-of-contents generation, etc. Requires manual adjustment of numbering and formatting.
Math Formula Support Powerful math formula typesetting, supports complex symbols and structures. Limited formula editing; complex formulas are hard to handle.
Cross-platform support Fully cross-platform; documents behave consistently across systems. Decent cross-platform support, but formatting may vary by version.
Document Structure Content and format are separated, easy to maintain and collaborate. Content and format are mixed, making long documents harder to maintain.
Extensibility Extends functionality via packages; supports custom commands and environments. Functionality extension relies on plugins, with lower flexibility.

LaTeX's workflow can be summarized in three steps: write source code, run compilation, get PDF.

LaTeX compilation flow: .tex source compiled into PDF document

The .tex file we write is an ordinary plain-text file that can be opened with any editor; the compiler turns it into the final PDF.


LaTeX's Basic Workflow

The basic process of writing a document with LaTeX is as follows:

For example, a simple LaTeX document is as follows:

Example

\

documentclass

{

article

}

% document class

\

title

{

My First LaTeX Document

}

% title

\

author

{

Author

}

% author

\

date

{

\today

}

% date

\begin

{

document

}

\

maketitle

% generate title

\

section

{

Introduction

}

% section

This is my first LaTeX document!

\

% line break

This is a simple paragraph.

\

section

{

Math Formulas

}

This is an inline formula:

$E = mc^2$

.

\

% inline formula

This is a display formula:

[

  \int_a^b f(x) \, dx       

\

]

\end

{

document

}


LaTeX's Core Idea

LaTeX's core idea is the separation of content and format:


The Relationship Between TeX, LaTeX, Packages, and Distributions

This is the most easily confused set of concepts for beginners; clarifying them means you will never get lost choosing tools or setting up the environment later.

The entire TeX ecosystem can be divided into four layers, from bottom to top: engine, format, package, and editor.

The engine is the program that actually does the typesetting; common ones are TeX, pdfTeX, XeTeX, and LuaTeX. Among them, XeTeX and LuaTeX natively support Unicode and system fonts, which is why they are recommended for compiling Chinese documents.

The format is a set of command rules built on top of the engine; LaTeX is currently the most popular format.

Packages are plugins that further extend functionality on top of the format, such as Chinese support (ctex), math enhancement (amsmath), and page setup (geometry). CTAN hosts over five thousand packages.

Finally, a collection that bundles the engine, format, and a vast number of packages for one-time installation is called a distribution, such as TeX Live and MiKTeX.

Layered architecture of the TeX ecosystem: editor, package layer, LaTeX format, TeX engine, and distribution

Remember Five Terms in One Sentence

Engine: the program that actually typesets source code into PDF, such as XeTeX.

LaTeX format: a set of handy command rules defined on top of the engine.

Package: a ready-made function extension written by others, such as the Chinese support package ctex.

Distribution: a complete installer that bundles the engine, format, and packages together.

Editor: the software you write code in; it does not participate in typesetting itself.

An editor is not a compiler. Overleaf, TeXstudio, and VS Code only write code and trigger compilation; the actual typesetting is done by the engine in the distribution. So in a local environment, installing only the editor without a distribution cannot produce a PDF (Overleaf is the exception, as its cloud includes a complete distribution).


LaTeX's Advantages and Use Cases

LaTeX is not a universal tool, but in the following scenarios its efficiency and quality advantages are very clear.

Scenario Why It Fits
Academic Papers and Theses Most journals and universities provide official LaTeX templates; formulas, figures, tables, and reference numbering are all automatic
Science and engineering lecture notes in math, physics, etc. Fast formula input; typesetting quality of complex formulas (matrices, equation systems, multi-line derivations) far exceeds rich-text editors
Books and Long Reports Automatic chapter management and globally consistent styles; documents of hundreds of pages still stay format-consistent
Resumes Templates like moderncv produce polished layouts; content and style are separated, so changing content does not break the layout
Presentations Beamer can produce academic slides with perfect formula typesetting, which is hard for PPT to achieve

Conversely, do not force LaTeX in these cases: posters needing heavy graphic design, office documents requiring multi-person real-time annotation, and short documents with few formulas that must be finished the same day; Word or specialized tools are more convenient.

LaTeX's learning curve is steep at first then flattens: in the first few days you may feel "even changing the font size requires looking up a command," but by finishing the basics of this series you will appreciate the long-term benefits of automated typesetting.


Common Distribution Comparison

A distribution solves only one problem: it saves you from installing the engine and packages one by one.

Distribution Supported platforms Size Feature Suitable for
TeX Live Windows / macOS / Linux Full about 8 GB, Basic scheme about 300 MB Officially maintained by TUG, one release per year, consistent behavior across the three platforms The first choice for most users
MacTeX macOS Full about 5 GB, Basic about 100 MB The macOS version of TeX Live, bundled with small GUI tools Mac users
MiKTeX Mainly Windows Basic about 300 MB Packages downloaded automatically on demand; small initial install Windows users, tight disk space
TinyTeX Windows / macOS / Linux About 100-200 MB Minimal distribution; install packages on demand via command line Users familiar with the command line, servers, and CI environments

When downloading TeX Live or packages in China, it is recommended to switch the software source to a domestic mirror such as Tsinghua TUNA; the speed can be an order of magnitude faster.


Choosing an Editor

The editor determines your "writing" experience; it can be changed at any time and is independent of the distribution.

Editor Type Advantages Limitation Who It's For
Overleaf Online No installation, built-in compilation environment, rich template library, supports collaboration Unavailable offline; the free version has limits on compilation time and number of projects Beginners (recommended by this tutorial)
TeXstudio Local Desktop Free and open source, strong command completion and error hints Interface is rather traditional Users who prefer local writing
VS Code + LaTeX Workshop Local Plugin Modern interface, Git-friendly, integrated compile preview Requires some configuration Developers already using VS Code
TeXworks Local Desktop Bundled with TeX Live, ready to use out of the box Fewer features Writing short documents temporarily

It is recommended to start with Overleaf https://www.overleaf.com/, zero configuration to directly follow the tutorial and type code; when you need offline writing or version management, then set up a local environment.


Sneak Peek: A Complete LaTeX Source File

Before formally setting up the environment, take a look at what a real LaTeX document looks like.

The source below is complete and compilable, including Chinese text, a title, and two math formulas.

Example

% document class: ctexart is equivalent to article plus Chinese support

\

documentclass

{

ctexart}

  \title{我的第一份 \LaTeX{} 文档

}

 

% document title

\

author

{

RUNOOB

}

                   

% author

\

date

{

August 2026

}

               

% date; writing \today auto-fills the current day

\begin

{

document

}

                 

% body starts here

\

maketitle

                       

% generate title block

LaTeX is especially good at math formula typesetting. The inline form of the mass-energy equation is

$E = mc^2$

,

To display it centered on its own line (display formula), write:

[

E = mc^2 \

]

where

$E$

is energy,

$m$

is mass,

$c$

is the speed of light in a vacuum.

\end

{

document

}

                   

% body ends here

After compiling this source, the resulting PDF page is as follows:

PDF effect after compiling the first LaTeX document

Not understanding these commands now is completely normal; each later part of this series will break them down one by one.

Here you only need to remember two structures: from \documentclass to \begin{document} is called the preamble, used for global settings; between \begin{document} and \end{document} is called the body, where you write content.