1

I would like to use the same Latex source file for both my document and the accompanying slides.

When creating a document it's easy to hide the slide sections by doing this:

\newcommand{\slide}[1]{}

However, how do I do the inverse, i.e. How can I only generate the slides and hide the rest of the document if I want to print only my slides? Basically I want to say, if the content does not fall in a slide area, then don't show it.

Unfortunately I don't have a simple example to show, because I honestly don't know where to start.

Jack
  • 1,025
  • Are you aware of the Beamer feature to generate notes and slides in one document? A while ago I created a blog article on this (in German) http://uweziegenhagen.de/?p=1053 – Uwe Ziegenhagen Oct 14 '14 at 07:23
  • It seems like, in your situation, you would have to construct the entire document by wrapping things in environments, conditionals, or macros. – Werner Oct 14 '14 at 14:20
  • Thanks guys, I'll sniff around a bit more. If I come up with a good solution, I'll post it here. – Jack Oct 15 '14 at 09:35
  • @JacobusR: Was my solution of any help? – Peter Grill Oct 20 '14 at 22:30
  • Oh yes! Thank you @PeterGrill. Just tried it now and it works like a charm! – Jack Oct 22 '14 at 09:32

1 Answers1

2

One way to do this would be to use the environ package to save the \BODY of the document into a \savebox which saves the text passed to the \Slide macro in a list and output the list at the end. The following

\begin{document}
  abc
  \Slide{Slide 1 content}
  ghi
  \Slide{Slide 2 content}
  jkl
\end{document}

yields:

enter image description here

References:

Code:

\documentclass{article}
\usepackage{environ}

%% -------------------------- \newsavebox{\DiscardedText} \newcommand{\Slide}[1]{} \newcommand{\SavedSlideText}{} \newcommand\AddToSavedSlideText[1]{\xdef\SavedSlideText{\SavedSlideText#1\endgraf}} \NewEnviron{GobbleExceptForSlide}{% \renewcommand{\Slide}[1]{\AddToSavedSlideText{##1}}% \savebox{\DiscardedText}{\BODY}% \SavedSlideText% }% \AtBeginDocument{\GobbleExceptForSlide} \AtEndDocument{\endGobbleExceptForSlide} %% --------------------------

\begin{document}

abc

\Slide{Slide 1 content}

ghi

\Slide{Slide 2 content}

jkl \end{document}

Peter Grill
  • 223,288
  • I've tried this approach in my documents, but found I get other errors when trying to group my environments. There is a new question in this regard, and I will value your opinion: http://tex.stackexchange.com/q/209258/35071 – Jack Oct 27 '14 at 10:04