# Defining a macro for making slides from same source document?

It's sloppy, but sometimes I just want to make an existing source document into slides containing exactly the same material, while leaving the original article unaltered. A further ambition would be that edits to the original would also result in changes to the hacked-up slides. I figured some macros would help me here, so I tried something like this:

%\def\NowMakingSlides{1}

\ifdefined\NowMakingSlides
\documentclass[aspectratio=43]{beamer}
\else
\documentclass[oneside, letterpaper,12pt]{amsart}
\fi

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%  Controlling for whether we are hacking up some slides
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\ifdefined\NowMakingSlides
\newcommand{\beginframe}[1]{\begin{frame}\frametitle{#1}}
\newcommand{\Section}[1]{\nextframe{#1}}
\newcommand{\stopframe}{\end{frame}}
\newcommand{\nextframe}[1]{\stopframe\beginframe{#1}}
\else
\newcommand{\Section}{\section}
\newcommand{\beginframe}[1]{}
\newcommand{\stopframe}{{}}
\newcommand{\nextframe}[1]{{}}
\fi

\begin{document}

\beginframe{This Sentence No Verb}
I like writing equations.

\nextframe{The End}
But sometimes I have to stop, even though $e^{i\pi}+1=0$

\stopframe
\end{document}


Note the \Section macro which is supposed to start a new slide title with the given text in places where the article starts a new section. (Similar macros left out of this MWE cover subsection etc.) That greatly reduces the number of spots in which a nextframe even needs to be inserted and keeps slide titles in sync with the article.

It works great for creating the normal document when I comment out the first line, but not when I leave the line in place, with a File ended message. Deleting the macro calls and substituting what I think they are doing gives me a working document. Further investigation shows that the stopframe macro is not working. What's wrong with it?

-
beamer has to parse frame environments specially and it misses your \end{frame}s because they are hidden by other macros. From the description of the frame environment in beameruserguide: "To determine the end of the frame, the following rule is used: The first occurence of a single line containing exactly \end{⟨frame environment name⟩} ends the frame." Read that section for how to change ⟨frame environment name⟩, but note that it must still be an environment, used with \begin and \end, not a macro. I advise using beamer's facilities for your purpose as alexis suggests. –  cyberSingularity Jan 21 '13 at 23:54
@cyberSingularity that makes sense. I think other packages must be more appropriate to my ambitions here. I really don't want something so environmental. –  Brian B Jan 22 '13 at 3:53

Why didn't you just say from the start "I want to change beamer's syntax so that I don't need to explicitly enclose my text in frames" ? Switching between print and slide mode has little to do with your ambitions. So, here's another answer. As @Brian argues, your approach is not likely to work well with beamer. You could go digging through the macros and look for another way to satisfy the syntax, but there are so many different modes (plain frames, [fragile] frames, frames under the [ignorenonframetext]) that I wouldn't even try.

However, beamer will also generate slides from text that's not enclosed text in {frame} environments-- just don't use the [ignorenonframetext] class option! You can use \newpage to separate slides. There are small glitches like \beamer@cramped turning up as an undefined command (which I fixed by setting it to \relax), and probably others you'll discover if you go this route. I haven't tested this thoroughly but it appears to work more or less as you would expect.

Long ago I used pdfscreen. It's much more lightweight, and what's more you don't need to enclose slides in anything-- again, just issue \newpage to start a new slide. I've got a ton of presentations written this way. (The current version provides a {slide} environment, but unless things have changed, you don't actually need to use it). So take your pick.

-
I believe that is the droid I am looking for. Thank you. –  Brian B Jan 22 '13 at 19:03
I just realized that beamer will let you do the same thing. D'uh! Updated my answer. –  alexis Jan 23 '13 at 19:30

Beamer already provides an elaborate framework for generating printed text and slides from the same source, with the some contents the same and some different (or entirely the same if that's what you want). Check out the Beamer User Guide (part IV, "Creating supporting material"). If it doesn't already do everything you want, you can build on that instead of reinventing the wheel.

Since the manual is kind of enormous, here's a simplified example showing just some of the options you have for controlling visibility. It's based on a longer example that appears in the section "Starting the article mode" (p. 205 in the current manual). I've just added the custom \if switch.

\newif\ifscreen
\screentrue % Toggle the mode here

\ifscreen
\documentclass[ignorenonframetext]{beamer}
\else
\documentclass[a4paper]{article}
\usepackage{beamerarticle}
\fi

% Conditional package inclusions with the \mode command:
\mode<article>{\usepackage{fullpage}}
\mode<presentation>{\usetheme{Berlin}}
% everyone:
\usepackage[english]{babel}

\begin{document}
\section{Introduction}
Thanks to the \verb|ignorenonframetext| option, text outside frames is not
shown in the presentation but will be part of the article.

\begin{frame}
This text is part both of the article and of the presentation.

\begin{itemize}
\item This stuff is shown in both versions.
\item This too.
\only<article>{\item This particular item is only part
of the article version.}
\item<article> This text is also only part of the article.
\end{itemize}
\end{frame}
\end{document}


Since you say you want exactly the same text, you won't really care (yet!) about all the conditional visibility bells and whistles. Just wrap your text in frames and you should be all set.

-
Based on your suggestion, I did go into the manual (wow, to page 200!) to find the section on supporting material. The paradigm appears to be that other material is supplementary to slides, rather than the other way around. What I really did -- or tried to do -- was mainly set myself up with a \nextframe macro and then redefine \subsection etc to call it to set slide titles. But of course I was stymied by the environmental behavior. I'm out of ideas on this one after a few hours and going to look for a "dumber" slide package. –  Brian B Jan 22 '13 at 3:51
Did you read on to page 205? I've pasted the relevant example in my answer to make it clearer. –  alexis Jan 22 '13 at 11:48
Thanks for the very clean example. I had read that far, and perhaps I should note that my MWE is a bit too minimal. Additional macros \Section defined in it were set up to call \section if in article mode, and start a new frame with the section title as frame title otherwise. The result was, I hoped, going to allow me to hack up some slides with only a few inserts of \nextframe macro calls. The need to work in environments precludes that hack -- it would appear that if I want slides I will either have to go "full beamer" or get medieval with find/replace. –  Brian B Jan 22 '13 at 13:48