I use \include to insert parts into a large document. Some of the parts contain chapter declarations, others only sections. I would like to make the current chapter name available in the daughter sections, even when the chapter parts are unincluded.
My attempt was to modify the \chaptermark command (from the answer to how to get the current chapter name, section name, subsection name, etc?) to store the chapter name in \@Chaptername and also save this to the part's aux file.
However, my line in the aux file is written outside the \@setckpt such that all definitions of \@Chaptername are read in at the beginning of the document and the variable then holds the name of the last chapter (until an included chapter part overwrites it).
Here is a MNWE:
\documentclass{scrbook}
\begin{filecontents}{Ch1.tex}
\chapter{Chapter 1}
\end{filecontents}
\begin{filecontents}{Ch2.tex}
\chapter{Chapter 2}
\end{filecontents}
\includeonly{Ch2} % <- Hide this to see the effect.
\makeatletter
\let\Chaptermark\chaptermark
\def\chaptermark#1{\gdef\@Chaptername{\thechapter\enskip#1}\Chaptermark{#1}%
\write\@partaux{\string\gdef\string\@Chaptername{\thechapter\enskip#1}}}
\def\Chaptername{\ifdefined\@Chaptername\@Chaptername\fi}
\makeatother
\begin{document}
\include{Ch1}
The parent chapter is called: \Chaptername
\include{Ch2}
\end{document}
With the marked line commented out, one gets the desired result:

With the marked line not commented out, one gets:

I suspect a possible solution could be to write to the checkpoint section \@setckpt in the part's aux file. Is this possible?
Or is there maybe a more elegant / better solution?