4.5.1 Changing the Font Style

There are two basic ways of changing fonts: you can either change the font for a small selection of text, for example, if you want to emphasize a word, or you may wish to change the font “from this point onwards”. The commands shown in Table 4.5 are of the first type (text-block commands), whereas those shown in Table 4.6 are of the second type—a declaration (or modal command).

Note:

Don't be tempted to use \bf, \md, \it, \sl, \sc, \sf, \tt or \rm. These commands are obsolete [15].[What's wrong with \bf, \it etc.?]

If you use an italic or slanted font declaration, such as \itshape, you will need to add an italic correction \/ at the end of the block of text, when the last letter of the sloping text leans too far over. This isn't necessary for text-block commands, such as \textit, just for the modal commands. The effect is more noticeable when part of a word is stressed, particularly with certain fonts.

Example:

In the code below, the first instance of “repeated” doesn't have an italic correction but the second does:

{\itshape repeated}ly {\itshape repeated\/}ly

Using Computer Modern:

Using Helvetica:

Using Antykwa Toruńska typeface:

 Example Input Corresponding output Command (Computer Modern) \textrm{} \textrm{roman} text \textsf{} \textsf{sans serif} text \texttt{} \texttt{typewriter} text \textmd{} \textmd{medium} text \textbf{} \textbf{bold} text \textup{} \textup{upright} text \textit{} \textit{italic} text \textsl{} \textsl{slanted} text \textsc{} \textsc{Small Caps} text \emph{} \emph{emphasized} text \textnormal{} \textnormal{default} text

Note that if you want to typeset an URL, rather than using \texttt it is better to use

\url{<address>}

which is defined in the url package. For example:

\url{http://theoval.cmp.uea.ac.uk/~nlct/}

produces:

(Note there is no need to do anything with the ~ (tilde) special character if you use it in the argument of \url.)

 Example Input Corresponding output Declaration (Computer Modern) \rmfamily \rmfamily roman text \sffamily \sffamily sans serif text \ttfamily \ttfamily typewriter text \mdseries \mdseries medium text \bfseries \bfseries bold text \upshape \upshape upright text \itshape \itshape italic text \slshape \slshape slanted text \scshape \scshape Small Caps text \em \em emphasized text \normalfont \normalfont default text

Environments can be used instead. Each environment has the same name as its corresponding declaration, but without the preceding backslash. For example:

\begin{sffamily}Some sans-serif text.\end{sffamily}

yields:

You can combine a font family with a given shape and weight using a variety of methods.

Examples:

1. Localised declarations:

2. Declarations that later get explicitly reset:

3. Mixing text-block and modal commands:

\textsf{\slshape Some slanted sans-serif text.}

4. Nested commands:

5. Mixing environments and declarations:

\begin{sffamily}\slshape Some slanted sans-serif text.\end{sffamily}

All of the above produce the same output:

[Warning: “Font shape ... not available”]Note that some combinations are not available, in which case LaTeX will give a warning message, and will substitute the font for what it considers to be the closest available match.

Example:

With the Antykwa Toruńska typeface, this appears as:

whereas with Computer Modern, the result is:

This is because Computer Modern doesn't have a bold small-caps font, so it just uses bold. LaTeX gives the following warning:
LaTeX Font Warning: Font shape T1/cmr/b/sc' undefined
(Font)              using T1/cmr/b/n' instead on input line 2792.

Most sans-serif fonts don't provide a small-caps variant, so

will either appear in regular sans-serif or small-caps serif, depending on the font in use. Using Libris sans-serif the result is:

whereas using Computer Modern Sans, the result is:

4.5.1.1 Emphasizing Words or Phrases

The command \emph, the declaration \em and the environment em behave slightly differently to the corresponding \textit command, \itshape declaration and itshape environment. The latter group simply use an italic font, whereas the former will toggle between sloping and upright. So if the surrounding font is upright then \emph, \em and em will use the sloping font, but if the surrounding font is italic or slanted, \emph, \em and em will use an upright font. This is particularly useful in abstracts where the abstract font varies between class files. It is recommended that if your intention is to emphasize something, you should use \emph etc. rather than \textit etc.

Examples:

1. Emphasized text in upright surrounding:

Some \emph{emphasized} text.

yields

2. Emphasized text in italic surrounding:

yields

3. Emphasized text in upright sans-serif surrounding:

yields

This book is also available as A4 PDF or 12.8cm x 9.6cm PDF or paperback (ISBN 978-1-909440-00-5).

© 2012 Dickimaw Books. "Dickimaw", "Dickimaw Books" and the Dickimaw parrot logo are trademarks. The Dickimaw parrot was painted by Magdalene Pritchett.