我想重新定义\section
命令,以便它可以接受一个输入\sectiondesc
;其中包含有关它的描述。考虑 MWE:
\documentclass{beamer}
\usepackage{graphicx}
\begin{document}
%%% old definition
\section[short title]{Long Title}
%%% new definition
%\section[short title]{Long Title}{Really long description \\ multiple lines, often with graphics \includegraphics[width=.5\textwidth]{example-image-a}}
\begin{frame}
\sectionpage
\begin{center}
\normalfont
% \sectiondesc
\end{center}
\end{frame}
\end{document}
答案1
在我看来,使用和的方式是最简单的xparse
方式。\RenewDocumentCommand
我建议使用\section[]{}[]
但是,即可以省略部分描述。
每次调用时宏\sectiondesc
都会被重新定义为不扩展为任何内容\section
,因此省略第 4 个参数将不会提供任何部分描述。
\documentclass{beamer}
\usepackage{graphicx}
\usepackage{xparse}
\let\beameroldsection\section% Store the old definition first
\def\sectiondesc{}
\RenewDocumentCommand{\section}{sO{#3}m+O{}}{%
\gdef\sectiondesc{}
\IfBooleanTF{#1}{% Grab the starred version, i.e. \section*
\beameroldsection*{#3}%
}{%
\beameroldsection[#2]{#3}%
\gdef\sectiondesc{#4}% Store argument 4
}%
}
\begin{document}
\section[short title]{Long Title}[Really long description \\ multiple lines, often with graphics \includegraphics[width=.5\textwidth]{example-image-a}]
\begin{frame}
\sectionpage
\begin{center}
\normalfont
\sectiondesc
\end{center}
\end{frame}
\section*{Foo}
\begin{frame}
\sectionpage
\begin{center}
\normalfont
\sectiondesc
\end{center}
\end{frame}
\end{document}