# Can I make a switch-like conditional environment?

I'm writing a running presentation for an entire semester's lecture (with beamer) and would like to make an environment such as

\begin{lecture}{3}
...
\end{lecture}


such that I can have at the top of my document a variable, \thelecture that I can set to a number to compile only the slides of that lecture. (Additionally I'd like to also be able to set it to zero or have some such flag to compile all lectures' slides.)

Usual conditionals don't seem to do the trick. As best as I can tell I will need to combine \ifthenelse with the comment environment.

Is there any elegant solution? Or ideally even already a package made to do this?

• Welcome to TeX.sx! Have you looked at Chapter 10.4 Splitting a Course Into Lectures from the beamer documentation with the \includeonlylecture command? – alpenwasser Apr 28 '17 at 13:52
• @alpenwasser, amazing! I googled basically exactly that phrase and found nothing. Thanks for the info! – DanielGr Apr 28 '17 at 13:54
• Happy to help, and yes, I know the struggle with mighty Google; sometimes it just thinks you want something other than the thing you actually want. Good luck! – alpenwasser Apr 28 '17 at 13:58
• @alpenwasser do you want to post that as an answer? – David Carlisle Oct 5 '18 at 22:18
• @alpenwasser I just meant literally cut and paste your comment into an answer to get this off the list of unanswered questions, it doesn't require an essay:-) – David Carlisle Oct 6 '18 at 20:12

Chapter 10.4, Splitting a Course Into Lectures, in the Beamer documentation might be worth checking out, providing the \includeonlylecture command:

Designate different lectures with the \lecture[<short lecture name>]{<lecture name>}{<lecture label>} command:

\begin{document}
\lecture{Vector Spaces}{week 1}
\section{Introduction}
...
\section{Summary}
\lecture{Scalar Products}{week 2}
\section{Introduction}
...
\section{Summary}
\end{document}


Then do

\includeonlylecture{week 1}


in the preamble of the document.

There's also \AtBeginLecture{<text>}, which will insert arbitrary text at the beginning of every lecture.

\AtBeginLecture{\frame{\Large Today's Lecture: \insertlecture}}


Where \insertlecture{} will provide the lecture name. There's also \insertshortlecture{}, which will do the same thing for the <short lecture name>.