In this lesson we describe:

• how to use different fonts,
• how to prepare monospaced text,
• how to change the colour, size, and justification of text, and
• how to change headers, footers, and use footnotes.

Fonts

Occasionally you may want some different ways to make part of your text stand out. The commands \textsf{}, \texttt{}, \textsl{} and \textsc{} can be used to make your text

This was generated by:

\textsf{Sans-serif} \texttt{Teletype} \textsl{Slanted} \emph{(vs Emphasized)} \textsc{Small Caps}

Verbatim Monospaced Text and URLs

You may have noticed that \texttt (tt stands for teletype) produces a monospaced font, like a computer terminal would. However, if you want to produce a long chunk of monospaced text, you should use the \verb and \begin{verbatim} commands. These have additional benefits like preserving whitespace and handling escape characters correctly.  \verb is for doing a short chunk of monospaced text in line with the surrounding text, while the verbatim environment begins a new line, and can handle multi-line inputs.

Using \verb is a little different from any commands we’ve seen before because it takes user-defined delimiters surrounding the text, instead of curly brackets. Let’s say that we’re using the | symbol as our delimiter. Then we would write

Here's \verb|monospaced verbatim text \%#{} (&   space!)| in a sentence.

which would give:

If you’d wanted to use a | character as part of the monospaced text, you would have to use another delimiter character such as + or ". The delimiter can be pretty much any character, as long as you remember to use the exact same delimiter at the start and the end.

For multi-line text, use

\begin{verbatim}
multi-line
verbatim text
\end{verbatim}

to get

When you use either of these commands, you don’t need to escape special characters: for example \ inside of verb or verbatim will give you the \ sign.

Exercise (nickname: verbatim)

Typeset the following chunk of text:

Note: As a visual aid, text appearing in the default font has been coloured purple, while monospaced text has been left in black. You do not need to colour your text.

URLs

URLs should be typeset in yet one more special way. If you use the hyperref package, then   \url{http://internet.com/web_page} will typeset the URL in a monospaced font, respecting special characters, and even producing a clickable link in your PDF document. The hyperref package will also let you create links to pieces of the same document; we’ll explain more when we talk about the \label and \ref commands.

Fonts in Math

If you include the amsfonts package, then you will be able to use three additional fonts that are particularly useful in math mode: \mathfrak, \mathbb, and \mathcal.

Exercise (nickname: mathfonts)

Typeset the following, by using the three fonts mentioned above:

The symbol for the permutation group is an S (short for symmetric), even though it looks like a G.

After you’ve completed the exercise above, you may want to make a note of the name of the font which gave you the $$\mathbb{Z}$$ symbol representing the set of integers. This same font also lets you write

• $$\mathbb{N}$$, the set of natural numbers
• $$\mathbb{Q}$$, the set of rational numbers
• $$\mathbb{R}$$, the set of real numbers
• $$\mathbb{C}$$, the set of complex numbers

Changing the Whole Document’s Font

While the default font in LaTeX is quite lovely and has an esteemed pedigree, you may decide that you want to go with something else. What we do not recommend is using \textsf over and over again throughout the whole document. Instead, use a technique that changes the whole document with just a single command.

LaTeX makes a big distinction between serif (or roman) fonts and sans-serif fonts. (Serifs are the little tails on the end of these letters, and this part of the sentence is in a sans-serif font; this other part of the sentence is in your browser’s default serif font.) For this reason, loading most serif fonts requires just a single command in the preamble,

\usepackage{bookman}

while switching to a sans-serif font requires two commands in the preamble:

\usepackage{helvet}                       % load new sans-serif font
\renewcommand{\familydefault}{\sfdefault} % set all text in sans-serif

If you switch the default family to sans-serif, use \textrm{} to set a portion of text with serifs.

Text Effects and Page Layout

Footnotes

Use \footnote{«your text here»} to insert a footnote in the text. You can also customize the symbol and other aspects of its appearance.

Color

To add a splash of color to your text, we recommend loading the xcolor package in the preamble,

\usepackage{xcolor}

Then you can set a portion of text in color using the \textcolor{}{} command:

\textcolor{red}{This is red text} and this is not.

Here red can be replaced with black, blue, brown, cyan, darkgray, gray, green, lightgray, lime, magenta, olive, orange, pink, purple, red, teal, violet, white, or yellow. For even more options and custom colors you should read the documentation for the xcolor package.

Text Size

If, like we have done so far, you are using the article document class, then you have some control over the font size for the whole document. By default it is 10 point but you can change it to 11 or 12 point using the option

\documentclass[11pt]{article}

Here, the square brackets are used only because they are an optional argument. If you really need another size than these three, read this tex.stackexhange post.

Changing the font size of the whole document to an arbitrary value requires packages that we won’t get in to here. However, you can easily change the size of a chunk of text using one of the commands \tiny, \scriptsize, \footnotesize, \small, \normalsize, \large, \Large, \LARGE, \huge, or \Huge. Beware, however, that these commands are used with braces in a slightly different way, for example:

{\Huge Here is some huge text} and some normal text.

Doing \Huge{A} B would erroneously cause B to be huge.

Text Alignment and  \noindent

Use \begin{center}«your text here»\end{center} in order to create centered text. Likewise, use \begin{flushleft} or \begin{flushright} (and the corresponding end) to get left or right alignment without indentation. To get rid of the indentation on a particular paragraph, you can alternatively begin it with the \noindent command.

If you want to combine multiple types of alignment on the same line, it’s likely that your goal can best be achieved using tables, which we’ll describe later.

Page Numbers, New Pages, Headers and Footers

By default, LaTeX will show the page number at the bottom of every page, and to change this you need to use the header/footer commands.

The simplest such command is \pagestyle: use this either in the preamble or in your document, to effect a permanent change on the headers and footers.

• \pagestyle{plain}, the default, has a blank header and a centred page number footer
• \pagestyle{empty} gives a blank header and blank footer
• \pagestyle{headings} gives an automatically-generated header and blank footer
• You can get custom versions with \pagestyle{myheadings} or the \fancyhdr package; see more information here.

Sometimes you want to control just a single page, especially the title page. The command  \thispagestyle{«style»} affects just the current page.

Tip: \maketitle and some other commands automatically set the current page style to plain. Use \thispagestyle right after the command to override it. For example to have no number on the page with the title, write

\maketitle \thispagestyle{empty}

\clearpage

To end the current page and force a new one to start, use \clearpage.

Appendix

An appendix is an optional collection of auxiliary data at the end of your document. There are two steps to creating an appendix in LaTeX:

1. Call the \appendix command in your text, where you want the appendices to start.
2. Thereafter, use the \section{} command to create a new appendix. The style will have changed from Section 1, Section 2, … to A, B, … etc.

Exercise (nickname: bodyparts)

Use a footnote and an appendix in your document (put whatever content you like in both of them). Naturally, the appendix will have to appear at the end of the document, rather than collected with the other exercises from this lesson.
These are course notes for the University of Waterloo's course Math 600: Mathematical Software.
© 2012—. Written and developed by David Pritchard and Stephen Tosh. Contact (goes to the CEMC)