Formatting Text

After what may have seemed like a lot of build-up, we finally get to add some content to our document. Compared to a word processor's what-you-see-is-what-you-get display and easy-to-use buttons, writing in LaTeX can seem laborious at first. But, after some adjustment, you will find that the process is similar.

We have seen that commands, with their backslashes and curly braces, do not print in the document. However, most other text can be typed as usual.

With a few simple commands, we can add formatting and organization.

Comic strip: a character is caught using MS Word by his mother, but he has typed what looks like LaTeX commands in the document to fool her.
Don't be tempted to run back to the sweet embrace of the word processor just yet. (Edit by u/TheC00lCactus on r/LaTeX.)

Sections and subsections

Before, we mentioned that the article document class allows us to use sections and subsections. These come with pretty intuitive commands.

The command \section{Title} produces a section.

The command \subsection{Title} produces a subsection of a section.

The command \subsubsection{Title} produces a subsection of a subsection.

Whatever title you choose for the section is put within the curly braces.

The sections, subsections, and subsubsections are all automatically numbered. As shown in the screenshot, the first section is 1, the first subsection of 1 is 1.1, the first subsection of 1.1 is 1.1.1, and so on.

Sections provide an easy way to organize a document. For example, you can use sections for separate questions in a homework assignment.

Sections and subsections in the document, as described in the text.

Example

Look back at your Practice Exercises project. In the document, you can see the command,

\section{Introduction}

Looking at the preview, 1 Introduction is printed in large, bold text.

Exercise 3.1.1

Looking forward to the rest of this module, let's add some sections and subsections to contain our work.

Add a section for text and a section for math. To the math section, add subsections for basic math symbols, fractions and functions, and calculus.

Solution 3.1.1

You can choose your own titles for the sections and subsections, but one possibility is

\section{Text}

\section{Math}

\subsection{Basic math symbols}

\subsection{Fractions and functions}

\subsection{Calculus}

Be sure that all commands are in the document - between \begin{document} and \end{document}.

Paragraphs

Try copying the following lines into the first section of your project and compiling the preview.

This is my first paragraph.

This is my second paragraph.

In the preview, the two sentences appear on the same line.

In order to start a new paragraph, we need an entirely blank line. Thus, add another line break between the two sentences,

This is my first paragraph.


This is my second paragraph.

and they should now appear on separate lines in the preview.

However, the second sentence is now indented.

As a rule, LaTeX automatically indents every new paragraph. The exception is the first paragraph of a section/subsection/subsubsection. If you'd like, you can remove this indentation with the \noindent command at the beginning of a paragraph.

As described, the new paragraph is automatically indented.

Start a new paragraph with a blank line.

Use \noindent at the beginning of a new paragraph to remove the automatic indentation.

Spacing between paragraphs

A new paragraph begins on a new line. You may have noticed that there is no extra spacing added between paragraphs, as is sometimes the default in programs like Word. In fact, multiple blank lines are treated as a single blank line, so hitting "enter" multiple times will not even add more space between paragraphs.

Since this tutorial focuses on math, we will not get into the many specialized commands for laying out text in LaTeX. However, if you would like more control over the spacing in your document, you can refer to Overleaf's tutorial on line breaks and blank spaces.

Font changes

To finish our brief survey of text typesetting, we will learn how to make text bold, italic, and underlined. You can paste the following samples into your project and compile to see how the different fonts look.

The command \textit{} italicizes the text within the curly braces. For example,

\textit{This text is italic.}

Similarly, the command \textbf{} makes the text in the curly braces bold. (The "bf" stands for "boldface.")

\textbf{This text is bold.}

Finally, the command \underline{} underlines the text in the curly braces.

\underline{This text is underlined.}

All of these commands require the curly braces to show where your font change begins and ends. Trying to compile without the braces will result in an error message.

\textbf{} makes text bold.

\textit{} makes text italic.

\underline{} makes text underlined.

Exercise 3.1.2

Use LaTeX to typeset the sample text below, replicated all font changes. The sample comes from the textbook Calculus Made Easy by Silvanus Thompson (1914). The book can be accessed for free on Project Gutenberg, both the PDF version and the TeX source code!

You may copy and paste the text into Overleaf, then apply the necessary commands.

On Relative Growings.

All through the calculus we are dealing with quantities that are growing, and with rates of growth. We classify all quantities into two classes: constants and variables. Those which we regard as of fixed value, and call constants, we generally denote algebraically by letters from the beginning of the alphabet, such as a, b, or c; while those which we consider as capable of growing, or (as mathematicians say) of varying, we denote by letters from the end of the alphabet, such as x, y, z, u, v, w, or sometimes t.

Moreover, we are usually dealing with more than one variable at once, and thinking of the way in which one variable depends on the other: for instance, we think of the way in which the height reached by a projectile depends on the time of attaining that height. Or we are asked to consider a rectangle of given area, and to enquire how any increase in the length of it will compel a corresponding decrease in the breadth of it. Or we think of the way in which any variation in the slope of a ladder will cause the height that it reaches, to vary.

Solution 3.1.2

\noindent \underline{On Relative Growings.}


\noindent All through the calculus we are dealing with quantities that are growing, and with rates of growth. We classify all quantities into two classes: \textit{constants} and \textit{variables}. Those which we regard as of fixed value, and call \textit{constants}, we generally denote algebraically by letters from the beginning of the alphabet, such as \textit{a}, \textit{b}, or \textit{c}; while those which we consider as capable of growing, or (as mathematicians say) of \textbf{varying}, we denote by letters from the end of the alphabet, such as \textit{x}, \textit{y}, \textit{z}, \textit{u}, \textit{v}, \textit{w}, or sometimes \textit{t}.


\noindent Moreover, we are usually dealing with more than one variable at once, and thinking of the way in which one variable depends on the other: for instance, we think of the way in which the height reached by a projectile depends on the time of attaining that height. Or we are asked to consider a rectangle of given area, and to enquire how any increase in the length of it will compel a corresponding decrease in the breadth of it. Or we think of the way in which any variation in the slope of a ladder will cause the height that it reaches, to vary.

Some things to pay attention to:

  • Remember to use a blank line (double line break) to start a new paragraph.

  • Remember to use curly braces with every font change command.

  • If you received an "Undefined control sequence" error, check the spelling of the commands you used. This error message means Overleaf didn't recognize a certain command, and can occur if you have a typo in one.

On the next page, we will learn how to deal with special characters in LaTeX.