LaTeX by Example: Text Formatting
LaTeX separates content from presentation. This sample shows commands for bold, italic, and typewriter fonts, as well as font sizing.
Code
\documentclass{article}
\begin{document}
% Font styles
This is \textbf{bold text}.
This is \textit{italic text}.
This is \texttt{monospaced text}.
This is \underline{underlined text}.
% Nested styles
\textbf{\textit{Bold and Italic}}
% Font sizes (relative to document class size)
\tiny Tiny
\small Small
\normalsize Normal
\large Large
\Huge Huge
% Paragraphs
New paragraphs are created by leaving a blank line.
Like this.
\end{document}Explanation
In LaTeX, logical formatting is preferred over physical formatting. However, you often need to apply specific styles. The commands \textbf{} (bold face), \textit{} (italic), and \texttt{} (teletype/monospaced) are the standard tools for this. Unlike word processors, these commands take the text as an argument, ensuring the style applies only to the enclosed content.
Font sizes in LaTeX are relative. Commands like \large, \Large, and \Huge scale the text relative to the base font size defined in the document class. This means if you change your document from 10pt to 12pt, all your headings and emphasized text will scale proportionally, maintaining the document's visual hierarchy.
Paragraphs are separated by one or more blank lines in the source code. A single newline character in the code is treated as a space. This allows you to wrap your source code at a reasonable column width (e.g., 80 characters) without affecting the output. LaTeX automatically handles indentation for new paragraphs, except for the first paragraph of a section.
Code Breakdown
\textbf{...} makes the text bold. It stands for "text bold font".\large is a switch command. It affects all subsequent text until the end of the current scope (group).
