I am currently using Beamer and the listing package to pretty-print code into Beamer blocks. So what I'm doing looks like :
\begin{block}{}
\begin{lstlisting}
int foobar(void) { return 0; }
\end{lstlisting}
\end{block}
Now, I find it cumbersome to start the block
and lstlisting
environments everytime. I'd like to have a simple codeblock
environment that just does it:
\begin{codeblock}
int foobar(void) { return 0; }
\end{codeblock}
So, I tried something like :
\lstnewenvironment{codeblock}
{\begin{block}{}}
{\end{block}}
But unfortunately, the Beamer document no longer compiles, with the following error:
! Missing } inserted.
<inserted text>
}
l.178 \end{frame}
?
Is there some way to do this ?
In Problem with creating a newenvironment in LaTeX, Andreas Grech had the same problem, but it could solve it since there was another way to enter/exit the enclosing environment. But in the case of the block
Beamer environment, it seems there is no other way than doing \begin{block}...\end{block}
.
\begin{tabular}{...}
and\end{tabular}
, but problem is solved using the TeX style\tabular{...}
and\endtabular
. I have no idea why (I thought both forms were strictly equivalent). Unfortunately, this does not seem to be applicable to beamer'sblock
environment. – Ergograph