I'd like to keep all the fonts for the document the same and only change the font for the llstststing environment to something sensible like IBM Plex mono, Adobe Source Code Pro, or Noto Sans Mono. Is that possible and how so?
MWE:
\documentclass{article}
\usepackage[english]{babel}
\usepackage{blindtext}
\usepackage{plex-mono}
\usepackage[table,xcdraw]{xcolor}
\definecolor{backcolour}{rgb}{0.98,0.98,0.95}
\usepackage{listings}
\lstdefinestyle{prettycode}{
backgroundcolor=\color{backcolour},
aboveskip={0.9\baselineskip},
keepspaces=true,
}
\lstset{style=prettycode}
\begin{document}
\section{Section One}
\blindtext
\begin{lstlisting}[language=c, caption=Hello world program., label=listing:hello_world]
#include <stdio.h>
int main()
{
// prints hello world
printf("Hello World");
return 0;
}
\end{lstlisting}
\subsection{Subsection}
\blindtext
\end{document}
Related, but solutions seem to change the typewriter font for the whole document: set the font family for lstlisting



fontspec's\newfontfamily, then\lstset{basicstyle=<cmd>}will do the work. – muzimuzhi Z Feb 10 '22 at 12:58\fontprimitive). – muzimuzhi Z Feb 10 '22 at 13:51/fontprimitive? – Max N Feb 10 '22 at 16:02fontspecis more or less just a wrapper to (different) font selection primitives and syntaxes provided by xetex and luatex, and it provides an cross-engine, easier-to-use, easier-to-read interface. Why you want to avoid it so much? – muzimuzhi Z Feb 10 '22 at 16:23fontspecat all, but about changing engine from pdftex to xe- or lua-tex, right? LaTeX usesTUfont encoding for unicode engines, butT1for pdftex. This may cause font messing. If the font you want is accessible under pdftex, then it's always possible to define a font switching command and use it inbasicstyle=<cmd>. Among the fonts you mentioned, both plex and noto have pdftex support. If you've decided which font to use and have trouble applying it only forlstlisting, welcome back. – muzimuzhi Z Feb 10 '22 at 17:08