5

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.

5

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

2

My problem was fixed after refactoring the \usepackage command:

\usepackage[english, greek]{babel}

and inserting the command

\selectlanguage{english} before the verbatim

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.