我想从 Beamer 演示文稿中提取所有小节标题,以便稍后构建类似于思维导图中的链接作为投影仪中的目录。但我会使用存储子部分标题的迭代构建命令。我认为 latex 至少应该运行两次。
\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}
答案1
该答案基于 Werner 的评论,因此所有功劳都归于他。
\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}