I write lecture notes and beamer slides using lots of macros containing math expressions. I'd like to be able to format conditional on whether or not I'm running beamer. So I've written conditional code using a \newif statement, which works except when I want to include formatting characters like \\ and &, in which case beamer throws an error. Here's sample code: There are three \ifThenBeamer lines of code: the first two throw the same error, i.e.,
! Missing } inserted.
<inserted text>
}
l.40 \end{frame}
The third line is fine.
\documentclass{beamer}
\newif\ifConditionOnBeamer
\makeatletter
\def\isConditionOnBeamer#1{
\ifnum\pdf@strcmp{\useBeamer}{#1}=0
\ConditionOnBeamertrue
\else
\ConditionOnBeamerfalse
\fi
}
\makeatother
\def\useBeamer{on}
\def\BeamerOn{\isConditionOnBeamer{on}}
\def\BeamerOff{\isConditionOnBeamer{off}}
\def\ifThenBeamer#1#2{
\ifConditionOnBeamer
{#1}
\else
{#2}
\fi
}
\BeamerOn
\begin{document}
\begin{frame}
\begin{align}
\ifThenBeamer{a \\ b}{c d} %This throws a Missing } inserted error
\ifThenBeamer{a & b}{c d}%This throws a Missing } inserted error
\ifThenBeamer{a b}{c d}
\end{align}
\end{frame}
\end{document}
Could somebody please explain why the error is being thrown, and how to fix it? Or else a workaround if it's unfixable?
Thanks!
alignblocks (the first appropriate for the "on" and the second for the "off" condition), and put these into the two branches of\ifThenBeamer, that should work. – barbara beeton Mar 25 '16 at 20:05