3

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.

  • Is changing the order of keys in [basicstyle=\tiny,style=Matlab-editor] any help? My guess is that the second key overrides the definition of the first. Also, just in case, check the .log file for font warnings. – siracusa Nov 6 '16 at 2:34
  • Do you mean: [style=Matlab-editor,basicstyle=\tiny]? I tried and it overwrote most of the Matlab-editor style, unfortunately. – Jesse Knight Nov 6 '16 at 19:43
6

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

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.