In a search for a good monospaced font for my code listings I found the lmodern fonts. I really like the lighttt variant of those. The difference between normal and bold version is clearly visible with the ttfamily.
Recently however I discovered I also need italic version of those. Unfortunately the following:
\documentclass{article}
\usepackage[lighttt]{lmodern}
\begin{document}
Abc {\ttfamily abc {\bfseries abc} {\itshape abc}}
\end{document}
throws an error:
! No declaration for shape OT1/lmtt/l/sl
Is there a way to enable italic in this font?
With a bit of experimentation I soon discovered, that while italic is not available, it is possible to use the slanted font. \slshape works with lmodern-lighttt-ttfamily well enough.
However, while in the above MWE I use the \itshape explicitly and can be easily exchanged with \slshape, in my real scenario it is not always the case.
- I use listings package which automatically uses italic font in certain scenarios (e.g. comments in code)
- Sometimes I put short pieces of code in a caption, which - as a whole - is italic (and shouldn't use slanted)
A quick hack: \renewcommand{\itshape}{\slshape} is not reasonable in longer run either as it changes all italic fonts to slanted, while my concern is only in the monospaced case - when typing source code.
Maybe there is a way to treat \itshape as \slshape only in the context of monospaced font?

\slshapemay or should not be used (e.g. with thelistingspackage and in captions), it will be easier to come up with a workaround. i know it's been done, but the approach has to be quite environment-specific. – barbara beeton Mar 19 '15 at 13:54ttfamily+itshapeasttfamily+slshape. – CygnusX1 Mar 19 '15 at 14:11