# Fragile and newenvironment

I would like to have the title and the subtitle of my beamer slides to be the "current" section and subsection respectively - just like in the following example:

\documentclass{beamer}

\newenvironment{fr}{
}{
\end{frame}
}

\begin{document}
\section{A}
\subsection{a}

\begin{fr}
bla
\end{fr}

\subsection{b}
\begin{fr}
blo
\end{fr}

\end{document}


However, when I change the line

\begin{frame}{\insertsectionhead}{\insertsubsectionhead}


to

\begin{frame}[fragile]{\insertsectionhead}{\insertsubsectionhead}


(adding the [fragile]), I get the error "File ended while scanning use of \next". I found out that the solution would usually be not to indent the \end{frame} except that I don't have any control over that in my situation.

It's not the indentation (it was, some time ago, but the code changed so now it is not important). The thing is that when you start a fragile frame, beamer looks for the exact string \ e n d { f r a m e }, which is never found in the file, so you get a File ended error. Even comments after the \end{frame} are not allowed.

However, beamer allows you to define verbatim (fragile) environments with different names as long as you tell it what is that name. For that you use the environment option:

\documentclass{beamer}

\newenvironment{fr}[1][]{%
}{%
\end{frame}
}

\begin{document}
\section{A}
\subsection{a}

\begin{fr}
bla
\end{fr}

\subsection{b}
\begin{fr}[fragile]
\begin{verbatim}
\blo\
\end{verbatim}
\end{fr}

\end{document}