add tag
JeT
Marmot's solution here https://topanswers.xyz/tex?q=1348 is an extremely flexible way to gather content from loads of lectures and avoid duplicates. 

It was based on `\lecture` (as equivalent to chapter in `beamer`). 

This option is so convenient, that I'd like to have more granularity to input content at a `\section` level.

here is the structure of my folder (lecture level = chapter level)

![TACoursebySection2.png](/image?hash=2137f7192763287f7eb0e82e1485ee0d07e2b565bf73cbc66b724c1963edf97b)

In a way,  the content and the container drive me to define a metric.    
- One section = 1h   
- One lecture= 3h 
  
Here is how I would see the flow. It'd powerful ! (unless I am missing something)    
  
```    
\pgfkeys{/courses/.cd,
	15hCourse/.initial={1,2,3,4,5},
	9hCourse/.initial={2,3,5},
	3hSeminar/.initial={01_02,02_03,03_01}}
```    
**Case 1 - all sections in a lecture**

`\CourseInput[Lecture]{15hCourse}{*}`  (% I like the star for all) 
loads all sections in 15hCourse

```
\input{Lecture1}
\input{Lecture2}
\input{Lecture3}
\input{Lecture4}
\input{Lecture5}
```

=> 5 lectures, it's a long 15h course !

`\CourseInput[lecture]{9hCourse}{*}`  loads all sections in 9hCourse

```
\input{Lecture2}
\input{Lecture3}
\input{Lecture5}

```
=> 3 lectures, it's a short 9h course.

**Case 2 - all First sections in different lectures**

`\CourseInput[lecture]{15hCourse}{1}` loads sections 1 (introduction) for 15hCourse (Lectures 1,2,3,4 and 5)

```
\input{sec01_01}
\input{sec02_01}
\input{sec03_01}
\input{sec04_01}
\input{sec05_01}

```

Looks like the summary of what's at stake in the 5 lectures
Could be part of an automated Syllabus

**Case 3 - different sections in different lectures**

`\CourseInput[Section]{}{3hSeminar} `

loads all sections in 3hSeminar

```
\input{sec01_02}
\input{sec02_03}
\input{sec03_01}
```
Short 3h intervention for a seminar on three different topics

**Extensions I imagine**

by naming things the right way (for bibiliography, internet links, any other topic/content related to a section) I could reach my long time goal to have a way to cut and slice and repackage content the way I want.


MWE adapted from the original answer.

```
\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}%
\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}}%
}%	
\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}
%\CourseInputbySection{03_02,01_01} %not easy to read or input :/ must be a smarter way

\end{document}
```

Top Answer
user 3.14159
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}
```

Enter question or answer id or url (and optionally further answer ids/urls from the same question) from

Separate each id/url with a space. No need to list your own answers; they will be imported automatically.