I need to run a command after each chapter, so I need to patch chapters. If I do:
\documentclass{scrreport} %% Works with memoir but not with scrreport
\NewDocumentCommand\MyAddLabel{}{\label{mylabel}}
\usepackage{etoolbox}
\makeatletter
%% Add the above command to \chapter if the command exists
\ifdef{\@chapter}{
\ifpatchable*{\@chapter}{
\apptocmd{\@chapter}{\MyAddLabel}{}{}%
}{\PackageWarning{mypackage}{Chapters are not patchable.}{}}
}{}
\makeatother
\begin{document}
Test
\chapter{Testchap}
asdf
\end{document}
Then it works great for the memoir
class, but not for the scrreport
class.
What's the proper way to also patch the memoir
class in the scrreport
class?
EDIT
The Komascript class even states:
Any package, that changes internal macros like \cs{@chapter}, \cs{@schapter}, \cs{@makechapterhead}, \cs{@makeschapterhead} is incompatible with \KOMAScript{} classes. Neither \KOMAScript{} nor the \KOMAScript{} author is responsible for this. Package authors are welcome to ask for interfaces they need, e.g., a good idea would be to define a own headings style.
EDIT2
I tried to use \AddtoDoHook{heading/endgroup}{\label{mydummylabel}}
but it adds an ugly chapter
or section
text right after the section:
\documentclass{scrreport} %% Works with memoir but not with scrreport
\usepackage{lipsum}
\AddtoDoHook{heading/endgroup}{\label{mydummylabel}} % IRL, the label is programmatically chosen
\begin{document}
\lipsum[1]
\chapter{Here is my chapter}
\lipsum[1]
\section{Here is my section}
% \begin{thmE}
% Here is my important theorem
% \end{thmE}
\end{document}
EDIT3
Oh, I understand, either we use heading/endgroup/chapter
to target chapters, otherwise it calls the content like a macro:
\documentclass{scrreport} %% Works with memoir but not with scrreport
\usepackage{lipsum}
%% Only for chapters
\AddtoDoHook{heading/endgroup/chapter}{Only for chapt.}
%% For everything
\def\mydummystuff#1{Coucou}
\AddtoDoHook{heading/endgroup}{\mydummystuff} % IRL, the label is programmatically chosen
\begin{document}
\lipsum[1]
\chapter{Here is my title}
\lipsum[1]
\section{Here is my section}
% \begin{thmE}
% Here is my important theorem
% \end{thmE}
\end{document}
chapter
text on the line after the title. Regarding the label, I use them in a library to provide a way to refer to the current section, so the labels are chosen programmatically and not accessible directly to the end user.