I came across this answer which claims that it works even with the starred version of \chapter et al. The following example shows that it does not, because \...mark macros are not called. Is there a way to "fix" this and be able to set the respective value of the \...name macros even if there is a *-type call?

\documentclass{book}
\let\Chaptermark\chaptermark
\let\Sectionmark\sectionmark
\let\Subsectionmark\subsectionmark
\let\Subsubsectionmark\subsubsectionmark
\def\chaptermark#1{\def\Chaptername{#1}\Chaptermark{#1}}
\def\sectionmark#1{\def\Sectionname{#1}\Sectionmark{#1}}
\def\subsectionmark#1{\def\Subsectionname{#1}\Subsectionmark{#1}}
\def\subsubsectionmark#1{\def\Subsubsectionname{#1}\Subsubsectionmark{#1}}
\begin{document}
\chapter{First chapter}
Title: ``\Chaptername''.
\section{First section}
Title: ``\Sectionname''.
\subsection{First subsection}
Title: ``\Subsectionname''.
\subsubsection{First subsubsection}
Title: ``\Subsubsectionname''.
\chapter*{Second chapter}
Title: ``\Chaptername''.
\section*{Second section}
Title: ``\Sectionname''.
\subsection*{Second subsection}
Title: ``\Subsectionname''.
\subsubsection*{Second subsubsection}
Title: ``\Subsubsectionname''.
\end{document}
Lets assume that I have a long file with many \section (etc.) calls. But there is a macro which I want to change to contain the title of the actual section (etc.).


nameref– Marco Daniel Nov 08 '13 at 14:05namerefmean that I have to\labeleach and every section, chapter, etc? If I want to automatize the labeling the problem seems to remain the same with a little more thinkering with labels. – masu Nov 08 '13 at 14:10\...markis called only for the non *-version. – egreg Nov 08 '13 at 14:59\chapter*command doesn't set any label. So your\chapter*{Second chapter}\label{ch:second}will simply make\ref{ch:second}refer to\subsubsection{First subsubsection}(or the last refstepped counter at the same group level, in general). – egreg Nov 08 '13 at 15:05\...namemacros even there is a * call. – masu Nov 08 '13 at 16:11todolist. Maybe it would be better to unset them if a\chapter*macro call occurs (but this would only mean to set them to\relaxinstead of the title. – masu Nov 08 '13 at 17:11\chapter*do you have? I guess one or two: alternating numbered and unnumbered chapters (or sections or subsections) is quite dubious practice. So I continue not to understand what this would be for. – egreg Nov 08 '13 at 17:17