[Tex/LaTex] Greek and Latin letters in verbatim

babelgreekverbatim

I want to write a code snippet where the commands are in greek and variables are in latin. I use the verbatim command but automatically the latin characters are translated to their greek equivalent.
I use the babel package so far and I had no issues.

\begin{verbatim}
για κάθε t:
    x1 = x0 + u*Δt
\end{verbatim}

which results in

enter image description here

In the preamble I use

\usepackage[utf8]{inputenc}
\usepackage[greek]{babel}
\usepackage{alphabeta}
\usepackage[LGR, T1]{fontenc}

Any ideas on how to fix that? I would like not to change to another package like polyglossia because that would make me to rewrite a big portion of my report.

Best Answer

Set the font encoding to T1 inside verbatim:

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[greek]{babel}
\usepackage{alphabeta}

\makeatletter
\renewcommand\verbatim@font{\normalfont\fontencoding{T1}\ttfamily}
\makeatother

\begin{document}

\begin{verbatim}
για κάθε t:
    x1 = x0 + u*Δt
\end{verbatim}

\end{document}

enter image description here