[Tex/LaTex] `\lstinputlisting` not respecting basicstyle=\tiny

listingsmatlab-prettifier

I am trying to fit MATLAB code in my document without wrapping, but I cannot change the font size when using matlab-prettifier. Here's a MWE using both lstinputlisting and environment style:

\documentclass[letterpaper,twoside,11pt]{article}
\usepackage{listings}
\usepackage[mlscaleinline=true]{matlab-prettifier}
\lstMakeShortInline[basicstyle=\tiny,style=Matlab-editor]@
\lstnewenvironment{matlab}{\lstset{basicstyle=\tiny,style=Matlab-editor}}{}
\begin{document}
\section{Why don't you respect me, prettifier?}
\lstinputlisting[basicstyle=\tiny,style=Matlab-editor]{m/example.m}
\tiny
\begin{matlab}
apples
\end{matlab}
\end{document}

The result:

the tex result

Any ideas how to force this? I've tried many variations of basicstyle=\tiny.

Best Answer

The matlab-prettifier package doesn't seem to have an extra field for setting the font size globally. But looking at the source code, it defines basicstyle = \color{black}\ttfamily\normalsize for all the different listings styles. So you can redefine this key with the modified font size command where necessary:

\documentclass[letterpaper,twoside,11pt]{article}

\usepackage{listings}
\usepackage[mlscaleinline=true]{matlab-prettifier}

\lstMakeShortInline[style=Matlab-editor]@
\lstnewenvironment{matlab}{\lstset{
    style=Matlab-editor,
    basicstyle=\color{black}\ttfamily\tiny
}}{}

\begin{document}
\section{sudo respect me, prettifier!}
Normal sized text
\begin{lstlisting}[style=Matlab-editor,basicstyle=\color{black}\ttfamily\tiny]
function [] = example(x,y)
% some code...
plot(x,y);
\end{lstlisting}
\tiny Some tiny text here with @function [] = inline(x,y)@
\begin{matlab}
apples
\end{matlab}
\end{document}

enter image description here

Related Question