# Is there a way to display a specific command and hide the rest

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.

• 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) uweziegenhagen.de/?p=1053 – Uwe Ziegenhagen Oct 14 '14 at 7: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 9: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 9:32

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:

## Code:

\documentclass{article}
\usepackage{environ}

%% --------------------------
\newcommand{\Slide}[1]{}
\newcommand{\SavedSlideText}{}
\NewEnviron{GobbleExceptForSlide}{%
\SavedSlideText%
}%
\AtBeginDocument{\GobbleExceptForSlide}
\AtEndDocument{\endGobbleExceptForSlide}
%% --------------------------

\begin{document}

abc

\Slide{Slide 1 content}

ghi

\Slide{Slide 2 content}

jkl
\end{document}

• 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: tex.stackexchange.com/q/209258/35071 – Jack Oct 27 '14 at 10:04