2

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}{ 
        \begin{frame}{\insertsectionhead}{\insertsubsectionhead}
    }{
        \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.

3

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][]{%
        \begin{frame}[environment=fr,#1]{\insertsectionhead}{\insertsubsectionhead}
    }{%
        \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}

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.