Reader small image

You're reading from  LaTeX Beginner's Guide - Second Edition

Product typeBook
Published inOct 2021
PublisherPackt
ISBN-139781801078658
Edition2nd Edition
Tools
Right arrow
Author (1)
Stefan Kottwitz
Stefan Kottwitz
author image
Stefan Kottwitz

Stefan Kottwitz studied mathematics in Jena and Hamburg. He works as a network and IT security engineer both for Lufthansa Industry Solutions and for Eurowings Aviation. For many years, he has been providing LaTeX support on online forums. He maintains the web forums LaTeX and goLaTeX and the Q&A sites TeXwelt and TeXnique. He runs the TeX graphics gallery sites TeXample, TikZ, and PGFplots, the TeXlive online compiler, the TeXdoc service, and the CTAN software mirror. He is a moderator of the TeX Stack Exchange site and matheplanet. He publishes ideas and news from the TeX world on his blogs LaTeX and TeX. Before this book, he authored the first edition of LaTeX Beginner's Guide in 2011, and LaTeX Cookbook in 2015, both published by Packt.
Read more about Stefan Kottwitz

Right arrow

Chapter 10: Using Fonts

The text's base font determines the appearance of your text significantly. You may choose a font that's especially clear and readable for a long piece of writing or a fancy calligraphic font for a greeting card. Your job application letter might use a very clear and serious font, whereas a mathematical article requires fonts with a lot of symbols and a text font that fits well with them.

Until now, we have been covering the logical properties of fonts. Although we have always used the LaTeX standard font, we switched, for instance, from roman to sans-serif, or typewriter, and learned how to make text bold, italicized, or slanted in Chapter 2, Formatting Text and Creating Macros. However, we never deviated from the standard set of fonts.

In this chapter, we will cover the following topics:

  • Using comprehensive font bundles
  • Using specific font families
  • Using arbitrary fonts

While we will inspect the text appearance, we will...

Technical requirements

You can use a local LaTeX installation, or you can compile the example code online at https://latexguide.org/chapter-10.

The code is available on GitHub: https://github.com/PacktPublishing/LaTeX-Beginner-s-Guide-2nd-Edition-/tree/main/Chapter_10_-_Using_Fonts.

In this chapter, we will use the following packages: arev, beramono, bookman, calligra, charter, cmbright, concmath, concrete, courier, fontenc, fouriernc, helvet, inconsolata, kerkis, kmath, kpfonts, kurier, lmodern, mathdesign, miama, newcent, newpx, newpxmath, newtx, newtxmath, sfmath, and unicode-math.

In addition, we will briefly discuss these packages: cm-super, inputenc, and sansmath.

You can find other and advanced code examples in the LaTeX Cookbook, Chapter 3, Adjusting Fonts, with compilable code at the book's website: https://latex-cookbook.net/chapter-3.

Using comprehensive font bundles

We start with the most extensive font bundles. To test fonts, we may use a pangram. This word has a Greek origin: pan gramma means every letter. It stands for a sentence that uses every letter of the alphabet. Thus, a pangram is very convenient for displaying fonts.

We will print out a very famous pangram phrase using the Latin Modern font family. Latin Modern is very similar to the default LaTeX font called Computer Modern. However, Latin Modern contains a lot of additional characters, most of them being accented characters. Because of this advantage and its very high quality, we can consider it as the successor to the standard font. Let's see how it looks in various font families and shapes, and with a math formula:

  1. Start a new document:
    \documentclass{article}
  2. Create a macro for the pangram with additional numerals. It will have one argument, which will be our font family or shape selection command. We will add a paragraph break...

Using specific font families

We will explore many more TeX fonts that are special in their own way. We will use our \pangram macro from the previous section with the corresponding family command for testing.

Serif fonts

A small line or stroke attached to a larger stroke in a letter or symbol is called a serif. A font regularly using such serifs is called a serif font, or a serif typeface.

The default serif font is called Computer Modern Roman. Latin Modern provides a very similar font, and you already know the Kp-Fonts serif font. Other packages specialize in serif fonts, and we will now look at some of them.

Times Roman

The newtx package defines a Times text font and a matching math font.

It's split into two parts, so they can be used independently, such as when you would like to have a different math font. That's why we load it in this way:

\usepackage{newtxtext}
\usepackage{newtxmath}

With \pangram{\rmfamily} and our math formula, we get the following...

Using arbitrary fonts

Arbitrary is a bit broadly worded, but the meaning is valid as today, we can choose among many thousands of fonts that were not even prepared for LaTeX. That may be operating system fonts, TrueType fonts, or modern OpenType fonts.

Let's use some fonts that are available on a Microsoft Windows 10 computer.

Selecting the main font

We can either open Settings / Fonts via the Windows start menu or look into the folder C:\Windows\Fonts to see the installed fonts. The Segoe UI font appears available with several names, so let's choose Segoe UI Semilight. We will see whether it's hard to use:

  1. Start a new document:
    \documentclass{article}
  2. Load the fontspec package because it provides us with font selection commands:
    \usepackage{fontspec}
  3. Choose the main font:
    \setmainfont{Segoe UI Semilight}
  4. Write the document body with some large text:
    \begin{document}
    \large
    The quick brown fox jumps over the lazy dog. 1234567890
    \end{document...

Summary

Now we can use different text and math fonts. Our documents no longer need to look like simple default font LaTeX articles or books.

We learned about installing and choosing font sets and specific fonts and made a survey of good font packages. For some advanced font tasks with ready-to-use examples, you can take a look at Chapter 3, Adjusting Fonts, in the LaTeX Cookbook.

Now, let's go back from fonts to LaTeX, and we will learn how to develop and manage larger documents in the next chapter.

lock icon
The rest of the chapter is locked
You have been reading a chapter from
LaTeX Beginner's Guide - Second Edition
Published in: Oct 2021Publisher: PacktISBN-13: 9781801078658
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Author (1)

author image
Stefan Kottwitz

Stefan Kottwitz studied mathematics in Jena and Hamburg. He works as a network and IT security engineer both for Lufthansa Industry Solutions and for Eurowings Aviation. For many years, he has been providing LaTeX support on online forums. He maintains the web forums LaTeX and goLaTeX and the Q&A sites TeXwelt and TeXnique. He runs the TeX graphics gallery sites TeXample, TikZ, and PGFplots, the TeXlive online compiler, the TeXdoc service, and the CTAN software mirror. He is a moderator of the TeX Stack Exchange site and matheplanet. He publishes ideas and news from the TeX world on his blogs LaTeX and TeX. Before this book, he authored the first edition of LaTeX Beginner's Guide in 2011, and LaTeX Cookbook in 2015, both published by Packt.
Read more about Stefan Kottwitz