Welcome to the World of LaTeX
If you are used to word processors like Microsoft Word or Google Docs, your first encounter with LaTeX might feel a bit unusual. In those programs, you see the final layout as you type (What You See Is What You Get, or WYSIWYG). LaTeX, however, is a typesetting system. You write plain text combined with "markup" commands that describe the structure and meaning of your document. When you "compile" your code, LaTeX handles the professional layout for you.
Think of it like building a house: standard word processors let you paint the walls while you're still framing the house. In LaTeX, you build the solid architectural frame first, and the "painting" (the layout) is handled automatically by an expert designer.
1. The Anatomy of a LaTeX File
Every LaTeX document consists of two main parts: the Preamble and the Body.
The Preamble
The Preamble is everything that comes before the command \begin{document}. This is where you tell LaTeX what kind of document you are creating, what language you are using, and which extra features (packages) you want to load.
The Body
The Body is everything between \begin{document} and \end{document}. This is where your actual content—text, images, and tables—resides.
Note: Anything written after
\end{document}will be completely ignored by LaTeX.
2. Your First Minimal Document
Let's look at the smallest possible LaTeX document that will actually compile. Open your LaTeX editor (like Typevia, TeXworks, or TeXstudio) and type the following:
\documentclass{article}
\begin{document}
Hello, LaTeX! This is my first document.
\end{document}Breaking Down the Code:
\documentclass{article}: This command tells LaTeX that we are writing a standard article. Other options includereport,book, orbeamer(for presentations).\begin{document}: This signals the start of your content.Hello, LaTeX!...: This is your actual text.\end{document}: This signals the end of the file.
3. Adding Structure: Titles and Sections
A document without a title or sections is just a wall of text. LaTeX makes it incredibly easy to create professional headers.
To add a title, we define the metadata in the Preamble and then tell LaTeX to display it in the Body.
\documentclass{article}
% --- Preamble ---
\title{My Journey into Typesetting}
\author{Jane Doe}
\date{\today}
\begin{document}
% This command actually draws the title
\maketitle
\section{Introduction}
This is the first section of my document. LaTeX automatically numbers sections for me.
\subsection{Why I am learning LaTeX}
I want my documents to look professional and handle mathematical formulas easily.
\section{Conclusion}
That's all for now!
\end{document}Key Commands:
\title{...},\author{...},\date{...}: These store information but don't display it yet.\maketitle: This command takes the information from the preamble and formats it into a beautiful title block.\section{...}and\subsection{...}: These create headers and automatically handle the numbering and font sizing.
4. Basic Text Formatting
In LaTeX, you don't highlight text and click a "B" button. Instead, you wrap the text in a command.
Bold, Italics, and Underline
To emphasize your text, use the following:
\documentclass{article}
\begin{document}
You can write in \textbf{bold text}, \textit{italicized text},
or even \underline{underlined text}.
You can also \textit{\textbf{combine them}} if you need to!
\end{document}Lists
Lists are "environments" in LaTeX. An environment always starts with \begin{...} and ends with \end{...}.
\documentclass{article}
\begin{document}
\section{Shopping List}
% An unordered list (bullet points)
\begin{itemize}
\item Milk
\item Eggs
\item Bread
\end{itemize}
\section{Top Priorities}
% An ordered list (numbered)
\begin{enumerate}
\item Finish the LaTeX guide
\item Practice coding
\item Drink coffee
\end{enumerate}
\end{document}5. Best Practices and Tips
To avoid frustration and keep your code clean, follow these industry-standard practices:
- Use Comments: Use the percent sign (
%) to leave notes for yourself. Anything after a%on that line will not appear in your PDF. - Naming Files: Avoid using spaces in your
.texfilenames (e.g., usemy_first_doc.texinstead ofmy first doc.tex). Spaces can sometimes confuse the compiler. - One Sentence Per Line: This is a "pro tip." LaTeX ignores single line breaks in your code, but starting a new line for every sentence makes it much easier to find errors and use version control (like Git).
- Watch Your Braces: Every
\beginmust have a matching\end, and every{must have a matching}. If you miss one, LaTeX will throw an error.
Warning: LaTeX is case-sensitive.
\Sectionis not the same as\section. Most commands are written in lowercase.
6. Common Mistakes to Avoid
As a beginner, you might run into "Compilation Errors." Don't panic! Here are the most common culprits:
- Missing Backslash: Every command must start with
\. If you typesection{Title}instead of\section{Title}, LaTeX will just print the word "section" and the title in curly braces. - Special Characters: Characters like
$,&,%,#, and_have special meanings in LaTeX. If you want to print them as text, you usually need to put a backslash before them (e.g.,\$). - Missing Preamble: You cannot start typing text before
\begin{document}. The area before that is strictly for setup.
Summary Checklist
- Did I include
\documentclass? - Does every
\beginhave an\end? - Did I use
\maketitleif I defined a title? - Did I save my file without spaces in the name?
Now that you've created your first document, you're ready to explore the world of mathematical typesetting and automated bibliographies—the areas where LaTeX truly shines!
