1

I'm writing a document using Overleaf. The main language I'm using is Greek. The Greek shows up fine but when I try to enter Matlab code using the package listings, it shows up as Greek in the compiled document instead of the English Matlab commands. Part of the code:

\usepackage[english, greek]{babel}
\usepackage{listings}

\begin{document}
%matlab
\lstset{language=Matlab,%
    %basicstyle=\color{red},
    breaklines=true,%
    morekeywords={matlab2tikz},
    keywordstyle=\color{blue},%
    morekeywords=[2]{1}, keywordstyle=[2]{\color{black}},
    identifierstyle=\color{black},%
    stringstyle=\color{mylilas},
    commentstyle=\color{mygreen},%
    showstringspaces=false,%without this there will be a symbol in the places where there is a space
    numbers=left,%
    numberstyle={\tiny \color{black}},% size of the numbers
    numbersep=9pt, % this defines how far the numbers are from the text
    emph=[1]{for,end,break},emphstyle=[1]\color{red}, %some words to emphasise
    %emph=[2]{word1,word2}, emphstyle=[2]{style},    
}

\lstinputlisting{MyMatlabCode.m}

Result:

matlab code result

How it should look like:

matlab code proper

I used code from this question: What can I use to typeset MATLAB code in my document?

1 Answers1

2

Solved by using \selectlanguage{} and changing the language to English and then back to Greek again.

\selectlanguage{english}
\lstinputlisting{MyMatlabCode.m}
\selectlanguage{greek}
  • That is basically what the otherlanguage env does, you just don't what to manually insert the Greek at the end – daleif Feb 21 '20 at 20:42