[Tex/LaTex] cmtt as font in texttt

fontstypewriter

I am using libertine fonts and I would like to change the texttt command to use the cmtt font.
I tried :

\renewcommand{\texttt}[1]{\fontfamily{cmtt}\selectfont{#1}}

but it seems to switch the font for all the text coming after the texttt command. If I type before \texttt{center} after, I want only center to be in cmtt. How to do that ?

Best Answer

If you load the libertine package, do

\usepackage[tt=false]{libertine}

With other font packages, if they don't provide a suitable option, just do

\renewcommand{\ttdefault}{cmtt}

after having loaded the font package.

Redefining \texttt in the way you tried is wrong.

Related Question