Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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?

share|improve this question
add comment

1 Answer 1

up vote 7 down vote accepted

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).

share|improve this answer
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 at 14:25
    
@JosephWright in some minutes I'll add some remarks along the lines of your comment to my answer. –  Gonzalo Medina Apr 11 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. –  Vagelis Bebelis Apr 11 at 16:56
    
@VagelisBebelis I've added some new information to my answer that could be of interest for you. –  Gonzalo Medina Apr 11 at 22:24
    
Yes, I saw it, now my question is completely answered! Thanks once more. –  Vagelis Bebelis Apr 12 at 11:37
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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