Chapter 3 – Adjusting Fonts

Here are the Code examples of this chapter. You can compile them online right on this web page by pressing the Typeset / Compile button. You can also edit them for testing and compile them again.

The code pages here are partially based on the First Edition of the book and are currently being edited to match the code of the Second Edition with all the additional examples. It is not complete yet since the focus was on the book production until weeks ago; please visit again soon!

Choosing a document font

Latin Modern:

\documentclass[paper=a4,oneside,fontsize=11pt,
  parskip=full]{scrartcl}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\begin{document}
\tableofcontents
\addsec{Introduction}
This document will be our starting point for simple
documents. It is suitable for a single page or up to
a couple of dozen pages.

The text will be divided into sections.
\section{The first section}
This first text will contain
\begin{itemize}
\item a table of contents,
\item a bullet list,
\item headings and some text and math in section,
\item referencing such as to section \ref{sec:maths} and
      equation (\ref{eq:integral}).
\end{itemize}
We can use this document as a template for filling in
our own content.
\section{Some maths}
\label{sec:maths}
When we write a scientific or technical document, we usually
include math formulas. To get a brief glimpse of the look of
maths, we will look at an integral approximation of a function
$f(x)$ as a sum with weights $w_i$:
\begin{equation}
  \label{eq:integral}
  \int_a^b f(x)\,\mathrm{d}x \approx (b-a)
  \sum_{i=0}^n w_i f(x_i)
\end{equation}
\end{document}

Kepler fonts:

\documentclass[paper=a4,oneside,fontsize=11pt,
  parskip=full]{scrartcl}
\usepackage[T1]{fontenc}
\usepackage{kpfonts}
\begin{document}
\tableofcontents
\addsec{Introduction}
This document will be our starting point for simple
documents. It is suitable for a single page or up to
a couple of dozen pages.

The text will be divided into sections.
\section{The first section}
This first text will contain
\begin{itemize}
\item a table of contents,
\item a bullet list,
\item headings and some text and math in section,
\item referencing such as to section \ref{sec:maths} and
      equation (\ref{eq:integral}).
\end{itemize}
We can use this document as a template for filling in
our own content.
\section{Some maths}
\label{sec:maths}
When we write a scientific or technical document, we usually
include math formulas. To get a brief glimpse of the look of
maths, we will look at an integral approximation of a function
$f(x)$ as a sum with weights $w_i$:
\begin{equation}
  \label{eq:integral}
  \int_a^b f(x)\,\mathrm{d}x \approx (b-a)
  \sum_{i=0}^n w_i f(x_i)
\end{equation}
\end{document}

Libertine with nextxmath font and Inconsolata typewriter font:

\documentclass[paper=a4,oneside,fontsize=11pt,
  parskip=full]{scrartcl}
\usepackage[T1]{fontenc}
\usepackage{libertine}
\usepackage[libertine,cmintegrals,cmbraces,vvarbb]{newtxmath}
\usepackage[scaled=0.95]{inconsolata}
\begin{document}
\tableofcontents
\addsec{Introduction}
This document will be our starting point for simple
documents. It is suitable for a single page or up to
a couple of dozen pages.

The text will be divided into sections.
\section{The first section}
This first text will contain
\begin{itemize}
\item a table of contents,
\item a bullet list,
\item headings and some text and math in section,
\item referencing such as to section \ref{sec:maths} and
      equation (\ref{eq:integral}).
\end{itemize}
We can use this document as a template for filling in
our own content.
\section{Some maths}
\label{sec:maths}
When we write a scientific or technical document, we usually
include math formulas. To get a brief glimpse of the look of
maths, we will look at an integral approximation of a function
$f(x)$ as a sum with weights $w_i$:
\begin{equation}
  \label{eq:integral}
  \int_a^b f(x)\,\mathrm{d}x \approx (b-a)
  \sum_{i=0}^n w_i f(x_i)
\end{equation}
\end{document}

The Mathpazo font with Euler virtual math and Bera for a typewriter style:

\documentclass[paper=a4,oneside,fontsize=11pt,
  parskip=full]{scrartcl}
\usepackage[sc,osf]{mathpazo}
\usepackage[T1,small,euler-digits]{eulervm}
\usepackage[scaled=0.86]{berasans}
\usepackage[scaled=0.84]{beramono}
\begin{document}
\tableofcontents
\addsec{Introduction}
This document will be our starting point for simple
documents. It is suitable for a single page or up to
a couple of dozen pages.

The text will be divided into sections.
\section{The first section}
This first text will contain
\begin{itemize}
\item a table of contents,
\item a bullet list,
\item headings and some text and math in section,
\item referencing such as to section \ref{sec:maths} and
      equation (\ref{eq:integral}).
\end{itemize}
We can use this document as a template for filling in
our own content.
\section{Some maths}
\label{sec:maths}
When we write a scientific or technical document, we usually
include math formulas. To get a brief glimpse of the look of
maths, we will look at an integral approximation of a function
$f(x)$ as a sum with weights $w_i$:
\begin{equation}
  \label{eq:integral}
  \int_a^b f(x)\,\mathrm{d}x \approx (b-a)
  \sum_{i=0}^n w_i f(x_i)
\end{equation}
\end{document}

Zapf Chancery:

\documentclass{article}
\newcommand{\zapf}{\fontfamily{pzc}\selectfont}
\newenvironment{zapfenv}{\fontfamily{pzc}\selectfont}{}
\begin{document}
Normal text

{\zapf Zapf Chancery\par}

Normal text

\begin{zapfenv}
Zapf Chancery
\end{zapfenv}

Normal text
\end{document}

Font change:

\documentclass{article}
\newcommand{\setfont}[1]{\fontfamily{#1}\selectfont}
\newenvironment{fontenv}[1]{\fontfamily{#1}\selectfont}{}
\begin{document}
Normal text

{\setfont{pzc} Zapf Chancery\par}

Normal text

\begin{fontenv}{pzc}
Zapf Chancery
\end{fontenv}

Normal text
\end{document}

\documentclass{scrbook}
\newcommand{\zapf}{\fontfamily{pzc}\selectfont}
\setkomafont{chapter}{\normalcolor\zapf\Huge}
\begin{document}
\chapter{The Heading}
Normal text
\end{document}

Printing a font table:

\documentclass[a4paper]{article}
\usepackage{fonttable}
\usepackage[margin=4.5cm]{geometry}
\pagestyle{empty}
\begin{document}
\fonttable{pzdr}
\end{document}

Extended font table:

\documentclass[a4paper]{article}
\usepackage{fonttable}
\usepackage[margin=4.5cm]{geometry}
\pagestyle{empty}
\begin{document}
\xfonttable{T1}{pzc}{m}{it}
\end{document}

Printing a font sample:

\documentclass[a4paper]{article}
\usepackage{fonttable}
\usepackage[margin=4.5cm]{geometry}
\pagestyle{empty}
\begin{document}
\fonttext{pzcmi7t}
\end{document}

Importing just a single symbol of a font:

\documentclass[border=10pt]{standalone}
\DeclareFontFamily{U}{matha}{\hyphenchar\font45}
\DeclareFontShape{U}{matha}{m}{n}{
      <5> <6> <7> <8> <9> <10> gen * matha
      <10.95> matha10 <12> <14.4> <17.28> <20.74> <24.88> matha12
      }{}
\DeclareSymbolFont{matha}{U}{matha}{m}{n}
\DeclareMathSymbol{\leq}{3}{matha}{"A4}
\DeclareMathSymbol{\nleq}{3}{matha}{"A6}
\begin{document}
If $A \leq B$, then $B \nleq A$.
\end{document}

Writing bold mathematical symbols:

\documentclass{article}
\usepackage{bm}
\bmdefine{\bX}{X}
\bmdefine{\bi}{i}
\bmdefine{\bMinus}{-}
\bmdefine{\bSum}{\sum}
\bmdefine{\bLeft}{(}
\bmdefine{\bRight}{)}
\pagestyle{empty}
\begin{document}
\[ \sum_{i} ( - X_{i} ) \]
\[ \bSum_{\bi} \bLeft \bMinus \bX_{\bi} \bRight \]
\end{document}

\documentclass{article}
\usepackage{amsmath}
\newcommand{\bX}{\boldsymbol{X}}
\newcommand{\bi}{\boldsymbol{i}}
\newcommand{\bMinus}{\boldsymbol{-}}
\newcommand{\bSum}{\boldsymbol{\sum}}
\newcommand{\bLeft}{\boldsymbol{(}}
\newcommand{\bRight}{\boldsymbol{)}}
\pagestyle{empty}
\begin{document}
\[ \sum_{i} ( - X_{i} ) \]
\[ \bSum_{\bi} \bLeft \bMinus \bX_{\bi} \bRight \]
\end{document}

Getting sans-serif mathematics:

\documentclass{article}
\usepackage{sfmath}
\usepackage{sansmathaccent}
\pagestyle{empty}
\begin{document}
\[
  \int_a^b f(x)\,\mathrm{d}x \approx (b-a)
  \sum_{i=0}^n w_i f(x_i)
\]
\end{document}

\documentclass{article}
\usepackage{sansmath}
\sansmath
\pagestyle{empty}
\begin{document}
\[
  \int_a^b f(x)\,\mathrm{d}x \approx (b-a)
  \sum_{i=0}^n w_i f(x_i)
\]
\end{document}

With the arev package:

\documentclass{article}
\usepackage{arev}
\pagestyle{empty}
\begin{document}
\[
  \int_a^b f(x)\,\mathrm{d}x \approx (b-a)
  \sum_{i=0}^n w_i f(x_i)
\]
\end{document}

With Kepler fonts:

\documentclass{article}
\usepackage[sfmath,lighttext]{kpfonts}
\pagestyle{empty}
\begin{document}
\[
  \int_a^b f(x)\,\mathrm{d}x \approx (b-a)
  \sum_{i=0}^n w_i f(x_i)
\]
\end{document}

Double-stroke letters:

\documentclass{article}
\usepackage{dsfont}
\begin{document}
\pagestyle{empty}
\[
  \mathds{N} \subset \mathds{Z} \subset
  \mathds{Q} \subset \mathds{R} \subset \mathds{C}
\]
\end{document}

Enabling the searching and copying of ligatures:

\documentclass{article}
\input{glyphtounicode}
\pdfgentounicode=1
\begin{document}
floating figures
\end{document}

Suppressing ligatures:

\documentclass{article}
\usepackage{microtype}
\DisableLigatures[f]{encoding = *, family = * }
\begin{document}
floating figures
\end{document}

Adding a contour:

\documentclass{scrbook}
\usepackage[pdftex,outline]{contour}
\contourlength{1.5pt}% Thickness of copies
\contournumber{25}% How many copies
\newcommand{\chapterfont}[1]{\contour{black}{\textcolor{yellow}{#1}}}
\setkomafont{chapter}{\Huge\protect\chapterfont}
\begin{document}
\chapter{Introduction}
\thispagestyle{empty}
Text follows.
\end{document}

Go to next chapter.