I added a switch that allows you to input sections via
```
\CourseInput[sections]{03_02,01_01}
```
The older commands
```
\CourseInput{one,two}
```
continue to work as usual. I personally like the fact that with pgf keys one can very often upgrade macros without losing backwards compatibilty. Of course, one could also require the user to add a switch for the course collections, but at the moment I do not see why.
```
\documentclass{beamer}
\usetheme{Copenhagen}
\setbeamercolor{lecture in toc}{parent=structure}
\usepackage{pgffor}
\usepackage{totcount}
\regtotcounter{part}
\begin{filecontents}[overwrite]{sec01_01.tex}
\section{Section 1}
\subsection{Subsection 1a}
\frame{}
\subsection{Subsection 1b}
\frame{}
\subsection{Subsection 1c}
\frame{}
\end{filecontents}
\begin{filecontents}[overwrite]{sec01_02.tex}
\section{Section 2}
\frame{}
\end{filecontents}
\begin{filecontents}[overwrite]{Lecture1.tex}
\lecture{Lecture1}{lec1}
\input{sec01_01.tex}
\input{sec01_02.tex}
\end{filecontents}
\begin{filecontents}[overwrite]{sec02_01.tex}
\section{Section 1}
\subsection{Subsection 1a}
\frame{}
\subsection{Subsection 1b}
\frame{}
\subsection{Subsection 1c}
\frame{}
\end{filecontents}
\begin{filecontents}[overwrite]{sec02_02.tex}
\section{Section 2}
\subsection{Subsection 2a}
\frame{}
\end{filecontents}
\begin{filecontents}[overwrite]{Lecture2.tex}
\lecture{Lecture2}{lec2}
\input{sec02_01.tex}
\input{sec02_02.tex}
\end{filecontents}
\begin{filecontents}[overwrite]{sec03_01.tex}
\section{Section 1}
\subsection{Subsection 1a}
\frame{}
\subsection{Subsection 1b}
\frame{}
\subsection{Subsection 1c}
\frame{}
\end{filecontents}
\begin{filecontents}[overwrite]{sec03_02.tex}
\section{Section 2}
\subsection{Subsection 2a}
\frame{}
\end{filecontents}
\begin{filecontents}[overwrite]{Lecture3.tex}
\lecture{Lecture3}{lec3}
\input{sec03_01.tex}
\input{sec03_02.tex}
\end{filecontents}
\makeatletter
\AtBeginLecture{%
\mode<beamer>{
\part{\beamer@lecturename}
\expandafter\NR@gettitle\expandafter{\beamer@lecturename}
\label{part:\thelecture}
\begin{frame}
\begin{beamercolorbox}[sep=16pt,center]{part title}
{\Large\textsc{Lecture}\par}
{\large\insertpart\par}
\end{beamercolorbox}
\tableofcontents
\end{frame}
}
\beamer@tocsectionnumber=0
}
\newif\ifpgf@course@union
\pgfkeys{/courses/.cd,union/.is if=pgf@course@union,union/.default=true}
\pgf@course@uniontrue
\newcommand{\CourseInput}[2][]{%
\pgfkeys{/courses/.cd,#1}%
\ifpgf@course@sections
\pgfutil@for\pgfutil@tmpa:={#2}\do{%
\input{sec\pgfutil@tmpa.tex}}%
\pgf@course@sectionsfalse
\else
\let\pgfutil@tmpc\relax
\pgfutil@for\pgfutil@tmpa:={#2}\do{%
\ifx\pgfutil@tmpc\relax
\edef\pgfutil@tmpc{\pgfkeysvalueof{/courses/\pgfutil@tmpa}}%
\else
\edef\pgfutil@tmpc{\pgfutil@tmpc,\pgfkeysvalueof{/courses/\pgfutil@tmpa}}%
\fi
}%
\ifpgf@course@union
\pgfmathtruncatemacro{\pgfutil@tmpd}{min(\pgfutil@tmpc)}%
\pgfmathtruncatemacro{\pgfutil@tmpe}{max(\pgfutil@tmpc)}%
\edef\pgfutil@tmpb{\pgfutil@tmpd}%
\c@pgf@counta\pgfutil@tmpd%
\pgfutil@loop
\advance\c@pgf@counta by1\relax
\edef\pgfutil@tmpf{\noexpand\pgfutil@in@{,\the\c@pgf@counta,}{\pgfutil@tmpc}}%
\pgfutil@tmpf
\ifpgfutil@in@%
\edef\pgfutil@tmpb{\pgfutil@tmpb,\the\c@pgf@counta}%
\fi
\ifnum\c@pgf@counta<\pgfutil@tmpe
\pgfutil@repeat
\else
\edef\pgfutil@tmpb{\pgfutil@tmpc}%
\fi
\pgfutil@for\pgfutil@tmpa:={\pgfutil@tmpb}\do{%
\input{Lecture\pgfutil@tmpa.tex}}%
\fi
}%
\makeatother
\title{Some Title}
\pgfkeys{/courses/.cd,
one/.initial={1,2},
two/.initial={2,5},
three/.initial={3}}
%It's probably here I need to have more granulartity but
%/courses/Lecture1.cd,
%/courses/Lecture2.cd, but I am still walking on eggs with keys.
\begin{document}
\begin{frame}
\tableofcontents
\foreach\x in {1,...,\totvalue{part}}{%
\vskip-0.4cm
\protect\usebeamercolor[fg]{lecture in toc}%
\vfill%
\hyperlink{part:\x}{\nameref{part:\x}}%
\tiny\tableofcontents[part=\x]%
}%
\end{frame}
%\CourseInput{one,two}
%\CourseInput[union=false]{one,two}
\CourseInput[sections]{03_02,01_01} % section switch added
\end{document}
```
Here is a second possibility in which you can define collections in an a bit more structured way,
```
\pgfkeys{/courses/.cd,
lectures/.cd,
9hCourse/.initial={1,2,3},
6hCourse/.initial={2,3},
/courses/sections/.cd,
3hSeminar/.initial={03_02,01_01}}
```
and can then use something of the sort
```
\CourseInput{9hCourse,3hSeminar,03_02}
```
The code will figure out that `9hCourse` is a collection of lectures (because you stored it in the `lectures` directory), `3hSeminar` is a collection of sections (because you stored it under `sections`) and then make the following checks:
1. is it a collection of lectures, i.e. can the key be found in the lecture directory?
2. is it a collection of section, i.e. can the key be found in the sections directory?
3. is the key a lecture, i.e. can a file with name `Lecture<key>.tex` be found?
4. is the key a section, i.e. can a file with name `sec<key>.tex` be found?
If none of this applies, a warning will be issued. If you set `union` to be true, duplicated **input** files will be eliminated, but this does not prevent duplicate files from being loaded when you load a section that is already contained in a lecture. Also overlapping lectures won't be eliminated. This is because the code does not look into the contents of the lecture files.
This is the corresponding code:
```
\documentclass{beamer}
\usetheme{Copenhagen}
\setbeamercolor{lecture in toc}{parent=structure}
\usepackage{pgffor}
\usepackage{totcount}
\regtotcounter{part}
\begin{filecontents}[overwrite]{sec01_01.tex}
\section{Section 1}
\subsection{Subsection 1a}
\frame{}
\subsection{Subsection 1b}
\frame{}
\subsection{Subsection 1c}
\frame{}
\end{filecontents}
\begin{filecontents}[overwrite]{sec01_02.tex}
\section{Section 2}
\frame{}
\end{filecontents}
\begin{filecontents}[overwrite]{Lecture1.tex}
\lecture{Lecture1}{lec1}
\input{sec01_01.tex}
\input{sec01_02.tex}
\end{filecontents}
\begin{filecontents}[overwrite]{sec02_01.tex}
\section{Section 1}
\subsection{Subsection 1a}
\frame{}
\subsection{Subsection 1b}
\frame{}
\subsection{Subsection 1c}
\frame{}
\end{filecontents}
\begin{filecontents}[overwrite]{sec02_02.tex}
\section{Section 2}
\subsection{Subsection 2a}
\frame{}
\end{filecontents}
\begin{filecontents}[overwrite]{Lecture2.tex}
\lecture{Lecture2}{lec2}
\input{sec02_01.tex}
\input{sec02_02.tex}
\end{filecontents}
\begin{filecontents}[overwrite]{sec03_01.tex}
\section{Section 1}
\subsection{Subsection 1a}
\frame{}
\subsection{Subsection 1b}
\frame{}
\subsection{Subsection 1c}
\frame{}
\end{filecontents}
\begin{filecontents}[overwrite]{sec03_02.tex}
\section{Section 2}
\subsection{Subsection 2a}
\frame{}
\end{filecontents}
\begin{filecontents}[overwrite]{Lecture3.tex}
\lecture{Lecture3}{lec3}
\input{sec03_01.tex}
\input{sec03_02.tex}
\end{filecontents}
\makeatletter
\AtBeginLecture{%
\mode<beamer>{
\part{\beamer@lecturename}
\expandafter\NR@gettitle\expandafter{\beamer@lecturename}
\label{part:\thelecture}
\begin{frame}
\begin{beamercolorbox}[sep=16pt,center]{part title}
{\Large\textsc{Lecture}\par}
{\large\insertpart\par}
\end{beamercolorbox}
\tableofcontents
\end{frame}
}
\beamer@tocsectionnumber=0
}
\newif\ifpgf@course@union
\pgfkeys{/courses/.cd,union/.is if=pgf@course@union,union/.default=true}
\pgf@course@uniontrue
\newif\ifpgf@course@sections
\pgfkeys{/courses/.cd,sections/.is if=pgf@course@sections,sections/.default=true}
\pgf@course@sectionsfalse
\pgfkeys{/courses/.cd,input/.code={%
\let\pgfutil@tmpc\relax
\def\pgfutil@tmp@append##1{\ifx\pgfutil@tmpc\relax
\edef\pgfutil@tmpc{##1}%
\else
\edef\pgfutil@tmpc{\pgfutil@tmpc,##1}%
\fi}%
\pgfutil@for\pgfutil@tmpa:={#1}\do{%
\typeout{Checking \pgfutil@tmpa.}%
% is this a collection of lectures?
\ifcsname pgfk@/courses/lectures/\pgfutil@tmpa\endcsname
\edef\pgfutil@tmpb{\pgfkeysvalueof{/courses/lectures/\pgfutil@tmpa}}%
\pgfutil@for\pgfutil@tmpd:={\pgfutil@tmpb}\do{%
\pgfutil@tmp@append{Lecture\pgfutil@tmpd.tex}}%
\else
% is this a collection of sections?
\ifcsname pgfk@/courses/sections/\pgfutil@tmpa\endcsname
\edef\pgfutil@tmpb{\pgfkeysvalueof{/courses/sections/\pgfutil@tmpa}}%
\pgfutil@for\pgfutil@tmpd:={\pgfutil@tmpb}\do{%
\pgfutil@tmp@append{sec\pgfutil@tmpd.tex}}%
\else
% % is this a lecture?
\IfFileExists{Lecture\pgfutil@tmpa.tex}{%
\pgfutil@tmp@append{Lecture\pgfutil@tmpa.tex}%
}{% is this a section?
\IfFileExists{sec\pgfutil@tmpa.tex}{%
\pgfutil@tmp@append{sec\pgfutil@tmpa.tex}%
}{%
\typeout{Could not make sense of \pgfutil@tmpa.}%
}%
}%
\fi
\fi
}%
\ifpgf@course@union
\edef\pgfutil@tmpd{\pgfutil@tmpc}%
\edef\pgfutil@tmpe{,\pgfutil@tmpc,}%
\let\pgfutil@tmpc\relax
\pgfutil@for\pgfutil@tmpa:={\pgfutil@tmpd}\do{%
\edef\pgfutil@tmpf{\noexpand\pgfutil@in@{,\pgfutil@tmpa,}{\pgfutil@tmpc}}%
\pgfutil@tmpf
\pgfutil@tmp@append{\pgfutil@tmpa}%
}%
\fi
\pgfutil@for\pgfutil@tmpa:={\pgfutil@tmpc}\do{%
\input{\pgfutil@tmpa}}%
}}
\makeatother
\newcommand{\CourseInput}[2][]{\begingroup%
\pgfkeys{/courses/.cd,#1}%
\pgfkeys{/courses/input={#2}}%
\endgroup}%
\title{Some Title}
\begin{document}
\begin{frame}
\tableofcontents
\foreach\x in {1,...,\totvalue{part}}{%
\vskip-0.4cm
\protect\usebeamercolor[fg]{lecture in toc}%
\vfill%
\hyperlink{part:\x}{\nameref{part:\x}}%
\tiny\tableofcontents[part=\x]%
}%
\end{frame}
\pgfkeys{/courses/.cd,
lectures/.cd,
9hCourse/.initial={1,2,3},
6hCourse/.initial={2,3},
/courses/sections/.cd,
3hSeminar/.initial={03_02,01_01}}
\CourseInput{9hCourse,3hSeminar,03_02}
\end{document}
```