As has been asked often enough, to get bold keywords in lstlisting
environments, one has to use a different typewriter font. Most answers suggest to include this or that package.
If just including a package changes the font, then the package must be applying some magic in the background to install itself. And unless the package was specifically made for listings, this means it potentially also changes other stuff.
How can I use another font in my listings while being sure that nothing else is affected, or at least that nothing but the default typewriter font is changed?
Best Answer
That's an excellent question. Many answers to questions about
listings
on this site tell you to load along with thefontenc
package with optionT1
(which is fine) along with a package such ascourier
orberamono
in order to have access to boldface typewriter fonts. However, packages likeberamono
andcourier
change the default typewriter font family globally, which may not be what you want.If you want a certain font only inside listings, you should simply select it in the
basicstyle
key.I suggest you define a macro to easily select the font in question (see below). You should still load the
fontenc
package with optionT1
, but don't loadberamono
or the likes of it.