I have a macro that contains the title for the current section, however when using the titlesec
package, it no longer works for \section
and \subsection
. I know titlesec
redefines the functions I'm using, but have not been able to figure out a workaround.
MWE:
\documentclass{article}
\usepackage{etoolbox}
\makeatletter
\pretocmd{\@sect}{\gdef\currtitle{#7}}{}{}
\pretocmd{\@ssect}{\gdef\currtitle{#5}}{}{}
\pretocmd{\@part}{\gdef\currtitle{#1}}{}{}
\pretocmd{\@spart}{\gdef\currtitle{#1}}{}{}
\makeatother
\usepackage{titlesec}
\begin{document}
\tableofcontents
\part*{First Starred part}
\currtitle
\part{First Un-starred part}
\currtitle
\section*{First Starred Section}
\currtitle
\section{Second Un-starred Section}
\currtitle
\subsection*{First Starred Subsection}
\currtitle
\subsection{Second Un-starred Subsection}
\currtitle
\end{document}
Best Answer
For
\section
and lower level titles you can doHowever, if you're not going to hide titles in groups, the simple
should suffice.
For
\part
your code still works and I believe also the similar one for\chapter
.In order to save only the current first level section title one can modify the code to