7

I ran onto this error today, here is a minimum example:

\documentclass[]{beamer}

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

\begin{frame}  
\frametitle{Cursed frame}
This is awkward.
\end{frame}

\end{document}

The compilation gives: Undefined control sequence. [\end{frame}] Apparently declaring a subsection without a section causes the error to appear as removing the comment, makes the error go way.

What also is weird is that despite the error, the .pdf is produced fine in both cases. I'd like to know why this happens, as in other documents having subsections without section never was a problem. Is it a bug or a feature?

9

As Joseph Wright has mentioned in his comment, the fact that sectional units have to be appropriately nested is a design choice made by Till Tantau.

The "culprit" of the error you got can be found in the following lines of the definition of \beamer@subsection (given in beamerbasesection.sty) used by \subsection:

    \Hy@writebookmark{\the\c@subsection}{#2}{Outline\the\c@part.\the\c@section.\the\c@subsection.\the\c@page}{3}{toc}%

Using the original definition and commenting out the mentioned lines, suppresses the error:

\documentclass[]{beamer}

\makeatletter
\def\beamer@subsection[#1]#2{%
  \beamer@savemode%
  \mode<all>%
  \ifbeamer@inlecture%
    \refstepcounter{subsection}%
    \beamer@ifempty{#2}{\long\def\subsecname{#1}\long\def\lastsubsection{#1}}
    {%
      \long\def\subsecname{#2}%
      \long\def\lastsubsection{#1}%
      \addtocontents{toc}{\protect\beamer@subsectionintoc{\the\c@section}{\the\c@subsection}{#2}{\the\c@page}{\the\c@part}{\the\beamer@tocsectionnumber}}%
    }%
    \beamer@tempcount=\c@page\advance\beamer@tempcount by -1%
    \addtocontents{nav}{%
      \protect\headcommand{\protect\beamer@subsectionentry{\the\c@part}{\the\c@section}{\the\c@subsection}{\the\c@page}{\lastsubsection}}%
      \protect\headcommand{\protect\beamer@subsectionpages{\the\beamer@subsectionstartpage}{\the\beamer@tempcount}}%
    }%
    \beamer@subsectionstartpage=\c@page%
    \edef\subsectionlink{{Navigation\the\c@page}{\noexpand\subsecname}}%
    \def\insertsubsection{\expandafter\hyperlink\subsectionlink}%
    \def\insertsubsubsection{}%
    \def\insertsubsectionhead{\hyperlink{Navigation\the\c@page}{#1}}%
    \def\insertsubsubsectionhead{}%
    %\Hy@writebookmark{\the\c@subsection}{#2}{Outline\the\c@part.\the\c@section.\the\c@subsection.\the\c@page}{3}{toc}%
    \hyper@anchorstart{Outline\the\c@part.\the\c@section.\the\c@subsection.\the\c@page}\hyper@anchorend%
    \beamer@ifempty{#2}{\beamer@atbeginsubsections}{\beamer@atbeginsubsection}%
  \fi%
  \beamer@resumemode}
\makeatother
\begin{document}
\section{A section}
\subsection{A subsection}

\begin{frame}  
\frametitle{Cursed frame}
This is awkward.
\end{frame}

\end{document}

but this, of course, it's not advisable since it will mess up the bookmarks.

Another way of preventing the error is to load the bookmark package:

\documentclass[]{beamer}
\usepackage{bookmark}

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

\begin{frame}  
\frametitle{Cursed frame}
This is awkward.
\end{frame}

\end{document}

However, the best thing to do is not to use a subsection without a previous section (using a subsection without section doesn't make much sense, anyways).

5
  • 1
    Indeed: Till's attitude on this sort of thing is quite clear if you read the code. Sections are only really supported by beamer if properly nested, and while \subsubsection is defined it's not really fully implemented as Till didn't want people to use it!
    – Joseph Wright
    Apr 11 '14 at 14:25
  • @JosephWright in some minutes I'll add some remarks along the lines of your comment to my answer. Apr 11 '14 at 16:26
  • I think that this covers my question thank you. Indeed it does not make sense using subsections without sections in beamer. I arrived at the situation because I commented out part of my slides to avoid compilation. Apr 11 '14 at 16:56
  • @VagelisBebelis I've added some new information to my answer that could be of interest for you. Apr 11 '14 at 22:24
  • Yes, I saw it, now my question is completely answered! Thanks once more. Apr 12 '14 at 11:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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