# How do I use a particular font for a small section of text in my document?

The standard font packages make global changes to the fonts in my document. What if I want to use a particular font for just a portion of my text?

1. How do I find the right name of the font?
2. How do I select the font?
3. How do I restrict the scope of the font change?

-
Fonts are such a pain in latex. But god they look good. –  Nicholas Hamilton Dec 10 '12 at 14:46
For short inline sections of font change, also discussed here: tex.stackexchange.com/questions/100575/… –  Steven B. Segletes Mar 2 '13 at 16:44
@Alan I think we can remove the “small section” part of this question since it covers all application scopes? –  doncherry Apr 21 '13 at 17:00
@doncherry I think the intended scope of the question is about non-global font changes. –  Alan Munn Apr 21 '13 at 17:01
@AlanMunn I agree, but the scope of this question could easily be widened to include local and global changes, making it more canonical? Having a separate question for global changes seems like a waste of resources. The XeLaTeX answer is ready already, the pdfLaTeX and ConTeXt answers might need a bit of tweaking. –  doncherry Apr 21 '13 at 17:07

# Regular LaTeX

## Finding the font name

This is actually the hardest part. When you load a regular font package like helvet (which sets the default sans serif font to a Helvetica clone) it issues commands to set up the font using an internal name, which is hidden to regular users. These names traditionally use a system of three or four letter lower case names for each font family. Usually these names are documented in documentation associated with the font.

Here is a list of the most common fonts, and their codes:

Family                 Font Name
pag                    Avant Garde
fvs                    Bitstream Vera Sans
pbk                    Bookman
bch                    Charter
ccr                    Computer Concrete
cmr                    Computer Modern
pcr                    Courier
mdugm                  Garamond
phv                    Helvetica
fi4                    Inconsolata
lmr                    Latin Modern
lmss                   Latin Modern Sans
lmtt                   Latin Modern Typewriter
LinuxBiolinumT-OsF     Linux Biolinum (formerly 'fxb' in older package versions)
LinuxLibertineT-OsF    Linux Libertine (formerly 'fxl' in older package versions)
pnc                    New Century Schoolbook
ppl                    Palatino
ptm                    Times
uncl                   Uncial
put                    Utopia
pzc                    Zapf Chancery


(Based on this post in the PhilTeX forums.)

If you don't find any documentation for the font, as a last resort (or a first resort once you know what you're doing) you can open the .sty file that actually loads the font and see for yourself what the internal font family name is (or you could search inside it with grep). Here are two examples:

From helvet.sty: the at the end of the package is the line

\renewcommand{\sfdefault}{phv}


This sets the default sans font (\sfdefault) to the phv family, so phv is the internal name of the font.

From PTSansCaption.sty

\renewcommand{\sfdefault}{PTSansCaption-TLF}


Here the internal name is closer to its actual name: PTSansCaption-TLF.

Both of these examples have shown the code for changing the sans serif font. If the font package changes the roman or mono font you would look for the following commands respectively

\renewcommand{\rmdefault}{...}
\renewcommand{\ttdefault}{...}


## Selecting the font

To select a font, you use the following commands:

\fontfamily{<familyname>}\selectfont


It's often useful to wrap this in a macro:

\newcommand*{\myfont}{\fontfamily{<familyname>}\selectfont}


## Restricting the scope of the selection

You can always restrict the scope of font changing commands by enclosing the text in braces:

{\fontfamily{<familyname>}\selectfont ...}


or if using a command

{\myfont ...}


or, to make the scope of the command more visible in your file if you don't have a brace-matching editor

\begingroup
\myfont ...
\endgroup


If this is something you will be doing a lot, it would make more sense to turn it into a proper environment:

\newenvironment{myfont}{\fontfamily{<familyname>}\selectfont}{\par}


Then you use it like any other environment:

\begin{myfont}
Some text in the new font.
\end{myfont}


You can also define a command corresponding to the standard font changing commands such as \textrm or \textsf, but using your particular font:

\DeclareTextFontCommand{\textmyfont}{\myfont}


Use this like the standard commands:

Text in the default font. \textmyfont{Text in the new font.} Again text in the default font.


An advantage of this command over the simpler version described above is automatic italic correction, cf. Why use \DeclareTextFontCommand vs. just \newcommand?.

-
Wow, huge thanks to whoever took my meagre beginning of an answer and made it 100 times better. –  frabjous Aug 8 '11 at 22:52
Good question. Excellent answer! –  DJP Aug 9 '11 at 3:59
I have no idea why PhilTeX forums disappeared and hence many related urls in answers based on them are broken . –  texenthusiast Aug 13 '13 at 17:10

## XeLaTeX and LuaLaTeX

The appearance of XeLaTeX and LuaLaTeX has simplified font selection greatly for LaTeX users, since any font installed on your system can be used with these engines using the fontspec package to load the font.

Both XeLaTeX and LuaLaTeX assume by default UTF-8 input, so you should not load the inputenc package when using them, and you should save your source files as UTF-8.

A basic document will therefore look like the following:

\documentclass{article}
\usepackage{fontspec}
\begin{document}
...
\end{document}


Selecting fonts globally

For a whole document, you can set the roman font, the sans serif font and the monospace font with the following commands:

\setmainfont[<font features>]{<name of font>} % sets the roman font
\setsansfont[<font features>]{<name of font>} % sets the sans font
\setmonofont[<font features>]{<name of font>} % sets the monospace font


Selecting fonts locally

If you want to use a font for a small section of your document it's best to define a new font family.

\newfontfamily\myfont[<font features>]{<name of font>}


This sets up a switch called \myfont which changes the font to that font. (It is also possible to select a font directly using the \fontspec command, but this is generally to be avoided, since the \newfontfamily method is much more efficient.)

Font Features

Since fontspec package provides access to OpenType fonts, it is able to provide access to many of the special features that come with these fonts. These features can be selected using the optional argument of any font selection command. See the fontspec documentation for more details. I'll outline a couple of commonly used features here.

• [Ligatures=TeX] This feature allows you to use regular TeX ligatures (which are not turned on by default in fontspec. Especially if you are used to e.g. typing LaTeX style quotation marks or -- and --- instead of typing the actual characters directly, you should always turn on this option.
• [Numbers=OldStyle] This feature turns on lower case numbers
• [Scale=MatchLowercase] This feature is used to scale e.g. the sans or mono font to match (in this example) the lower case characters of the roman font. Another option is MatchUppercase; alternatively a numeric scaling value can be given.

See the fontspec documentation for a full description of the wealth of features that can be specified.

If you are setting separate roman, mono, and sans fonts or creating new font families, you often want to have the same font features specified for all. You can do this by using the \defaultfontfeatures command:

\defaultfontfeatures{Ligatures=TeX} % makes this a feature for all selected fonts


## Finding the name of the font

If you are using system fonts, you can use the name of the font as it appears in any application on your system. (On a Mac, these are usually the fonts in /Library/Fonts; on Windows they are usually in \Windows\Fonts; on Linux the usual place is /usr/local/share/fonts. For example:

\setmainfont{Linux Libertine O}


There's really no sense in listing font names here, but I'll add some examples of what the names can look like:

• Arial Rounded MT Bold
• DejaVu Sans Mono
• Florencesans SC Black

Notice that spaces that normally appear in the name of the font must also be present when you choose the font using fontspec.

## Restricting the scope of the selection

You can always restrict the scope of font changing commands by enclosing the text in braces:

{\myfont ...}


or, to make the scope of the command more visible in your file if you don't have a brace-matching editor

\begingroup
\myfont ...
\endgroup


If this is something you will be doing a lot, it would make more sense to turn it into a proper environment:

\newenvironment{myfont}{\myfont}{\par}


Then you use it like any other environment:

\begin{myfont}
Some text in the new font.
\end{myfont}


You can also define a command corresponding to the standard font changing commands such as \textrm or \textsf, but using your particular font:

\DeclareTextFontCommand{\textmyfont}{\myfont}


Use this like the standard commands:

Text in the default font. \textmyfont{Text in the new font.} Again text in the default font.


An advantage of this command over the simpler version described above is automatic italic correction, cf. Why use \DeclareTextFontCommand vs. just \newcommand?.

-
More font features: [Color=000099] (dark blue) –  Igor Kotelnikov Apr 13 '12 at 6:40

# ConTeXt MkIV

In ConTeXt MkIV it is easy to use a font for a small section. For larger parts of text I would recommend to use the Simplefonts module or to write typescripts, because larger parts probably contain font switches that change the style.

## How do I find the right name of the font?

First you have to install the font, if not already done. On Unix you can use the directory $HOME/.fonts for a per user or e.g. /usr/local/share/fonts for a system wide installation. You have to point the environment variable OSFONTDIR to the directory where the fonts can be found: export OSFONTDIR="/usr/local/share/fonts;$HOME/.fonts"


Then run

mtxrun --script fonts --reload


to regenerate the font database. Now you can query the database. This gives you a list of all available fonts:

mtxrun --script fonts --list --all


Here are the first ten lines of this list:

ams                   wncysc10              wncysc10.afm
amsbold               wncyb10               wncyb10.afm
amsmedium             wncysc10              wncysc10.afm
antpoltbold           antpoltbold           antpolt-bold.otf
antpoltbolditalic     antpoltbolditalic     antpolt-bolditalic.otf
antpoltcondbold       antpoltcondbold       antpoltcond-bold.otf
antpoltcondbolditalic antpoltcondbolditalic antpoltcond-bolditalic.otf
antpoltconditalic     antpoltconditalic     antpoltcond-italic.otf
antpoltcondregular    antpoltcondregular    antpoltcond-regular.otf
antpoltexpdbold       antpoltexpdbold       antpoltexpd-bold.otf


You get three columns the second being the normalised (all lower-case, no special characters, no spaces) name and the third being the file name (in lower-case).

You can run the list through grep or use the built-in mechanism to search for particular fonts:

mtxrun --script fonts --list --pattern=deli* --all


gives

delicious             deliciousbold         Delicious-Bold.otf
deliciousbold         deliciousbold         Delicious-Bold.otf
deliciousbolditalic   deliciousbolditalic   Delicious-BoldItalic.otf
deliciousheavy        deliciousheavy        Delicious-Heavy.otf
deliciousitalic       deliciousitalic       Delicious-Italic.otf
deliciousmedium       deliciousitalic       Delicious-Italic.otf
deliciousnormal       deliciousroman        Delicious-Roman.otf
deliciousregular      deliciousheavy        Delicious-Heavy.otf
deliciousroman        deliciousroman        Delicious-Roman.otf
delicioussmallcaps    delicioussmallcaps    Delicious-SmallCaps.otf


## How do I select the font?

Since we deal just with one font without bold or italic font switches (however, the selected font can of course be bold or italic) we can simply use \definefont:

\definefont [delicious] [name:deliciousroman]


This defines a macro \delicious which switches to the given font. The name: prefix is used to refer to the normalised name in the font list (second column). One can also use the file: prefix and use the file name (third column) without the path.

## How do I restrict the scope of the font change?

You can use braces, \start \stop, \begingroup \endgroup or any other grouping mechanism.

Here is a complete example which uses the font Delicious-Roman (an OpenType font).

\definefont [delicious] [name:deliciousroman]

\starttext

\start
\delicious
\input knuth
\stop

\input knuth

\stoptext


The output:

The right box indicates that indeed the requested font is being used. Further information can be found one the ConTeXt wiki - Fonts in LuaTeX and the Chapter on fonts.

-
Museo font is not there in list. –  manish Jul 25 '12 at 4:40
If it's not in the list, it is not installed (at least not for ConTeXt). Are you sure you are using LuaTeX (MkIV) and you didn't forget to set OSFONTDIR or reloading the font database? For clarification of this very problem please contact the mailing list –  Marco Jul 25 '12 at 5:26