1

I would like to reduce the font size within a (beamer) document for some code listings; to allow an occasional larger program to fit on a slide.

I have in the past used \begin{lstlisting}[basicstyle=\tiny], but this approach requires also to set the sizes of identifierstyle, commentstyle, stringstyle, and keywordstyle. Each of these categories also requires their colours to be set again; or default to black. (I am also not aware of how to obtain existing colours/fonts for these categories.)

Setting the font size overall (via \documentclass[9pt]{beamer}) will produce the sought result on the slide in question - with the desired syntax colouring - but of course all other text in the document is affected. Is there a way to change the font for individual slides for this purpose?

1

Something like this?

\documentclass{beamer} 

\usepackage{minted}
\usepackage{tcolorbox}
\tcbuselibrary{minted}

\newtcblisting{mycodelisting}[1]{%
  listing engine=minted,
  minted style=default,
  minted language=python,
  minted options={fontsize=#1},
  listing only
}

\begin{document}

\begin{frame}[fragile]
\frametitle{Test}
normalsize
\begin{mycodelisting}{\normalsize}
v0 = 6.4
g = 9.81
t = 1
y = v0*t - 0.5*g*t**2
print(y)
\end{mycodelisting} 
scriptsize
\begin{mycodelisting}{\scriptsize}
v0 = 6.4
g = 9.81
t = 1
y = v0*t - 0.5*g*t**2
print(y)
\end{mycodelisting} 
\end{frame}

\end{document}

output

  • Fascinating. I am working with the Rust syntax highlighter from here. I'll investigate compatibility when I'm back at my workstation. – user4417 Dec 11 '19 at 19:48
  • 1
    This is my first look at minted, and I'm quite impressed. For others using pdflatex, note that the --shell-escape flag is required. I was glad to see that although it isn't listed here, Rust is supported. (btw. I noticed an unexpected box appears around the ellipsis when using a C++11 template pack declaration following the class keyword.) – user4417 Dec 13 '19 at 11:46

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.