TEX: LaTeX Document
The mathematician's choice.
Deep dive into the professional typesetting system used for scientific papers, complex formulas, and high-quality books.
Master the .tex File.
A .tex file is plain text code that builds beautiful documents. It is the secret tool used by smart people to create perfect books, math papers, and reports.
What is a .tex file?
A .tex file is a raw text file used by a system called LaTeX. You do not format text by clicking buttons. Instead, you write short commands to tell the computer what to do.
Think of it like writing a recipe. You write the ingredients and steps in the .tex file. The computer reads it and "bakes" a perfect PDF.
No Visual Editing
If you use Word or Google Docs, you see exactly what you get while you type. This is easy, but it gets messy with big files.
In a .tex file, you only look at code. You let the computer handle the margins, fonts, and spacing. This makes your document look exactly the same every single time.
The 3-Step Process
Write Code
You write plain text and commands in your .tex file using any text editor.
Compile
A LaTeX program reads your .tex file and figures out where everything should go.
Get PDF
The program gives you a final, locked PDF file. It looks perfect and professional.
The Anatomy of a .tex File
\documentclass{article}
% This is a comment. It is ignored.
\usepackage{amsmath}
\begin{document}
\title{My First Paper}
\author{Jane Doe}
\maketitle
Hello world! This is my text.
\end{document}
Everything before \begin{document} is the setup. You
tell the computer what type of document it is (like an article or a book) and load extra
tools.
Any line starting with a % sign is a note for yourself.
The computer skips it.
Everything between \begin{document} and
\end{document} is the actual text that will show up on your PDF pages.
Why use .tex files?
Learning to write code just to make a document sounds hard. But people do it because it fixes huge problems.
- It never crashes with big files. A 500-page book will make normal apps freeze. A .tex file handles it easily.
- Total consistency. If you say a heading should be big and bold, every single heading will be exactly the same. No manual fixing needed.
- Free and forever. A .tex file is just text. You can open it 50 years from now on any computer. You don't have to pay for an app to read it.
The Math Superpower
The number one reason people use .tex files is for math. It makes hard equations look perfect without using a mouse.
E = mc^2
You get this:
\frac{1}{2} \times x
You get this:
Handling Book References (Citations)
If you write a paper, you have to list the books you read. Doing this by hand is a nightmare. .tex files use a helper file called a .bib file to do it for you.
1. The Data (.bib file)
You put all book details in one list.
@book{smith2020,
title={Big Data},
author={John Smith},
year={2020}
}
2. The Command (.tex file)
You just call the name when writing.
As seen in \cite{smith2020},
data is growing.
The computer will automatically build a perfect "Works Cited" list at the end of your PDF and put the numbers in the right order. If you move a paragraph, it changes the numbers for you.
Building Big Documents
You do not have to write a 100-page report in one giant .tex file. You can break it into small pieces.
Common Mistakes
Because you are writing code, one small typo can stop the PDF from building. Here are the most common traps to avoid.
Every open brace { needs a close brace }. If you
forget one, the computer gets stuck.
\textbf{Bold text <- ERROR!
Signs like $, %, and & are code
commands. To type them as normal text, put a slash first.
It costs $5. <- ERROR!
It costs \$5. <- GOOD!
How to open and edit .tex files
You can open a .tex file with Notepad, but you need special tools to turn it into a PDF.
Overleaf (Best for Beginners)
A website that runs entirely in your browser. No setup needed. You write code on the left, and the PDF shows up on the right.
TeXstudio (Offline)
A free program you download to your computer. It has lots of buttons to help you insert math and tables quickly without typing.
VS Code (For Pros)
If you are a programmer, you can use VS Code with an extension called LaTeX Workshop. It is very fast and powerful.
Basic Text Formatting
In a normal app, you highlight text and press a "B" button to make it bold. In a .tex file, you wrap the text in a short code.
\textbf{Warning}
\textit{Special}
\underline{Look}
Bullet Points
Use an itemize block to create standard bullet points. Every new
item gets an \item tag.
Numbered Lists
If you want 1, 2, 3 instead of bullets, just change the word to
enumerate. The computer counts for you.
Adding Pictures
You cannot drag and drop images into a plain text file. Instead, you put the image file in the same folder as your code, and then type a command to pull it in.
// Step 1: Tell the file you want to use images (put at top)
\usepackage{graphicx}
// Step 2: Show the image and set its width
\includegraphics[width=5cm]{logo.png}
Building Data Grids (Tables)
Tables are the hardest part of learning .tex files, but they look incredibly clean once finished.
The Rules:
-
{ |c|c| }means two columns, centered, with vertical lines. -
&is used to jump to the next column. -
\\tells the computer to go to the next row. -
\hlinedraws a horizontal line across the grid.
The 1-Second Table of Contents
In Word, making a Table of Contents requires updating it every time you move a page. In a .tex file, it is fully automatic.
\tableofcontents
Just type that one line. The program will scan your file for every
\section{} and \subsection{}, figure out what page they are on, and build a
perfect list for you.
Choosing a Document Type
The very first line of your file decides the layout rules for the whole document.
\documentclass{article}
Best for short reports, homework, or science papers. It does not have chapters, only sections.
\documentclass{report}
Best for longer school papers or company manuals. It supports chapters and title pages.
\documentclass{book}
Best for real books. It formats pages for double-sided printing (left and right margins are different).
Fixing Your Margins
By default, .tex files use massive margins designed for reading academic papers. To change them to normal sizes, you use the geometry package.
\usepackage[margin=1in]{geometry}
Put this at the very top of your file to get standard 1-inch margins on all sides.
Making a Cover Page
You do not have to press "Enter" twenty times to center your title. You just provide the data, and the program builds the cover.
\title{My Great Report}
\author{John Doe}
\date{October 2026}
\maketitle
Magic Page Links (References)
If you type "See Table 4 on page 10", and then add a new table earlier, it becomes Table 5, but your text will still say "Table 4". This is bad. Instead, use magic links.
This is my table. \label{my_cool_table}
Please look at Table \ref{my_cool_table}.
The computer will automatically find the correct number and insert it for you, no matter where you move the table.
Working With a Team
Because a .tex file is just plain text, it is incredibly easy to work on it with other people at the same time.
Overleaf
Works exactly like Google Docs. You share a link, and multiple people can type code into the same file at the same time in the browser.
Git & GitHub
Because it is code, software engineers can use Git to track every single letter that changes, save versions, and merge work together safely.
Ready to try it yourself?
You now know the basics of .tex files. The best way to learn is to copy the code from the "Anatomy" section above, paste it into a blank project on Overleaf, and press "Compile".
More in this series
Master more skills with other tutorials from the Digital Publishing series.
Data Engineering
- DB: Generic Database File: The universal data container.
- SQLite: Portable Database: A database in a single file.
- SQL: Structured Query Language: The language of data.
- CSV: Comma-Separated Values: The universal data exchange format.
Spreadsheets
- NUMBERS: Apple Numbers Spreadsheet: Visual data storytelling.
- XLSM: Macro-Enabled Spreadsheet: Excel with automation power.
- ODS: OpenDocument Spreadsheet: The open spreadsheet standard.
- XLS: Legacy Excel Spreadsheet: The foundation of digital spreadsheets.
- XLSX: Modern Excel Spreadsheet: The data powerhouse.
Presentations
- ODP: OpenDocument Presentation: The open standard for slides.
- PPT: Legacy Presentation: The classic slide deck format.
- PPTX: Modern Presentation: The gold standard for slide decks.
Word Processing
- WPS: WPS Office Document: The lightweight contender.
- PAGES: Apple Pages Document: The designer's word processor.
- ODT: OpenDocument Text: The open text standard.
- DOC: Legacy Word Document: The classic document format.
- DOCX: Modern Word Document: The standard for office documents.
- RTF: Rich Text Format: The universal translator.
Digital Publishing
- TEX: LaTeX Document: The mathematician's choice.
- PDF: Portable Document Format: The digital paper standard.
Software Engineering
- TSX: TypeScript XML: The modern web component.
Markdown & Text
- MD: Markdown: The programmer's writer.
- TXT: Plain Text: The simplest file in the world.