Get current "section" name without label
Not exactly an answer to your question but maybe useful to others:
The Beamer class provides the commands \secname
and \subsecname
to get the current sections or subsections name.
This example produces a frame containing the text "Current section: Foo":
\documentclass{beamer}
\begin{document}
\section{Foo}
\begin{frame}
Current section: \secname
\end{frame}
\end{document}
Variations of the same theme. All the title
-/nameref
packages have to remember the current title somewhere.
Package nameref
\documentclass{article}
\usepackage{nameref}
\makeatletter
\newcommand*{\currentname}{\@currentlabelname}
\makeatother
\begin{document}
\section{My section name}
The name of the current section is: "\currentname".\\
It should be: "My section name".
\subsection{My subsection name}
The name of the current subsection is: "\currentname".\\
It should be: "My subsection name".
\end{document}
Package titleref
\documentclass{article}
\usepackage{titleref}
\makeatletter
\newcommand*{\currentname}{\TR@currentTitle}
\makeatother
\begin{document}
\section{My section name}
The name of the current section is: "\currentname".\\
It should be: "My section name".
\subsection{My subsection name}
The name of the current subsection is: "\currentname".\\
It should be: "My subsection name".
\end{document}
Same result.
Package zref-titleref
\documentclass{article}
\usepackage{zref-titleref}
\makeatletter
\newcommand*{\currentname}{\zref@getcurrent{title}}
% or \newcommand*{\currentname}{\zref@titleref@current}
\makeatother
\begin{document}
\section{My section name}
The name of the current section is: "\currentname".\\
It should be: "My section name".
\subsection{My subsection name}
The name of the current subsection is: "\currentname".\\
It should be: "My subsection name".
\end{document}
Same result.
If you use the standard classes that rely on the kernel commands for making headers, then here's a possibility that works unmodified if the class is article
(removing the \chapter
command, of course).
\documentclass{book}
\usepackage{etoolbox}
\makeatletter
\newif\if@chapters
\@ifundefined{chapter}{\@chaptersfalse}{\@chapterstrue}
\if@chapters
\apptocmd{\@chapter}{\gdef\currentname{#1}}{}{}
\apptocmd{\@schapter}{\gdef\currentname{#1}}{}{}
\fi
\apptocmd{\@sect}{\gdef\currentname{#7}}{}{}
\def\currentname{---Still no title given---}
\makeatother
\begin{document}
\chapter{ABC}
\currentname
\section{My section name}
The name of the current section is: ``\currentname''
It should be: ``My section name''
\subsection{My subsection name}
The name of the current subsection is: ``\currentname''
It should be: ``My subsection name''
\end{document}
For the memoir
class there's nothing to do: the class already provides \currenttitle
that does exactly what you want.
Note that you shouldn't redefine \todo
as you're trying; rather do
\makeatletter
\renewcommand\todo[2][]{\@todo[#1]{\currentname: #2}}
\makeatother