[Tex/LaTex] Using lmodern as default teletype font

fontslatin-modern

I would like to use lmodern as my default teletype font, while using other fonts for sans etc.

So far I have

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[defaultsans]{cantarell}
\usepackage{lmodern}
\renewcommand*\ttdefault{???}

\begin{document}
{\ttfamily Hello in lmodern }
\end{document}

What do I have to replace the ??? with in order for the lmodern to be used as the default teletype?

Best Answer

The cantarell package with the defaultsans option sets the sans serif font to Cantarell by redefining \sfdefault. However, lmodern does

\renewcommand{\sfdefault}{lmss}

so loading it after cantarell will override the specification made by this package. The lmodern package sets \ttdefault to lmtt (Latin Modern Typewriter), so you get served by

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage[defaultsans]{cantarell}

\begin{document}
{\sffamily Hello in Cantarell}

{\ttfamily Hello in lmodern}
\end{document}

without doing anything for \ttdefault.

enter image description here