# 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?

• 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
• @doncherry: The global change is trivial when it just involves including a package. Making that change only for a portion of the document is, however, unexpectedly challenging (and I fear that's one more reason for non-LaTeX-people to refuse LaTeX), and I suspect a significant portion of the 200+ upvoters so far came here specifically looking for a way to not make a global font change, as I just did. Widening the scope of the question to include global changes could make it less obvious that the question actually explains how to locally apply a font. – O. R. Mapper Oct 1 '15 at 9:03

# 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
qbk                    TeX Gyre Bonum
qzc                    TeX Gyre Chorus
qcr                    TeX Gyre Cursor
qhv                    TeX Gyre Heros
qpl                    TeX Gyre Pagella
qcs                    TeX Gyre Schola
qtm                    TeX Gyre Termes
ptm                    Times
uncl                   Uncial
put                    Utopia
pzc                    Zapf Chancery


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?.

## Common fonts rendered

(except ccr Compute Concrete).

• 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
• What's the recommended way of limiting the scope of the font to just the block? The calligra font (tug.dk/FontCatalogue/calligra) seems to have a \calligra command that applies only to the current block, however for some packages (like tug.dk/FontCatalogue/tgchorus) set the default font for the entire document. Must one reset this (using \renewcommand) right after the \usepackage command and then use the \myfont macro you describe? – ffledgling Oct 24 '15 at 13:40
• visual reference: The LaTeX Font Catalogue, for example here the Typewriter Fonts – nilon Sep 22 '16 at 13:34
• @Alan Munn When using \newcommand*{\myfont}{\fontfamily{<familyname>}\selectfont} or \newenvironment{myfont}{\fontfamily{<familyname>}\selectfont}{\par} and then in the text begin/end, the text does not get justified and it exceeds the set width of the text. Is it possible to fix this? – Valerio May 17 '17 at 14:52
• @Valerio Make a minimal example document that shows the problem and then ask a new question. – Alan Munn May 17 '17 at 15:03

## 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.) This switch behaves exactly like \rmfamily or sffamily (except that it is called \myfont and switches to the font assigned to it).

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 GUI 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}
\newfontfamily\myfont{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

These names are not the filenames of the fonts. If you have some sort of font manager GUI like Font Book on the Mac, the names are displayed there. On Windows you can find the names in the Fonts preview section of the control panel.

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

If you want to list the fonts which support a certain language (since fonts usually support only part of the Unicode character), you can use the fc-list command. For example, to find fonts which support Chinese, first find the language code of Chinese, i.e., zh, then we use the following command

fc-list :lang=zh


to show the list of fonts supporting Chinese. Output will be something like:

/usr/share/fonts/custom/STLITI.TTF: STLiti,华文隶书:style=Regular
/usr/share/fonts/custom/SourceHanSerifSC-Regular.otf: Source Han Serif SC,思源宋体:style=Regular
/usr/share/fonts/wqy-microhei/wqy-microhei.ttc: WenQuanYi Micro Hei Mono,文泉驛等寬微米黑,文泉驿等宽微米黑:style=Regular
/usr/share/fonts/custom/SIMLI.TTF: LiSu,隶书:style=Regular
/usr/share/fonts/custom/STXINWEI.TTF: STXinwei,华文新魏:style=Regular
/usr/share/fonts/wqy-zenhei/wqy-zenhei.ttc: WenQuanYi Zen Hei Sharp,文泉驛點陣正黑,文泉驿点阵正黑:style=Regular
/usr/share/fonts/wqy-microhei/wqy-microhei.ttc: WenQuanYi Micro Hei,文泉驛微米黑,文泉驿微米黑:style=Regular
/usr/share/fonts/custom/FZYTK.TTF: FZYaoTi,方正姚体:style=Regular


The font name is after the font location, for example, STLiti.

## 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
• In the final section Restricting the scope of the selection I don't understand what 'myfont' is supposed to stand for. The font's name?? So if the font's name is, say, 'Linux Libertine O', is this how one switches to this font locally: {\Linux Libertine O ...}? – Evan Aad Jun 23 '17 at 6:29
• Another point of confusion for me is the following. The section Finding the name of the font begins with the following instruction '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[...]'. The filenames appearing in /Library/Fonts are not necessarily the names of the fonts, as there need be no relation between the name of a font's file and the font's name. So which name are you referring to? File or font? In the latter case, how can it be found on Mac, Windows and Linux? – Evan Aad Jun 23 '17 at 9:28
• @EvanAad \myfont is the literally the macro that is created when you use \newfontfamily\myfont{Name of Font}. It is not the name of the font, but whatever name you choose to use as the macro to switch to that font. As for finding the names of fonts, on a Mac it is the name displayed in Font Book (or in the Font menu of any Mac application.) Similarly on other OSes, it is the name that is used in GUI applications, not the font filename. – Alan Munn Jun 23 '17 at 14:02
• @Philipp But you need the \par in the environment, because it's only at the ends of paragraphs that TeX applies the changes. – Alan Munn Aug 21 '18 at 15:31

# 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
• simplefonts was superseded by \definefontfamily. There is also a new manual on Fonts in MKIV. – Henri Menke Sep 23 '16 at 9:20

As far as delimiting small sections, you can use text property declarations. Fore example, to change the font to teletype and then back to default, follow this example:

\ttfamily http://www.ctan.org\normalfont


Or, use braces to restrict the scope of the change:

{\ttfamily http://www.ctan.org}


You could also create an environment with a declaration, for example when writing multiple lines of code:

\begin{ttfamily}
statement 1;
statement 2;
...
statement n;
\end{ttfamily}