1

I want to extract all subsection titles from a beamer presentation to later build a customized table of contents similar to Links in mindmap as table of contents in beamer. But I would use the iterative built commands where the subsection titles are stored. I think latex should run at least twice.

\documentclass{beamer}
\usepackage{lmodern}

\AtBeginSubsection{%
    \renewcommand{\thesection}{\alph{section}}
    \renewcommand{\thesubsection}{\alph{subsection}}
    \expandafter\def\csname Section\thesection subsection\thesubsection\endcsname{\tableofcontents[currentsubsection,hideothersubsections,sectionstyle=hide/hide,subsectionstyle=show/hide]}
}

\begin{document}

\begin{frame}
    \frametitle{contents of all subsections}

    % The commands below shall be defined 
    \SectionAsubsectionA
    \SectionAsubsectionB
    \SectionBsubsectionA

\end{frame}

\section{section 1}

\subsection{subsection 1.1}

\subsection{subsection 1.2}

\section{section 2}

\subsection{subsection 2.1}

\end{document}
cacamailg
  • 8,405
  • 1
    The following does what you seem to be after, but I don't get how you'd use it... – Werner Nov 08 '16 at 20:44
  • Alternative approaches could be to 1) read the information from the .toc file 2) to manipulate the creation of the .toc file to already contain the mindmap code or 3) to use the beamer way and modify the definition of \insertsectionnavigation and \insertsubsectionnavigation. But I have not enough tikz/mindmap knowledge to do either. – samcarter_is_at_topanswers.xyz Nov 08 '16 at 20:59
  • @Werner I would use it to define leafs of the mindmap tree. Per each section, the subsections would be the leafs. With that approach I could use a \foreach to build the section and them connect its leafs (wich would be the subsections). – cacamailg Nov 08 '16 at 21:12
  • @cacamailg: I use \csname ... \endcsname which doesn't throw an error when you make a call to it. However, you may as well define something with \providecommand to make sure it exists. Then, I write to the .aux which is read in around \begin{document}. That allows you to use the defined macros in a similar way to how one would use \labelsand\ref`s. – Werner Nov 08 '16 at 21:18
  • @Werner I tried your code, but it didn't work. I was not able to print the subsections name. Can you provide a full answer? – cacamailg Nov 08 '16 at 21:18
  • @cacamailg: Well, yes, that's because you define the \SectionXSubsectionY to expand to \tableofcontents[..]. That's what I don't understand in your question. Your title suggests you want to retrieve the \subsection title, but your question uses \tableofcontents as the definition. – Werner Nov 08 '16 at 21:19
  • @Werner Well, yes. I want to extract all the subsections names (and possible numbers) in a beamer presentation. So that latter I can build a custom ToC, following, e.g. a mindmap or a table. The idea in the end is to have a possible way to have the sections/subsections that were used in the document stored in a command or via csname... \endcsname. – cacamailg Nov 08 '16 at 21:24
  • @cacamailg: Check this example. – Werner Nov 08 '16 at 21:38
  • It gave me an error Undefined control sequence. l.23 \global\defA .A{} subsection 1.1{A.A{} subsection 1.1}. – cacamailg Nov 08 '16 at 21:44
  • @cacamailg: Sorry, check this example. – Werner Nov 08 '16 at 23:09
  • Thanks! The only thing that is missing is the hyperlink. Would it be possible to have it? Furthermore, if you provide the answer here I will accept it. – cacamailg Nov 09 '16 at 00:04

1 Answers1

1

This answer is based on the comments from Werner, so all credits shall go to him.

\documentclass{beamer}

\usepackage{tikz}

\makeatletter
\let\oldsection\section
\renewcommand{\section}[2][]{%
    \oldsection[#1]{#2}% Call default \section (this also steps the section counter)
    \hypertarget{\csname Section\Alph{section}\endcsname}{}%
    \setbox0=\hbox{#1}\ifdim\wd0=0pt%
        \immediate\write\@auxout%
            {\string\global\string\def\string\Section\Alph{section}{%
              \arabic{section}{.} #2}}%
            %{\string\global\string\def\string\Section\Alph{section}{#2}}%
    \else%
        \immediate\write\@auxout%
            {\string\global\string\def\string\Section\Alph{section}{%
              \arabic{section}{.} #1}}%
            %{\string\global\string\def\string\Section\Alph{section}{#1}}%
    \fi%
}
\makeatother

\makeatletter
\let\oldsubsection\subsection
\renewcommand{\subsection}[2][]{%
    \oldsubsection[#1]{#2}% Call default \subsection (this also steps the subsection counter)
    \hypertarget{\csname Section\Alph{section}subsection\Alph{subsection}\endcsname}{}%
    \setbox0=\hbox{#1}\ifdim\wd0=0pt%
        \immediate\write\@auxout%
            {\string\global\string\def\string\Section\Alph{section}subsection\Alph{subsection}{%
              \arabic{section}.\arabic{subsection}{.} #2}}%
            %{\string\global\string\def\string\Section\Alph{section}subsection\Alph{subsection}{#2}}%
    \else%
        \immediate\write\@auxout%
            {\string\global\string\def\string\Section\Alph{section}subsection\Alph{subsection}{%
              \arabic{section}.\arabic{subsection}{.} #1}}%
            %{\string\global\string\def\string\Section\Alph{section}subsection\Alph{subsection}{#1}}%
    \fi%
}
\makeatother

\begin{document}
\begin{frame}

% Print sections with hyperlinks
\foreach \Idxsec in {A,...,Z}{%
    \ifcsname Section\Idxsec \endcsname
        \xdef\sectionname{\csname Section\Idxsec\endcsname}
        \hyperlink{\sectionname}{\sectionname}\par
    \fi
}

% Print subsections with hyperlinks
\foreach \Idxsec in {A,...,Z}{%
    \foreach \Idxsubsec in {A,...,Z}{%
        \ifcsname Section\Idxsec subsection\Idxsubsec \endcsname
            \xdef\subsectionname{\csname Section\Idxsec subsection\Idxsubsec\endcsname}
            \hyperlink{\subsectionname}{\subsectionname}\par
        \fi
    }
}

% Print sections and subsections with hyperlinks
\foreach \Idxsec in {A,...,Z}{%
    \ifcsname Section\Idxsec \endcsname
        \xdef\sectionname{\csname Section\Idxsec\endcsname}
        \hyperlink{\sectionname}{\sectionname}\par
        \foreach \Idxsubsec in {A,...,Z}{%
            \ifcsname Section\Idxsec subsection\Idxsubsec \endcsname
                \xdef\subsectionname{\csname Section\Idxsec subsection\Idxsubsec\endcsname}
                \hyperlink{\subsectionname}{\subsectionname}\par
            \fi
        }
    \fi
}

\end{frame}
\end{document}
cacamailg
  • 8,405