141 lines
13 KiB
TeX
141 lines
13 KiB
TeX
\chapter{Styling Text in \LaTeX{}}
|
|
|
|
One of the most confusing things in \LaTeX{} for some people is how to format text, especially when you are creating some custom macros that change the appearance of text.
|
|
|
|
There are two key concepts to keep in mind here. The first concept to keep in mind here is that \LaTeX{} has both \textit{commands} and \textit{switch commands} to style text. The second is that ``text'' is not just a collection of characters, but a collection of characters with \textit{distinct groups of characteristics}.
|
|
|
|
\section{Text Characteristics}
|
|
|
|
The history of making marks on paper (or clay, or cave walls, or skin) goes a long way back in human history, so the subject of type and how to talk about it is complex, but interesting. Needless to say, we don't have the space to discuss all of it here, so we'll just look at those things that \LaTeX{} gives us control over. Those characteristics are:
|
|
|
|
\begin{itemize}[noitemsep]
|
|
\item Family
|
|
\item Shape
|
|
\item Series
|
|
\item Size
|
|
\end{itemize}
|
|
|
|
Let's look at each of these in turn. But first, let's clear up a bit of confusion about the terms \textit{font} and \textit{typeface}.
|
|
|
|
\subsection{Typefaces vs. Fonts}
|
|
|
|
For better or for worse, the rise of the Apple Macintosh led to a blurring between the meaning of the words ``typeface'' and ``font''. What most people mean when they say ``font'' and what your GUI-based word-processing program is referring to in its ``Font'' menu is actually a \textit{typeface}, which means a collection of characters styled in a particular way. ``Times New Roman'' is a typeface, ``Verdana'' and ``Arial'' are others.
|
|
|
|
A \textit{font}, on the other hand, actually refers to a collection of characteristics, including shape, series, and size. ``Times New Roman'' is a typeface; ``Times New Roman bold italic 10 point'' is a font. This distinction goes back to the days when typefaces were physical objects made of lead.
|
|
|
|
In actuality, your ``Font'' menu should really be called the ``Typeface'' menu, because you are selecting a typeface, and not a font.\footnote{I am not entirely sure why this menu ended up being called ``Font'' instead of ``Typeface''. It might have to do with saving screen space, or it might have to do with somebody not understanding the difference between the two. Or, knowing the history of the Apple corporation, it might have to do with hubris. I hope to find out some day.} You might use the same typeface throughout a family (and you really should use no more than two or three in a document, unless your intention is to write a ransom note), but if you use bold or italic, or different sizes, those are in reality, different fonts.
|
|
|
|
\subsection{Family}
|
|
|
|
Typefaces fall into a number of different categories, including serif, sans-serif, proportional, and monospace. In \LaTeX{} we refer to those as a ``family''. \LaTeX{} recognizes three families: roman (i.e., serif), sans-serif, and monospace.
|
|
|
|
A serif font has small decorative lines attached to the ends of letters, whereas a sans-serif font does not. This zine is typeset using the \textsf{kpfonts} package, which uses serif fonts that were originally derived from the URW Palladio font\footnote{See \kref{https://fontesk.com/palladio-typeface/}{https://fontesk.com/palladio-typeface/} and \kref{https://ctan.org/tex-archive/fonts/kpfonts}{https://ctan.org/tex-archiv\\e/fonts/kpfonts}.} so all the letters you see here have serifs. When I need a sans-serif font,\footnote{I've made up a change in this issue to start using a sans-serif font for \LaTeX{} package names. If I had known this little project was going to go to six issues, I would have created an in-house style sheet first.} I use the Cantarell font.\footnote{See \kref{https://ctan.org/tex-archive/fonts/cantarell}{https://ctan.org/tex-archive/fonts/cantarell}.} \textsf{This sentence is typeset in a sans-serif font.}
|
|
|
|
Both the Palladio and Cantarell fonts used in this zine are proportional fonts. In a proportional font, each letter takes up a different width. Some letters, such as \textsf{m} and \textsf{w}, are fairly wide, whereas other, such as \textsf{i} and \textsf{l}, are fairly narrow, and most other letters are somewhere in between.
|
|
|
|
In a monospace font (which is also called a fixed width font), each letter takes up the same exact width. The \textsf{kpfonts} package I use for the text in this zine is a proportional font, but the code samples are in a monospace font. \texttt{This sentence is typeset in a monospace font.} Typewriters typically use a monospace font, but as computers became commonly available, a few were produced that could actually type in a proportional font.\footnote{Typewriters are a particular love of mine, and I can go on about them at considerable length. Don't get me started.}
|
|
|
|
You can see this in action if we compare five of the same characters with different widths, first in a proportional font, and then in a monospace font:
|
|
|
|
\begin{itemize}[noitemsep]
|
|
\item[] \texttt{iiiii} iiiii
|
|
\item[] \texttt{nnnnn} nnnnn
|
|
\item[] \texttt{WWWWW} WWWWW
|
|
\end{itemize}
|
|
|
|
You can easily see that the first set of letters in a monospace font all takes up the same amount of space, but the second set in a proportional font takes up widely different amounts of space.\footnote{Again, this is a remarkably difficult concept for some people to understand. Again, see most of chapter \ref{flashcards}.}
|
|
|
|
Interestingly, both proportional and monospace fonts can be either serif or sans-serif. The first three issues of this zine used a sans-serif monospace font for the code samples. I've never particularly cared for most sans-serif fonts, but I learned I could pass the \texttt{[nott]} option to the \textsf{kpfonts} package, which prevents it from modifying the default fixed width fonts.
|
|
|
|
\subsection{Shape}
|
|
|
|
The \textit{shape} of a font refers to how the individual characters are formed.\footnote{This is a terrible definition, but it is what it is. I didn't make the rules here.} Shape can be upright (i.e., ``normal'' or ``roman''), italic, slanted, and/or small caps.\footnote{For the illustrations in this section, I am hugely grateful to the StackExhange user \kref{https://tex.stackexchange.com/users/4918/tobi}{Tobi}, who provided examples at \kref{https://tex.stackexchange.com/a/139592/245702}{https://tex.stackexchange.com/a/139592/245702}.}
|
|
|
|
Both italic and slanted shapes lean to the right. The main difference between the two occurs when you apply this to a serif font. A slanted shape is just that: it's as if you had written out the text on a flexible substrate and then just stretched it a bit so it leans to the right. An italic shape, however, actually has a completely different, somewhat more curvy shape to each character. \textsl{This is slanted text}, and \textit{this is italic text}. Italic or slanted shapes are often used to emphasize a word or group of words (i.e., ``This is \textit{very} good cake.'') but it also used by convention to indicate the titles of books and movies (i.e., \textit{The Grapes of Wrath}, \textit{Star Wars}).
|
|
|
|
Small caps is shorthand for ``small capitals'' and refers to text in which all the lower-case characters are substituted by their upper-case equivalents. \textsc{This text is in small caps.} Small caps is often used to convey prestige and stability.
|
|
|
|
I should also point out that small caps are not the same as using capital letters, and typesetting the first letter of a word in a larger size. (Notice that I said ``upper-case \textit{equivalents}'' above.) Small caps are a separate set of glyphs in which all the characters have the same stroke thickness.
|
|
|
|
\begin{center}
|
|
\frame{\includegraphics[scale=0.3]{smallcaps}}
|
|
\end{center}
|
|
|
|
This is what all these different variations look like in a serif typeface:
|
|
|
|
\ksamp{large}{Normal abc}{-3}{-2}
|
|
|
|
\noindent{}You can see the different between the italic and slanted versions in this sample.
|
|
|
|
And here is what they look like in a sans-serif typeface:
|
|
|
|
\textsf{\ksamp{large}{Normal abc}{-5}{-1}}
|
|
|
|
It's interesting to note that in the Cantarell typeface, the italic and the slanted shapes are pretty much identical, and it also doesn't include a small caps version at all. Some font packages include these, and some do not. As always, you should read the font documentation to see what is included.
|
|
|
|
\subsection{Series}
|
|
|
|
Series is usually known as \textit{weight}, or how bold a particular bit of text is. In theory, you could have a number of different series or weights (and CSS does allow for this) but in reality, most typefaces are available either as \textit{normal} (i.e., not bold) or \textit{bold}. (A few also have a ``light'' option, but this is rare in my experience.)
|
|
|
|
Almost all of the text you read is ``normal'' weight, but \textbf{this bit is in bold} (which is also called ``boldface''). Boldface is sometimes used for emphasis, but it is more typically used to highlight important words or phrases. It is also used a lot in headlines, and you can see that in this zine, where the chapter names, as well as the names of sections and subsections within each chapter, are all printed in bold.
|
|
|
|
\subsection{Size}
|
|
|
|
Size is easy to figure out: it just refers to how large a bit of text appears, either on screen or on paper. In reality, a typeface's size is much more complicated than that. Font sizes are usually measured in \textbf{points}, the size of which has varied over the years. With digital printing, points are usually defined as being \nicefrac{1}{72} of an inch, or exactly $0.352\bar{7}$ millimeters. (I could go on at length about this, but I won't. If you are interested, you might want to read \kref{https://en.wikipedia.org/wiki/Point_(typography)}{https://en.wikipedia.org/wiki/Point\_(typography)}.\footnote{I'm not going to talk about type size here, because it's fairly straightforward in \LaTeX{} and I also mentioned how to get specific font sizes in issue \#4.}
|
|
|
|
\section{Semantic Formatting}
|
|
|
|
``Semantic'' formatting means that your code should \textit{mean} something. It other words, you need to distinguish between when you are emphasizing something (i.e., ``This is \textit{very} good cake.'') or merely when you are marking something as italic or bold as a convention, such as book and movie titles or vocabulary words (i.e., \textit{The Grapes of Wrath}, \textit{Star Wars}, ``\textbf{mitosis} is the process of cell division'', etc.).
|
|
|
|
In \LaTeX{}, the command for emphasizing text is \verb|\emph{<text>}|. This generally gets rendered as italic text, although not always. For example, the \textsf{beamer} document class renders it as red text, rather than italic text, as this work better in most presentations. (check this)
|
|
|
|
\section{Commands and Environments}
|
|
|
|
\LaTeX{} has both modal commands that change \textit{all} the text following that command, and environments that change the text only within that environment.
|
|
|
|
\paragraph{Notes:} Most document classes (but not all) use a roman (that is, a serif) font by default; to set entire passages in a different shape, use one of the three shape \texttt{<XXfamily>} switch commands. \verb|\textrm{<text>}| can be used to return to a roman font in an extended passage of either sans-serif or monospace text, for example.
|
|
|
|
Likewise, \verb|\upshape| can be used to return a regular shape in an extended passage of italic, slanted, or small caps text. Similarly, to return to a regular shape in a shorter passage of italic, slanted, or small caps text, you can use \verb|\textup{<text>}|.
|
|
|
|
\verb|\textmd{<text>}| can be used in the middle of a long passage of bold faced text to omit a word or two from being bold.
|
|
|
|
The commands and environments are summarized in the following table. It's a lot easier to remember them when you know what characteristic (family, shape, series) you are targeting, and what the two-letter code (\texttt{rm}, \texttt{bf}, etc.) stands for.
|
|
|
|
\newpage
|
|
|
|
\begin{longtblr}
|
|
[
|
|
caption = {Summary of Text Formatting in \LaTeX{} },
|
|
label = {tb:},
|
|
% theme = {custom1}
|
|
]{
|
|
width = {\textwidth},
|
|
colspec = { X[0.2,c] X[1,l] X[2,c] X[2,c] },
|
|
hlines = {0.5pt,solid},
|
|
vline{1,5} = {0.5pt,solid},
|
|
vline{2} = {2-10}{0.5pt,solid},
|
|
rows = {5mm, m, rowsep=3pt},
|
|
rowhead = 1,
|
|
cells = {font=\sffamily\fontsize{8pt}{10pt}\selectfont},
|
|
row{1} = {font=\bfseries},
|
|
verb,
|
|
cell{2}{1} = {r=3}{c},
|
|
cell{5}{1} = {r=4}{c},
|
|
cell{9}{1} = {r=2}{c},
|
|
cell{11}{1}= {c=2}{l},
|
|
}
|
|
& Characteristic & Switch Command & Command \\
|
|
\rotatebox[origin=c]{90}{Family} & Roman* & \verb|\rmfamily| & \verb|\textrm{<text>}| \\
|
|
& Sans-Serif & \verb|\sffamily| & \verb|\textsf{<text>}| \\
|
|
& Monospace & \verb|\ttfamily| & \verb|\texttt{<text>}| \\
|
|
\rotatebox[origin=c]{90}{Shape} & Upright* & \verb|\upshape| & \verb|\textup{<text>}| \\
|
|
& Italic & \verb|\itshape| & \verb|\textit{<text>}| \\
|
|
& Slanted & \verb|\slshape| & \verb|\textsl{<text>}| \\
|
|
& Small Caps & \verb|\scshape| & \verb|\textsc{<text>}| \\
|
|
\rotatebox[origin=c]{90}{Series} & Medium* & \verb|\mdseries| & \verb|\textmd{<text>}| \\
|
|
& Boldface & \verb|\bfseries| & \verb|\textbf{<text>}| \\
|
|
{Return to the default \\style for the \\document class} & & \verb|\normalfont| & \verb|\textnormal{<text>}| \\
|
|
\end{longtblr}
|
|
|
|
\paragraph{Note:}An asterisk (*) indicates the typical default for most document classes.
|