Update:
I accepted the solution provided by Heiko Oberdiek, because that was doing exactly what I asked.
When interested only in the chapter name, egreg's solution works fine. However, to get it working with memoir, one has to change the parameter from #1
to #2
. Don't ask me why.
\documentclass[a4paper, 10pt, oneside]{memoir}
\usepackage{etoolbox}
\makeatletter
\apptocmd{\@chapter}{\gdef\currentchapter{#2}}{}{}
\def\currentchapter{?}
\makeatother
\begin{document}
\chapter{A Chapter}
``\currentchapter''
\section{A Section}
``\currentchapter''
\end{document}
Old question: I want to get the name of the current "section" (chapter, section, subsection, ...) without labeling the section.
I tried using \nameref
with e.g. \thechapter
which obviously doesn't work, as \nameref
expects a reference (the name of \label
) and not a number.
Is there a command, that gives me directly the name of the current "section"? Or is there a command which can "generate" a reference out of section numbering, like: \getname{\thechapter}
?
I found out already, that it is impossible to get the numbering of the current "section" - I'd need to check the counter to get the correct "section".
My goal is to redefine \todo
from the package todonotes
that it always displays the current "section" name:
\let\Oldtodo\todo
\renewcommand{\todo}[1]{\Oldtodo{\currentname: #1}}
If it is not possible to get the name of the current "section", I would be happy with the current chapter or section name too:
\let\Oldtodo\todo
\renewcommand{\todo}[1]{\Oldtodo{\currentchaptername: #1}}
Below is a simple example without todonotes
.
\documentclass{memoir}
\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}
Notice that I'm using documentclass memoir.
nameref
in combinations withlabels
. Is there some other way? Like receiving a reference from header numbering? This way, one could get the reference and plug it intonameref
:\nameref{\getrefofnumber{\thechapter}}
The name of the current section is: "\rightmark"
doing what you would like? This is what is used (at least in memoir) to extract the name of the current section and put it in the headers. Note that, as section numbering is also given in headers, you might be able to find a way to extract it too if you make some digging in this direction.\currenttitle
instead of\currentname
.