I have set a new matcode environment in order to have some matlab code in my .tex file, using the matlab-prettifier package (combined with the listings package). However, I have a problem with the tilde symbol.
\documentclass{article}
\usepackage[english,greek]{babel}
\usepackage[utf8]{inputenc}
\usepackage{kerkis}
\usepackage{xcolor}
\usepackage{listings}
\makeatletter
% Avoid the spurious error
\AtBeginDocument{%
\expandafter\def\expandafter\originalTeX\expandafter{%
\expandafter\@tempcnta\number253\expandafter\relax\originalTeX}%
}
% apply the fix
\addto\extrasgreek{%
\@tempcnta=128
\@whilenum\@tempcnta<253\do{%
\expandafter\babel@savevariable\expandafter{\expandafter\lccode\the\@tempcnta}%
\lccode\@tempcnta=\@tempcnta
\advance\@tempcnta\@ne
}%
}
\usepackage{matlab-prettifier}
\lstnewenvironment{matcode}
{
\selectlanguage{english}
\fontfamily{cmr} \fontsize{8}{10}\selectfont
\lstset{
language=matlab-pretty,
style=Matlab-editor,
basicstyle = \ttfamily,
keepspaces=true,
escapechar=\#}
}
{
\normalsize
\selectlanguage{greek}
}
\begin{document}
\begin{matcode}
% This is a comment.
[~, a ]
\end{matcode}
\end{document}
If I use the kerkis.sty package, then the result is going to be this one, where I miss the tilde symbol (apparently the tilde symbol is not supported by kerkis):

Ignoring (by commenting) the kerkis.sty package, the result is going to be this one:

Although the tilde symbol is somewhat displaced, at least it is visible. As you can see, I tried to load the cmr font inside the matcode environment, but I had no luck with that. So my question is:
How can I load the
cmrfont inside mymatcodeenvironment, without commenting the command\usepackage{kerkis}?
Edit: In order to override this problem and make the tilde symbol appear, I used the escapechar # and I replaced the tilde symbol in my .tex file, with the command #\texttildelow#, but this is not a neat solution for sure.
matlab-prettifiermanual). For some solutions, see http://tex.stackexchange.com/questions/312/correctly-typesetting-a-tilde. – jub0bs Jun 28 '15 at 10:43