[Tex/LaTex] Use of Bera Mono font with \mlttfamily described by matlab-prettifier

matlab-prettifier

I am using latex with pdftex and trying to use the Bera Mono font with the \mlttfamily described by matlab-prettifier documentation. However, my generated output seams to ignore my \lstset basicstyle = \mlttfamily setting and uses the default \ttfamily instead? Below is image of my output.

\documentclass[border=30pt]{standalone} 

\usepackage[final]{matlab-prettifier}

\usepackage[T1]{fontenc}

\lstset{
  style              = Matlab-editor,
  basicstyle         = \mlttfamily, %\ttfamily
  escapechar         = ",
  mlshowsectionrules = true,
}

\begin{document}

\begin{lstlisting}[style=Matlab-editor]
%% Code sections are highlighted.
% System command are supported...
!gzip sample.m
% ... as is line continuation.
A = [1, 2, 3,... % (mimicking the ouput is good)
 4, 5, 6]
fid = fopen('testFile.text', 'w')
for i=1:10
  fprintf(fid,'%6.2f \n', i);
end
x=1; %% this is just a comment, though
% Context-sensitive keywords get highlighted correctly...
p = properties(mydate); %(here, properties is a function)
x = linspace(0,1,101);
y = x(end:-1:1)
% ... even in nonsensical code.
]end()()(((end end)end ))))end (function end
%{
    block comments are supported
%} even
runaway block comments
are
   \end{lstlisting}

\end{document}

output image

Best Answer

This fixes the problem, \lstset defines the default setting for \lstlisting and I was overwriting this style setting earlier without the change in font.
The following code now correctly changes the font to Bera Mono.

\documentclass[border=30pt]{standalone} 

\usepackage[final]{matlab-prettifier}

\usepackage[T1]{fontenc}

\lstset{
  style              = Matlab-editor,
  basicstyle         = \mlttfamily, %\ttfamily
  escapechar         = ",
  mlshowsectionrules = true,
}

\begin{document}

\begin{lstlisting}
%% Code sections are highlighted.
% System command are supported...
!gzip sample.m
% ... as is line continuation.
A = [1, 2, 3,... % (mimicking the ouput is good)
     4, 5, 6]
fid = fopen('testFile.text', 'w')
for i=1:10
  fprintf(fid,'%6.2f \n', i);
end
x=1; %% this is just a comment, though
% Context-sensitive keywords get highlighted correctly...
p = properties(mydate); %(here, properties is a function)
x = linspace(0,1,101);
y = x(end:-1:1)
% ... even in nonsensical code.
]end()()(((end end)end ))))end (function end
%{
    block comments are supported
%} even
runaway block comments
are
\end{lstlisting}

\end{document}
Related Question