3

(This is a follow-up to a previous question that recieved an answer, but raised a new issue that is presented here)

Goal

Given that (as far as I know) Beamer doesn't provide a way to include only a specific \part, I try to do it myself.

So if there's actually a way to do that 'naturally', all the following discussion is useless.

What I've done so far

To do that, I built a dynamic way to assign labels to my frames. So every frame has the option [labe=\partName]. I set the content of this variable with \defPartName{partX}, and change it before every new part. So when I call the command \includeonlyframes{partX}, all the frames of the chapter X, and only them, will be displayed.

It works quite well for a standard usage of the frames. Except that I also built a customized frame to introduce the chapter.

And the two codes don't seem to be compatible.

The issue

In order to assign dynamic labels to my frames (with the option [label=\partName], I have to add the option fragileto the frames. It works for a standard frame, but not for the one inside the macro of the Chapter Frame.

If you compile the following code, it will work, but since you active the line \includeonlyframes{firstChapter}, it crashes.

\documentclass{beamer}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Code for the dynamic labels
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newcommand{\partName}{blank}
\newcommand {\defPartName}[1]{\renewcommand{\partName}{#1}}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Code for the customized chapter frame
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\AtBeginPart{\begingroup
\advance\textwidth-2cm 
\hsize\textwidth
\columnwidth\textwidth
\begin{frame}[fragile, plain, label=\partName]
\begin{block}{}
\begin{center}
  \Huge Chapitre  \thepart \\
    \vspace{.5cm}
  \Large \insertpart
\end{center}
  \end{block}
  \tableofcontents
\end{frame}
\endgroup} 



%\includeonlyframes{firstChapter}
\begin{document}

\defPartName{firstChapter}
\part{first Part}
\begin{frame}[fragile,label=\partName]{A title}
The label of the current frame is \partName .
\end{frame}

\defPartName{secondChapter}
\begin{frame}[fragile,label=\partName]{A title}
The label of the current frame is \partName .
\end{frame}


\end{document}

If I remove the fragileor the label option to the Chapter Frame, it works again, it displays the intended frames, but the chapter frame is not shown.

My question(s)

Any idea how to make this code work? Or eventually any alternative to this code?

13
  • How is this related to/different from your earlier question: tex.stackexchange.com/questions/158964/… ? It might be worth referencing it in your question as a follow-up. – Steven B. Segletes Feb 7 '14 at 17:09
  • Yeah it's exactly a follow up, but given that the initial issue was solved (and the new issue is due to another macro), I thought it was worth creating a new discussion. And I give the link to the previous discussion in this post. I may be wrong though. – BonyHoax Feb 7 '14 at 17:15
  • There is no problem with follow ups. It is, however, generally helpful to reference the earlier question, so as to get the readers in the right frame of mind as to where you are heading. – Steven B. Segletes Feb 7 '14 at 17:26
  • Ok but I thought I did by indicating the link to the previous feed in my post. Should I have been more specific (by indicating it on the first line)? – BonyHoax Feb 7 '14 at 17:31
  • My bad. I missed it because you changed the name of the link when posting it here. Sorry. Ya' done good. – Steven B. Segletes Feb 7 '14 at 17:32
2

One solution might be to use lectures rather than parts. The advantage of this is that beamer already has commands to selectively include lectures. Moreover, you do not need to use fragile or to define custom commands such as \defPartName. Not that it is bad to do that but it is easier if you don't have to.

This solution allows you to obtain

Only the first lecture

by using \includeonlylecture{firstChapter} or

Both/All lectures

by commenting the command out. It should work pretty much as the command you are trying to create would work, if I've understood correctly.

Here is the code:

\documentclass{beamer}

\AtBeginLecture{\begingroup% use \AtBeginLecture rather than \AtBeginPart
\advance\textwidth-2cm
\hsize\textwidth
\columnwidth\textwidth
\begin{frame}[plain]% no need to label the frame, so no need for fragile
  \begin{block}{}
    \begin{center}
      \Huge Chapitre  \thelecture \\% use \thelecture rather than \thepart
        \vspace{.5cm}
      \Large \insertlecture% use \insertlecture rather than \insertpart
    \end{center}
  \end{block}
  \tableofcontents
\end{frame}
\endgroup}


\includeonlylecture{firstChapter}% to produce only the first lecture
\begin{document}

\lecture{First Lecture}{firstChapter}
\part{First Part}% you can use parts within lectures, if you wish
\begin{frame}{A title}
This frame needs no label as it is part of Lecture \thelecture, \insertlecture.
\end{frame}

\lecture{Second Lecture}{secondChapter}
\begin{frame}{A title}
This frame needs no label as it is part of Lecture \thelecture, \insertlecture.
\end{frame}


\end{document}
6
  • Thank you for this solution! But can you tell me if there are other differences/consequences between the 'article' mode and the 'standard' mode? – BonyHoax Feb 8 '14 at 16:03
  • @BonyHoax What do you mean exactly? This will work for either mode just like the other things in beamer. Sorry, I don't mean to be obtuse but I don't quite understand what you are getting at. – cfr Feb 8 '14 at 19:50
  • My bad, I read your code too quickly. Actually, after reading the doc about the 'article' possibilities, I thought it was a general set up for the beamer presentation, that would have consequences on the whole code. It seems that it's not the case, so forget my question :) – BonyHoax Feb 12 '14 at 10:39
  • @BonyHoax Using article would affect the entire document. But using lecture is just a way of organising the document into different sections, whether you are in article mode or not. So what I've done is really just a matter of how it is organised. Using article mode would get you very different output, though, which would not be suitable for display on screen. I think maybe you are confusing article and lecture but they things of different kinds: article is a mode (cf. beamer, handout, presentation etc.) whereas lecture is a sectioning command (cf. part, section` etc.) – cfr Feb 12 '14 at 21:57
  • 1
    @BonyHoax Ah, OK. Now it makes sense. I was just confused by your question - I even double-checked that I didn't include the word 'article' somewhere by mistake! All's well. – cfr Feb 13 '14 at 1:40
1

It is not clear to me what you are trying to do and why you have fragile frames everywhere. You cannot place a fragile frame as an argument to a macro so your MWE does not work. You do not need to use a fragile frame to define dynamic labels, you just need to get the expansion correct. As long as your "part" frame does not need to be fragile the following MWE does what I think you are trying to accomplish

\documentclass{beamer}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Code for the customized chapter frame
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\makeatletter
\AtBeginPart{
\edef\partName{\beamer@partname}
\begingroup
\advance\textwidth-2cm 
\hsize\textwidth
\columnwidth\textwidth
\def\@tempa{\begin{frame}[plain, label=}
\expandafter\@tempa\partName]
\begin{block}{}
\begin{center}
  \Huge Chapitre  \thepart \\
    \vspace{.5cm}
  \Large \insertpart
\end{center}
  \end{block}
  \tableofcontents
\end{frame}
\endgroup} 
\makeatother


\includeonlyframes{firstChapter}
\begin{document}

\part{firstChapter}
\def\temp{\begin{frame}[label=}
\expandafter\temp\partName]{A title}
The label of the current frame is \partName .
\end{frame}

\begin{frame}[fragile,label=\partName]{B title}
The label of the current frame is \partName .
\end{frame}

\part{secondChapter}
\def\temp{\begin{frame}[label=}
\expandafter\temp\partName]{C title}
The label of the current frame is \partName .
\end{frame}
\begin{frame}[fragile,label=\partName]{D title}
The label of the current frame is \partName .
\end{frame}


\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.