Using lstlisting with T2A

I would like to display a code listing using the package listings. It all work nice, except if I had the fontenc T2A. When I do, the listing stop being displayed using \ttfamily font and is shown using regular font.

A MWE:

\documentclass{article}
\usepackage[T1,T2A]{fontenc}        %T2A causes a problem...
\usepackage[utf8]{inputenc}

\usepackage{courier}
\usepackage{listings}
%\renewcommand*{\ttdefault}{pcr}
\lstset{
basicstyle=\ttfamily,breaklines=true,keepspaces=true,columns=flexible,
aboveskip=6pt,belowskip=6pt
}

\begin{document}

\begin{lstlisting}
GRD
/SUBJECTSPERGROUP equal = 1000
/WSFACTORS X (2)
/SCORES population = "RV.MVN({0,0}, {5**2,.99*5*5;.99*5*5,5**2})"
/CONTAMINANTS population = "RV.MVN({-5,5}, {1**2,-.01*1*1;-.01*1*1,1**2})" PROPORTION = .5.
\end{lstlisting}

\end{document}


Remove T2A in the fontenc package call, and everythings work fine. Put it and the font is no longer \ttfamily. I tried renewing the command \ttdefault (see commented line), but to no avail. Any idea?

• courier doesn't support the T2A encoding. You could add \fontencoding{T1} to the basicstyle (provided your listings don't contain any Cyrillic). – Robert Mar 21 '16 at 4:46
• As simple as that! \lstset{ basicstyle=\fontencoding{T1}\ttfamily,...} indeed solved my problem. Thanks @Robert. – Denis Cousineau Mar 21 '16 at 10:51

There is no support for the T2A encoding with the courier font, so LaTeX will fall back to Computer Modern Roman. If you don't want to use a different typewriter font, and provided that the code listings don't contain any Cyrillic, you can switch to T1 encoding for the listings:
\lstset{basicstyle=\fontencoding{T1}\ttfamily,