Substitute \chapter in Book with \lecture in Beamer

The question

How can we "translate" automatically chapters in book to lectures in Beamer to avoid the legitimate Undefined control sequence \chapter when compiling a presentation ?

The context

I have a very long presentation (~ 2000 frames) splitted in 20 lectures. Thanks to a beamerarticle and if 0\Article \documentclass{article} else \documentclass{beamer} at the beginning of my code, I manage to have a good process to compile, either in a form of an article or in a presentation.

My document had the following structure

• Part 1
• Section 1
• Section 2
• etc

It was working very well until I needed to restructure my document and realize a book (with chapters) made more sense.

• Part 1
• Chapter 1
• Section 1
• Section 2
• Chapter 2
• etc

Thanks to Lecture/chapters I understand the right "bridge" from book to Beamer (to avoid errors from Beamer not recognizing \chapters) would be to translate Chapters in book to Lectures in Beamer.

• Part 1
• Chapter 1 => Lecture 1
• Section 1
• Section 2
• Chapter 2 => Lecture 2
• etc

• I don't understand the code if 0\Article \documentclass{article} else \documentclass{beamer}. What is processing it? Not (La)TeX. Why not, in the else portion, include \let\chapter=\lecture? – Donald Arseneau Apr 7 '20 at 9:50
• At the very beginning of the preambule, I defined \def\Article{1}. I decide whether I want an article (\Article{1}) and i load \documentclass{article} or a beamer (\Article{0}) \documentclass{beamer}. It worked well to switch from one to the other since both article and beamer mode have parts but no chapter. As for the \let\chapter=\lecture, does it mean all the \chapter will be interpeted as \lecture in beamer ? As simple as that ? :) – JeT Apr 7 '20 at 10:21
• @DonaldArseneau Would not there be a problem using \let since \lecture{First Lecture}{firstChapter} requires 2 arguments ? – JeT Apr 7 '20 at 10:33

Typing as a comment was too messy. OK, so the document uses \if and \else and \fi, and LaTeX handles it; although the usage seems backwards (you probably meant \if 1\Article for \documentclass{article}).

Yeah, you no-doubt want to type \lecture in the document, and convert it to \chapter, rather than translating chapter => lecture, and not with \let. So

\def\Book{1}% or 0, or use optional.sty!
\if 1\Book
\newcommand\lecture[3][\shortlecname]{%
\def\shortlecname{#2}% default for TOC and header
\chapter[#1]{#2}\label{#3}}
\else
\documentclass{beamer}
\AtBeginLecture{
blah blah a frame like a chapter
}
\fi


Don't use \includeonlylecture. Then, in the document body

\lecture{Exciting stuff}{excite}

• Merci Donald ! the code worked well but after a second compilation I go an ! LaTeX Error: Command \lecture already defined. Also, given the synthax \lecture{Exciting stuff}{excite}, should not it be \newcommand\lecture[3][\shortlecname]{ \def\shortlecname{#2} \chapter[#2]{#1}\label{#3}} ? – JeT Apr 8 '20 at 15:14
• I can't guess where you have a double definition of \lecture. It does not happen in simple tests. And, no, it is \chapter[#1]{#2}\label{#3} That also covers the actual defined syntax with optional arguments (where #1 is the optional short name in both the lecture and the chapter case). I didn't know if you wanted to do anything with the third argument, so I used it for a \label. – Donald Arseneau Apr 8 '20 at 21:10