# How can I use Beamer's \includeonlylecture{} to modify frame title content?

I'm preparing a course lecture in Beamer. Every so often, I prompt students to answer a question on one slide. I use subsequent slides to answer the questions. I include the answer as a part of a sentence in the frame title. I provide students the slides in advance of lecture so some students simply read the answer from the subsequent slide instead of thinking about possible answers.

I know that I can use \includeonlylecture{} to prepare one set of slides for students and a different set for me. I could create two copies of a slide: a student copy with with a blank line for the answer, and an instructor copy with the answer included. That requires me to make two copies of every slide which would get cumbersome if I prompt for several items or when I edit slides in the future.

What I would like is a macro that can determine whether I am \includeonlylecture{} mode is active. If so, then a blank line is drawn. The line is the length of the answer. If \includeonlylecture{} is inactive (commented out), then the answer is printed.

In my MWE below, I've written a macro called \HiddenWord which draws the blank line in place of the answer. I've tried to convert this into an if-then-else construct but to no avail. Beamer has defined variables in beamerbasesection.sty for determining if it is in lectureonly mode that I tried to use. For example, I tried the following macro

\includeonlylecture{student}

\newlength{\myLength}
\makeatletter
\newcommand{\HiddenWord}[1]{%
\ifbeamer@inlecture{
\settowidth{\myLength}{#1}
\rule{\myLength}{0.4pt}
}%
}%
\makeatother


However, this always prints the blank line, whether or not \includeonlylecture{student} is commented out. I do not know how to incorporate an \else statement into this macro or even if \ifbeamer@inlecture is the right variable to check. I have a feeling I may not be too far off the mark but I don't know how to take one of Beamer's existing if macros and use it in on my my macros, or at least determine if Beamer's is T or F, and assign that value to my own variable.

Finally, this has to work when I use when I convert the slides to handouts. That too is included in the preamble but commented out for making the slides.

MWE:

\documentclass[t]{beamer}

%%%% HANDOUTS For online Uncomment the following four lines for handout
%\documentclass[t,handout]{beamer}  %Use this for handouts.
%\usepackage{handoutWithNotes}
%\pgfpagesuselayout{3 on 1 with notes}[letterpaper,border shrink=5mm]
%   \setbeamercolor{background canvas}{bg=black!5}

\includeonlylecture{student}

\newlength{\myLength}

\makeatletter
\newcommand{\HiddenWord}[1]{%
\ifbeamer@inlecture{
\settowidth{\myLength}{#1}
\rule{\myLength}{0.4pt}}}
\makeatother

\begin{document}

\lecture{student}{student}

\begin{frame}[c]{Name two terms about salinity tolerance in fishes.}
1. \rule{4cm}{0.4pt}
\vspace{1cm}

2. \rule{4cm}{0.4pt}
\end{frame}

\begin{frame}[c]{\HiddenWord{Stenohaline} fishes tolerate a narrow salinity range.}
\end{frame}

\begin{frame}[c]{Fishes that are \HiddenWord{euryhaline} tolerate a wide salinity range.}
\end{frame}

\end{document}


This accomplishes what you have asked for, but in another way: Instead of using the \includeonlylecture mechanism, I just use beamer's overlay commands to not print certain content in handout mode:

%\documentclass[t]{beamer}
\documentclass[t,handout]{beamer}

\begin{document}

\begin{frame}[c]{Name two terms about salinity tolerance in fishes.}
1. \rule{4cm}{0.4pt}
\vspace{1cm}

2. \rule{4cm}{0.4pt}
\end{frame}

\begin{frame}[c]{\onslide<handout:0>{Stenohaline} fishes tolerate a narrow salinity range.}
\end{frame}

\begin{frame}[c]{Fishes that are \onslide<handout:0>{euryhaline} tolerate a wide salinity range.}
\end{frame}

\end{document}


This is the result in handout mode (option handout passed to the document class):

Compared to this in beamer mode (no option passed to the document class):

To draw a horizontal line instead of some empty space, we can apply the same trick, but now use beamer's \alt<handout>{true}{false} command to draw a line in handout mode and the original word in all other cases. I have adopted your original interface \HiddenWord{...} here to make this a bit more comfortable:

%\documentclass[t]{beamer}
\documentclass[t,handout]{beamer}

\usepackage{calc} % for the \widthof command

\newcommand\HiddenWord[1]{%
\alt<handout>{\rule{\widthof{#1}}{\fboxrule}}{#1}%
}
\begin{document}

\begin{frame}[c]{Name two terms about salinity tolerance in fishes.}
1. \rule{4cm}{0.4pt}
\vspace{1cm}

2. \rule{4cm}{0.4pt}
\end{frame}

\begin{frame}[c]{\HiddenWord{Stenohaline} fishes tolerate a narrow salinity range.}
\end{frame}

\begin{frame}[c]{Fishes that are \HiddenWord{euryhaline} tolerate a wide salinity range.}
\end{frame}

\end{document}


The result in handout mode looks as follows:

• Yours is a very simple solution to something I tried to make harder. However, I very much would like to have a blank line (\rule) where the answer should be. Is that possible with your method? – Michael S Taylor Sep 14 '14 at 18:11
• @MikeTaylor: Sure, see updated answer. – Daniel Sep 14 '14 at 18:35