# Change language inside verbatim environment

I have the following:

\documentclass[a4paper]{article}

%% Language and font encodings
\usepackage[greek, english]{babel}
\usepackage[iso-8859-7]{inputenc}
\usepackage{amsfonts}
\usepackage{amsmath}

\selectlanguage{english}
\author{You}

\begin{document}
\maketitle

\begin{abstract}
blah blah
\end{abstract}

\section{Introduction}

\begin{verbatim}
% Ελληνικά (Greek) <-----
Dt = 0.0001;
t = 2+Dt:Dt:100;

% Comment
x = (1/3)*exp(-2*(t-2));

% Comment
x_sq = x.^2;

% Comment
result = Dt * sum(x_sq)
\end{verbatim}
\selectlanguage{greek}
Ελληνικά - \textlatin{This works well, this should appear in the first comment line inside verbatim}.
\end{document}


First of all, I am using PDFLatex. The problem is when I compile this code, the first comment inside verbatim environment appears in latin characters, not in Greek. Is there any way to overcome this?

• What engine do you use? (pdftex, xetex, luatex). Please edit your question and add a MWE. – David Purton Jan 4 at 13:43