I am writing a document in LaTeX and I want to change the font of selected words within a paragraph. An example of what I am trying to achieve is this: enter image description here

3 Answers 3


If you want to switch to a fixed-width font, you can load any fixed-width font package (such as tgcursor or inconsolata) and use \texttt. You will rarely if ever want to use more than one fixed-width font in the same document.

If you do need to use a specific font that isn’t one of the predefined font families, you either declare the command with \newfontfamily in the modern toolchain with fontspec, or \fontfamily in legacy NFSS.

I would recommend that you use \DeclareTextFontCommand to define the command you will be using inside the body of your document. This both takes care of some of the fiddly little details, such as italic correction, and also lets you change how you load the font without changing the body in dozens of places. For example,

\newfontfamily\tgcursor{TeX Gyre Cursor}[Scale=MatchLowercase]

could be replaced with


to compile with the legacy toolchain.


Specifically, you are looking for \underline{} and \texttt{} basic commands. Generally, to change the style or font size you are looking for the section 6.2 of The Not So Short Introduction to LATEX 2ε.

The above is to always use the same default roman, sans serif, typewriter and math fonts with standard sizes and it's the only thing the normal user should know (since a page with "enriched text", i.e., with with more than three or four typefaces, is basically garbage).

Nonetheless, if you need also switch to another fonts (e.g., said change from Computer Modern to Fraktur) the method depend on of the font. Some font packages provide commands to switch to a particular font family (as \frakfamily using the yfonts package). The LaTeX font Cataloque is the right place to know about many of them.

However, you can see there that most fonts packages are designed only to change the default fonts in the whole document. If you want to use them for only for some word, I warn you, you will go to the dark side of TeX\LaTeX, with obscure incantations like the \fontfamily{ptm}\selectfont suggested by js bibra or more ominous spells as \font\Aparecium=pagko \Aparecium and \usefont{T1}{phv}{b}{sl}, or even true black magic charms as \input Acorn.fd \usefont{U}{Acorn}{xl}{n}

The routine example:


\usepackage{fix-cm} % scalable cm
foo  \underline{foo} \texttt{foo} \textbf{foo} \emph{foo}\par

{\fontsize{30}{50}\selectfont foo \Huge foo  \normalsize foo \footnotesize foo \tiny foo \fontsize{3}{5}\selectfont foo}\par

{\calligra foo} {\frakfamily foo} {\tgothfamily foo} 

\font\foo=pagko \foo  foo
\font\omding=omding \omding  foo 
\usefont{T1}{phv}{b}{sl} foo 
\usefont{U}{webo}{xl}{n} foo 
\input Acorn.fd \usefont{U}{Acorn}{xl}{n} foo

  • incantation dark spells magic charms haahaha truly nice write up for a dreary subject
    – js bibra
    May 9, 2020 at 2:26

enter image description here

You can set the fontfamily using \fontfamily{<family>}\selectfont



    Text in \myuline{Palatino} any new user defined function or 
    \myuline{modification} \par  %switch font after this
    {\fontfamily{ptm}\selectfont function \myuline{Text in Times with 
    underline for descendants gly}}\par %switch font after this
    \texttt {function} \par %switch font back to palatino
    \myuline{Text in Palatino with underline for descendants gly}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .