# switching beamer mode with commands

I have a beamer main document which is called by various wrappers and I want to make all \mode-switching dependent from commands defined in the preamble of this wrappers. For normal modes like \mode<presentation> this works fine, but the only way I found to include \mode* in this system was to hack an internal command.

Has someone a better idea to achieve the same goal? And do someone some danger in my redefinition (apart from the general danger to redefine internal commands)?

\documentclass[]{beamer}
\newcommand\secondmode{presentation}
\newcommand\mainmode{*}
\makeatletter
\def\beamer@@@mode<#1>{\if#1*
\expandafter\@firstoftwo
\else
\expandafter\@secondoftwo
\fi
{\beamer@modeoutsideframe}
{\beamer@closer\@ifnextchar\bgroup{\beamer@modeinline<#1>}{\beamer@switchmode<#1>}}}
\makeatother
\begin{document}
\mode
<\mainmode>
some text outside a frame in main mode
\begin{frame}
test in frame in main mode
\end{frame}

\mode
<\secondmode>

some text outside a frame in second mode

\begin{frame}
second mode in a frame
\end{frame}

\mode
<\mainmode>

some text outside a frame

\mode
<all>
\end{document}

-

I don't know beamer well enough to be able to say whether a completely different technique should be used but at least I think you want to change

\if#1*

\if*#1%


as otherwise if the first two letters of the mode name are the same it will expand to true and typeset the remaining letters followed by a *.

In the MWE it is testing the p and r of presentation so it happens to take the right branch, but compare with:

\newcommand\secondmode{ppesentation}

-
Good point. It doesn't matter currently but is naturally cleaner. – Ulrike Fischer Feb 23 '13 at 9:47