(Name-)referencing to current chapter

As I understood, I define my chapter title as follows:

\chapter[title in table of contents][title in header line]{title in body}


afterwards I add a label e.g.

\label{Chapter1}


I know that I can use something like \nameref(Chapter1) to display the title of the respective chapter. However, how can I display the name/title of the current chapter ... so the chapter in which I give the command (e.g. if I want to display the name of the current chapter in my custom footer) Please no fancyhdr solutions. Thanks!

• 'Please no fancyhdr solutions' ... well.. please add a compilable document as well. Apparently, you're using memoir. And \nameref(Chapter1) will make (pdf)LaTeX turn back on you ;-) Numbered label names are also very error prone – user31729 Oct 31 '17 at 19:06
• Shall this have a link to the chapter title as well? – user31729 Oct 31 '17 at 19:16

A version without any links (Will edit this later on)

\documentclass{memoir}

\usepackage{xpatch}
\usepackage{hyperref}
\makeatletter

\gdef\@currentchaptername{}%
}{%
\gdef\@currentchaptername{#1}%
}{\typeout{Patch success for @makechapterhead}}{\typeout{Patch failure for @makechapterhead}}

\newcommand{\currentchapref}{%
\@currentchaptername%
}

\makeatother

\begin{document}

\tableofcontents

\section{ A foo section}

This is \currentchapref.
\end{document}


And here is version with linking (if necessary) or use the starred macro version \currentchapref* to suppress links:

\documentclass{memoir}

\usepackage{blindtext}
\usepackage{xpatch}
\usepackage{hyperref}
\makeatletter

\gdef\@currentchaptername{}%
}{%
\@ifundefined{@currentHref}{%
\gdef\@currentchaptername{{}{#1}}%
}{%
% Store the current anchor for the chapter
\edef\@currentchaptername{{\@currentHref}{#1}}%
}%
}{\typeout{Patch success for @makechapterhead}}{\typeout{Patch failure for @makechapterhead}}

\NewDocumentCommand{\currentchapref}{sm}{%
\IfBooleanTF{#1}{%
\expandafter\@secondoftwo\@currentchaptername% Use only the second argument
}{%
}%
}

\makeatother

\begin{document}

\tableofcontents