# Beamer template problem: flushright frame subtitle causes spurious extra slide (or worse!)

So here is a MWE that illustrates the problem.

\documentclass{beamer}
\defbeamertemplate{frametitle}{weird}{%
\insertframetitle\par%
\rule{\textwidth}{4pt}%
\flushright%
\insertframesubtitle\par%
}
\setbeamertemplate{frametitle}[weird]
\begin{document}
\begin{frame}
\frametitle{Here is the title}
%\framesubtitle{Here is the subtitle}
Here is the text
\pause
Here is more text
\end{frame}
\end{document}


This code fails with a:

! LaTeX Error: Something's wrong--perhaps a missing \item.


Commenting out the \pause or \flushright or uncommenting the \framesubtitle allows it to compile. [Commenting out the \pause leads to a spurious empty page at the end.]

So my guess is that this is a "wrong mode" problem when the subtitle is empty. But I don't know enough to fix it. Any clues? Or any hints on what to try in order to fix it?

-

where is the sense to use the two macros instead of using the arguments of frame? This works:

\begin{frame}{Here is the title}{Here is the subtitle}


you should also check for an existing subtitle:

\documentclass{beamer}
\makeatletter
\defbeamertemplate{frametitle}{weird}{%
\insertframetitle\par%
\rule{\textwidth}{4pt}%
\ifx\insertframesubtitle\@empty\else
\flushright%
\insertframesubtitle\par\fi}
\makeatother
\setbeamertemplate{frametitle}[weird]
\begin{document}
\begin{frame}{Here is the title}{}
Here is the text
\pause
Here is more text
\end{frame}
\end{document}

-
\begin{frame}{Title}{} breaks. –  Seamus Oct 11 '11 at 11:51
So does \begin{frame}{Title} (i.e. just the one extra argument. As for why use these macros? I read somewhere they are more robust, and I think they're more semantic. [Also, emacs does them automatically...] –  Seamus Oct 11 '11 at 11:53
see edit for handling a missing subtitle –  Herbert Oct 11 '11 at 11:58
Thanks! So it is a problem with TeX not liking to \flushright an empty paragraph, right? Why is this? –  Seamus Oct 11 '11 at 12:25
I suppose a problem with horizontal and vertical mode, but I am not really sure. The code of beamer is not really user friendly ... –  Herbert Nov 2 '11 at 16:41