LaTeX fundamentals¶
Prerequisite: compile your first document. Goal: use semantic structure instead of manual spacing.
Think in structure¶
An article is built from sections, paragraphs, lists, and references. A blank
line starts a new paragraph. A single line break usually behaves like a space.
Do not use repeated \\ commands to create paragraph spacing; \\ requests
a line break in contexts that support it.
\documentclassselects the overall document type.\usepackageloads capabilities in the preamble.\sectionand\subsectionexpress the document hierarchy.\labelnames a numbered object;\refretrieves its number.\newcommandgives a repeated idea a meaningful name.
Complete example¶
\documentclass[11pt]{article}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage[margin=1in]{geometry}
\usepackage{hyperref}
\newcommand{\toolname}{LaTeX}
\title{A Small Document with Structure}
\author{LaTeX for Everyone}
\date{\today}
\begin{document}
\maketitle
\section{Introduction}
\label{sec:introduction}
\toolname{} separates content from its appearance. A blank line starts
a new paragraph; repeated spaces do not create layout.
This paragraph contains \textbf{bold text}, \emph{emphasis}, and an
escaped percentage: 25\%.
\section{A short plan}
Section~\ref{sec:introduction} introduced the main idea.
\begin{enumerate}
\item Write meaningful headings.
\item Compile the document.
\item Read the PDF and fix the first reported error.
\end{enumerate}
\subsection{Things to bring}
\begin{itemize}
\item A text editor and a TeX distribution.
\item A willingness to revise.
\end{itemize}
Visit the \href{https://www.latex-project.org/}{LaTeX Project}
for official documentation.
\end{document}
The empty group in \toolname{} keeps the following space from being swallowed
after a command name. Section~\ref{...} uses a non-breaking space so that the
word and its number stay together.
Compile and inspect¶
From the repository root:
Expected output: a title, two sections, one subsection, an ordered plan, a bullet list, a working external link, and the text 25%. The section reference resolves to the introduction.
Characters such as %, &, _, #, and $ have special meanings.
In ordinary text use \%, \&, \_, \#, and \$ when you need the
literal symbols. A % otherwise starts a comment through the end of the line.
Practice¶
Add a third section with a label and refer to it from the introduction.
Change \toolname once and check that every use changes.
Insert 50% completed and observe why the rest of that source line disappears;
repair it as 50\% completed.
Check your work: the reference displays a number, the list numbering is automatic, and no manual spaces are needed to align headings.
Next: mathematics.