I am setting up a template for a presentation on some sort of code. Thus I would like to have an environment that holds a frame (done with \usepackage{environ}
) within which I have a lstlisting environment.
The minimal working example, not defined as a new environment would be the following:
\documentclass{beamer}
\usepackage{listings}
\begin{document}
\begin{frame}[fragile]
\begin{center}
\begin{minipage}{0.9\linewidth}
\begin{lstlisting}
for i=1:2:10
do something
end
\end{lstlisting}
\end{minipage}
\end{center}
\end{frame}
\end{document}
Now what I would like to achieve is something like this:
\NewEnviron{TFListing}[1][]{
\begin{frame}[fragile]{#1}
\begin{center}
\begin{minipage}{0.9\linewidth}
\begin{lstlisting}
\BODY
\end{lstlisting}
\end{minipage}
\end{center}
\end{frame}
}
Which I could then use as:
\begin{TFListing}[Title]
for i=1:2:10
do something
end
\end{TFListing}
However, the main problem is that latex does not allow reading the \BODY
argument signalizing the content of the newly defined environment, since it is escaped by the \begin{lstlisting}
. The benefit of such an environment would be that about eight lines of code per frame could be spared.
Thanks for all of your help in advance.
\NewEnviron
you lose line breaks, for instance; but the most important aspect is that the contents is absorbed as the argument to a command, solistings
can no longer do its job. – egreg Feb 4 '18 at 21:28