# Beamer: \begin{frame} + minted package for syntax highlighting

I am trying to define a .sty file to help adding slides with code samples in my presentations. The minted package is a nice-looking solution for adding syntax-highlighting, but I can't get it to work together with a custom environment using \begin{frame}.

my beamerthemetheme.sty file is defined as below:

\usepackage{minted}
\newenvironment{Sli}[1]{
\begin{frame}[fragile]
{}
#1
\end{frame}
}%


my main.tex file is as follows:

\documentclass[aspectratio=169]{beamer} %. Aspect Ratio 16:9
\usetheme{theme}

\begin{document}
\Sli{
\begin{minted}{python}
import numpy as np
\end{minted}
}
\end{document}


But it is impossible to get the \Sli command working together with minted.

When written as defined above I get a Runaway argument? error. I've tried moving things around and small changes and the error changes but I still can't get it working. Curiously, if I use the commands directly without separating it in the \Sli command it works:

\documentclass[aspectratio=169]{beamer} %. Aspect Ratio 16:9
\usetheme{theme}

\begin{document}
\begin{frame}[fragile]
\begin{minted}{python}
import numpy as np
\end{minted}
\end{frame}
\end{document}


Any thoughts on how I can fix the \Sli command definition to make it work?

• Maybe a bit late, but IMHO, it is not a good practice to wrap frames inside a command or an environment. – BambOo May 8 '20 at 21:04