1

I would like to have a switch that detects whether I'm compiling a file as a beamer presentation or as an article, adjusting specific commands for both classes, but having the same content for the single page/slide. Unfortunately, the following code does not work for beamer.

%\documentclass{article}
\documentclass{beamer}

\usepackage{ifthen} \newif\ifbeamer \beamertrue

\begin{document}

\ifbeamer \begin{frame} \else % article \newpage \fi

% common code for both beamer and article blah blah

\ifbeamer \end{frame} \fi

\end{document}

It seems that beamer only accepts to have \begin{frame} and \end{frame} inside single "if" statement. How can I handle this limitation?

  • 6
    Are you aware of all the ways in which beamer supports handouts, and, in particular, the beamerarticle class? It appears to me that you try to achieve a variant thereof, but there are already quite advanced options. –  Jun 16 '20 at 23:00
  • 1
    @martinoidar I had the same type of issue since I produce either long notes or slides. Maybe this could help you to use bemerarticle like Mr Cat mentioned it. https://tex.stackexchange.com/questions/545574/easily-switch-figure-size-from-beamer-to-article-and-vice-versa – JeT Jun 16 '20 at 23:18
  • 1
    I find that "portatble" code winds up having do many if/then/else constructs that it becomes unreadable. I would much rather see separate files for each option, or at least put all the option dependent code in one location. – John Kormylo Jun 17 '20 at 03:43

1 Answers1

2

You could use the beamerarticle package and adjust the frame environment depending on the current mode:

\documentclass{article}
%\documentclass{beamer}
\usepackage{beamerarticle}

\mode<article>{ \AtBeginEnvironment{frame}{\newpage} }

\begin{document}

\begin{frame} % common code for both beamer and article blah blah \end{frame}

\begin{frame} % common code for both beamer and article blah blah \end{frame}

\end{document}