Indentation eliminated when using listings in beamer

There is a nice post addressing this issue from stackoverflow. Below is a copy:

That cannot work, because fragile material has to written into an external temporary file and then read back by beamer. The tabs get lost here. Use it this way:

\documentclass[dvipsnames,cmyk]{beamer}
\usepackage{listings}
\begin{document}
\defverbatim[colored]\Lst{%
\begin{lstlisting}[tabsize=2,showtabs,frame=single]
using System;
publid delegate void Foo(object o);
\end{lstlisting}}
\begin{frame}[allowframebreaks]{MyListing}
\Lst
\end{frame}
\end{document}
Reference: http://stackoverflow.com/questions/3106419/center-latex-lstlisting
Indentation eliminated when using listings in beamer

An extra ‘}’??

We need to be a bit more careful about typesetting in section/caption.

I was trying to include a pseudo code under algorithm2e style in a poster created using beamerposter, as listed below.

\begin{algorithm}
 \caption{\textbf{buffer}}
 }
\end{algorithm}
Then I received some weird error messages:
./WenxiangChen-CS560-poster.tex:215: Argument of \@caption has an extra }.<inserted text>
 \par
l.215 \end{frame}

I found that this something relative to the fragile command. I forced the command in \caption to be robust by prefixing it with \protect. Now the compilation goes smoothly. 🙂

\begin{algorithm}
 \caption{\protect \textbf{buffer}}
 }
\end{algorithm}

Reference: http://www.tex.ac.uk/cgi-bin/texfaq2html?label=extrabrace

An extra ‘}’??