Include and exclude latex-beamer frames

Posted by ads' corner on Tuesday, 2009-12-08
Posted in [Tex]

For my slides I sometimes want to disable parts of the presentation, as example: if the operating system is Linux, I don’t need Solaris installation instructions. The \ifthenelse{<condition>}{...true...}{...false...} from the ifthen package works very well for normal frames, but it fails if there are examples (verbatim environment) in the code.

In such a case \iftrue and \iffalse are much more lazy than \ifthenelse and compiling the examples results no longer in LaTeX parser errors. The downside of this solution: I need to predefine the condition, but in my case I have them in a separate file anyway.

The definition looks like:

1
2
3
4
5
6
\newboolean{usesolaris}
\ifthenelse{\equal{\targetos}{solaris}}{
 \setboolean{usesolaris}{true}
}{
 \setboolean{usesolaris}{false}
}

I have defined the variable \targetos, which contains a string with the currently used platform name for my presentation. If the string matches solaris, the boolean \usesolaris is set to true, else to false. LaTeX compiles the \ifusesolaris definition from the boolean, which I later can use to include or exclude frames:

1
2
3
4
5
\ifusesolaris
\begin{frame}[fragile]
 ... frame content
\end{frame}
\fi

In addition, it is also possible to add code for the case where \usesolaris is false. Just add \else and the code before \fi.


Categories: [Tex]