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?

3
  • 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.
    – user194703
    Commented Jun 16, 2020 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. tex.stackexchange.com/questions/545574/…
    – JeT
    Commented Jun 16, 2020 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. Commented Jun 17, 2020 at 3:43

1 Answer 1

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} 

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .