[Tex/LaTex] How to change the font for selected words in LaTeX document

fonts

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

Best Answer

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,

\usepackage{fontspec}
\newfontfamily\tgcursor{TeX Gyre Cursor}[Scale=MatchLowercase]
\DeclareTextFontCommand\textcourier{\tgcursor}

could be replaced with

\usepackage[T1]{fontenc}
\DeclareTextFontCommand\textcourier{\fontfamily{qcr}}

to compile with the legacy toolchain.