\documentclass[preview,border=12pt]{standalone}% change it to your own document class
% begin
% this part is used to allow your readers to copy the code from a PDF viewer but without copying the line numbers.
\usepackage{accsupp}
\newcommand*{\noaccsupp}[1]{\BeginAccSupp{ActualText={}}#1\EndAccSupp{}}
% end
\usepackage{xcolor}
\usepackage{listings}
\lstdefinestyle{shared}
{
numbers=left,
numbersep=1em,
numberstyle=\tiny\color{red}\noaccsupp,
frame=single,
framesep=\fboxsep,
framerule=\fboxrule,
rulecolor=\color{red},
xleftmargin=\dimexpr\fboxsep+\fboxrule\relax,
xrightmargin=\dimexpr\fboxsep+\fboxrule\relax,
breaklines=true,
tabsize=2,
columns=flexible,
}
\lstdefinestyle{xml}
{
style=shared,
language={XML},
%alsolanguage={PSTricks},
basicstyle=\small\tt,
keywordstyle=\color{blue},
commentstyle=\color[rgb]{0.13,0.54,0.13},
backgroundcolor=\color{yellow!10},
morekeywords={
graphicspath,
includegraphics,
blinddocument,
},
}
\lstdefinestyle{python}
{
style=shared,
language={Python},
%alsolanguage={[Sharp]C},
basicstyle=\small\tt,
keywordstyle=\color{blue},
commentstyle=\color[rgb]{0.13,0.54,0.13},
backgroundcolor=\color{cyan!10},
morekeywords={
Console,
WriteLine,
int,
},
}
\lstnewenvironment{xml}
{\lstset{style=xml}}
{}
\lstnewenvironment{python}
{\lstset{style=python}}
{}
\begin{document}
\begin{xml}
<XML></XML>
\end{xml}
\begin{python}
for i in python:
pass
\end{python}
\end{document}
Redefine \lstinputlisting
to always use frame=lines
:
\documentclass{article}
\usepackage{filecontents}
\begin{filecontents*}{code.py}
for j in range(100):
print(j)
print(j**3)
\end{filecontents*}
\usepackage{listings}
\lstset{
basicstyle=\footnotesize\ttfamily,
escapechar=ยข,
language=python
}
\let\oldlstinputlisting\lstinputlisting
% \lstinputlisting always have frame=lines
\renewcommand{\lstinputlisting}[2][]{\oldlstinputlisting[frame=lines,#1]{#2}}
\begin{document}
An inline code example:
\begin{lstlisting}
for i in range(10):
print(i**2)
\end{lstlisting}
Some code inputted from elsewhere:
\lstinputlisting[caption=code example]{code.py}
\end{document}
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 definesbasicstyle = \color{black}\ttfamily\normalsize
for all the different listings styles. So you can redefine this key with the modified font size command where necessary: