% \iffalse^^A meta-comment
% ======================================================================
% scrlayer-fancyhdr.dtx
% Copyright (c) Markus Kohm, 2021–2025
%
% This file is part of the LaTeX2e package `scrlayer-fancyhdr'.
%
% This work may be distributed and/or modified under the conditions of
% the LaTeX Project Public License, version 1.3c of the license.
% The latest version of this license is in
%   http://www.latex-project.org/lppl.txt
% and version 1.3c or later is part of all distributions of LaTeX
% version 2005/12/01 and of this work.
%
% This work has the LPPL maintenance status "author-maintained".
%
% The Current Maintainer and author of this work is Markus Kohm.
%
% This work consists of the files `scrlayer-fancyhdr.dtx' and
% `README.md'.
% ======================================================================
%
%<identify>%%% docstrip run: identify
%<init>%%% docstrip run: init
%<options>%%% docstrip run: options
%<body>%%% docstrip run: body
%\changes{v0.3}{2025-01-07}{needs at least \LaTeX{} 2020-10-01}
%<identify>\NeedsTeXFormat{LaTeX2e}[2020/10/01]
%<*dtx>
\ifx\ProvidesFile\undefined\def\ProvidesFile#1[#2]{}\fi
\ProvidesFile{scrlayer-fancyhdr.dtx}
%</dtx>
%<package&identify>\ProvidesPackage{scrlayer-fancyhdr}
%<*dtx|(package&identify)>
  [2025-02-10 v0.4
%</dtx|(package&identify)>
%<*dtx>              
    source of package scrlayer-scrpage]
%</dtx>
%<*package>
%<identify>    combining fancyhdr with KOMA-Script's scrlayer]
%</package>
%<*dtx>
\ifx\documentclass\undefined
  \input docstrip.tex
  \generate{%
    \file{scrlayer-fancyhdr.sty}{%
      \from{scrlayer-fancyhdr.dtx}{package,identify}%
      \from{scrlayer-fancyhdr.dtx}{package,init}%
      \from{scrlayer-fancyhdr.dtx}{package,options}%
      \from{scrlayer-fancyhdr.dtx}{package,body}%
    }%
  }
\else
  \let\endbatchfile\relax
\fi
\endbatchfile
\documentclass{koma-script-source-doc}% KOMA-Script related packages use this.
\usepackage[main=english,ngerman]{babel}
\usepackage{csquotes}
\usepackage{biblatex}
\usepackage{listings}
\usepackage{scrhack}

\begin{filecontents}[force]{\jobname.bib}
@Misc{      package:fancyhdr,
  language= {english},
  author  = {Piet van Oostrum},
  title   = {{\pkg{fancyhdr}}\,---\,Extensive control of page headers and
             footers in {\LaTeXe}},
  date    = {2025-02-07},
  edition = {5.2},
  url     = {https://www.ctan.org/pkg/fancyhdr},
  urldate = {2025-02-10}
}

@Misc{      package:koma-script,
  language= {english},
  author  = {Markus Kohm},
  title   = {{\pkg{koma-script}}\,---\,A bundle of versatile classes and
             packages},
  date    = {2024-10-24},
  edition = {3.43},
  url     = {https://www.ctan.org/pkg/koma-script},
  urldate = {2025-01-07}
}

@Misc{      package:scrlayer,
  language= {english},
  author  = {Markus Kohm},
  title   = {{\pkg{scrlayer}}\,---\,Manage text `layers' within
             {\KOMAScript}},
  date    = {2024-10-24},
  edition = {3.43},
  url     = {https://www.ctan.org/pkg/scrlayer},
  urldate = {2025-01-07}
}
\end{filecontents}

\addbibresource{\jobname.bib}

\CodelineIndex
\RecordChanges
\GetFileInfo{scrlayer-fancyhdr.dtx}
\title{The \texttt{scrlayer} interface \texttt{scrlayer-fancyhdr}%
  \footnote{\parbox[t]{.9\linewidth}{\raggedright
      This is version \fileversion\ of file \texttt{\filename}.\\
      Dies ist Version \fileversion\ der Datei \texttt{\filename}.}}\\
  \otherlanguage{ngerman}{Das \texttt{scrlayer}-Interface
    \texttt{scrlayer-fancyhdr}\footnotemark[1]}}
\date{\filedate}
\author{Markus Kohm}

\NewDocElement[%
  macrolike = false,
  toplevel  = true,
  idxtype   = \textit{internal},
  idxgroup  = Page styles (internal),
  printtype = \textit{internal}
]{iPageStyle}{ipgstyle}


\renewcaptionname{english}{\partname}{Part}
\renewcaptionname{english}{\contentsname}{Contents\,/\,Inhalt}%
\renewcaptionname{english}{\refname}{References\,/\,Literatur}%
\renewcaptionname{ngerman}{\partname}{Teil}
\renewcaptionname{ngerman}{\contentsname}{Inhalt\,/\,Contents}
\renewcaptionname{ngerman}{\refname}{Literatur\,/\,References}%

\begin{document}
\maketitle
\tableofcontents
\DocInput{\filename}
\printbibliography
\PrintChanges
\PrintIndex
\end{document}
% \fi^^A meta-comment
% 
% \changes{v0.0}{2018/09/01}{start of interface}
% \changes{v0.0}{2018/09/05}{some user documentation}
% \changes{v0.2}{2021/02/18}{package is no longer part of \KOMAScript}
% \changes{v0.2.1}{2021/03/30}{improved user manual}
% \changes{v0.2.1}{2021/03/30}{German user manual}
% \changes{v0.2.2}{2022/07/08}{using class \cls*{koma-script-source-doc}}
%
% \part{English User Manual}
% \section{The Purpose of this Package}
% \label{sec:purpose}
% This package has been made to give users a chance to combine the features of
% Piet van Oostrum's \pkg{fancyhdr} \autocite{package:fancyhdr} with the
% features of \pkg{scrlayer} \autocite{package:scrlayer}. In other words: It
% has been made to combine the page layers of \pkg{scrlayer} with the page
% styles of \pkg{fancyhdr}.
%
% In this combination compatibility with \pkg{fancyhdr} is the
% first aim!  Usability and the freedom provided by \pkg{scrlayer}
% is only the second one. Compatibility with other packages or classes of
% \KOMAScript{} \cite{package:koma-script} is not a primary aim. Perhaps it
% will become an optional feature in future. Abolishing any real or virtual
% limitations of \pkg{fancyhdr} other than make it possible to use
% layers is not an aim and will not be an aim in future.
%
% If you need a better combination of page styles and layers, you should
% either use the low level interface of \pkg{scrlayer} to define
% your page styles or\,---\,and this is the recommendation of the
% author\,---\,use \pkg{scrlayer-scrpage} instead of
% \pkg*{scrlayer-fancyhdr} or \pkg{fancyhdr}. If you need more
% compatibility with other parts of \KOMAScript, i.\,e.\@ with the
% \KOMAScript{} classes, you should use \pkg{scrlayer-scrpage} instead of
% \pkg*{scrlayer-fancyhdr} or \pkg{fancyhdr}.
%
%
% \section{How it works}
% \label{sec:howitworks}
%
% To combine \pkg{fancyhdr} and \pkg{scrlayer},
% \pkg{scrlayer-scrpage} loads both packages. After loading
% \pkg{fancyhdr} it redefines page style \pstyle{@fancy} (up to
% \pkg{fancyhdr} version 3.10) resp. \pstyle{f@nch@fancycore}
% (from \pkg{fancyhdr} version 4) to make it a layer page style of
% \pkg{scrlayer} using the newly defined layers
% \texttt{fancy.head.even}, \texttt{fancy.head.odd}, \texttt{fancy.foot.even}
% and \texttt{fancy.foot.odd}. The \texttt{\dots head\dots} layers are
% background layers like the page head of \pkg{fancyhdr}'s page
% styles (or other usual page styles). The \texttt{\dots foot\dots} layers are
% foreground layers like the page footer of \pkg{fancyhdr}'s page
% styles (or other usual page styles). The \texttt{\dots even} layers are
% restricted to even pages, that means left side pages in two-sided
% documents. The \texttt{\dots odd} layers are restricted to odd pages, that
% means right side pages in two-sided documents or all pages in single-sided
% documents.
%
% \DescribeiPageStyle{@fancy}
% \DescribeiPageStyle{f@nch@fancycore}
% \DescribePageStyle{fancyplain}
% \DescribeiPageStyle{plain@fancy}
% Up to \pkg{fancyhdr} version 3.10 page style \pstyle{@fancy}
% was an internal page style, users should not select direclty. From version 4
% page style \pstyle{f@nch@fancycore} is used internally by package
% \pkg{fancyhdr}. In both cases, the internal page style is used
% for the user page style \pstyle{fancy}. The user page style
% \pstyle{fancy} is also used for \pkg{fancyheadings}'s deprecated page
% style \pstyle{fancyplain}, that also redefines page style
% \pstyle{plain} to be \pkg{fancyhdr}'s internal page style
% \pstyle{plain@fancy}, that also uses \pstyle{fancy} but with
% \cs{if@fancyplain} set to \cs{iftrue}. There is an additional
% deprecated command \cs{fancyplain}\marg{plain code}\marg{fancy
% code}, too. The command uses the \meta{plain code} if \cs{if@fancyplain}
% is \cs{iftrue} and \meta{fancy code} if \cs{if@fancyplain} is
% \cs{iffalse}. It can be used inside the definition of the page style
% elements to distinguish settings of \pstyle{fancy} and \pstyle{plain}
% pages.
%
% Page styles defined using \pkg{fancyhdr}'s command
% \cs{fancypagestyle} also always use page style \pstyle{fancy} and so
% the internal basic page style \pstyle{@fancy} (up to
% \pkg{fancyhdr} version 3.10) resp. \pstyle{f@nch@fancycore}
% (from \pkg{fancyhdr} version 4).
%
% As a result of the two notes above, every page style of
% \pkg{fancyhdr} always uses the same internal basic page style
% \pstyle{@fancy} (up to \pkg{fancyhdr} version 3.10)
% resp. \pstyle{f@nch@fancycore} (from \pkg{fancyhdr} version
% 4). As a result of redefining page style \pstyle{@fancy} (up to
% \pkg{fancyhdr} version 3.10) resp. \pstyle{f@nch@fancycore}
% (from \pkg{fancyhdr} version 4) to be a layer page style, users
% can add layers to or remove layers from all \pkg{fancyhdr} page
% styles by adding layers to or remove layers from page style
% \pstyle{@fancy} (up to \pkg{fancyhdr} version 3.10)
% resp. \pstyle{f@nch@fancycore} (from \pkg{fancyhdr} version
% 4). You cannot add layers to or remove layers from
% \pkg{fancyhdr}'s single page styles \pstyle{fancy},
% \pstyle{fancyplain}, \pstyle{plain@fancy} or the page styles defined
% using \cs{fancypagestyle} directly. So using layers is a all or nothing
% feature with \pkg{scrlayer-scrpage}. However, you can use the second
% argument of \cs{fancypagestyle} to add or remove layers whenever one of
% the \pkg{fancyhdr} page styles is activated. So this is a move
% from the \pkg{scrlayer} interface of adding or removing layers to
% single page styles to the \pkg{fancyhdr} interface of defining
% modifications of page style \pstyle{fancy}.
%
% Another such movement from a \pkg{scrlayer} user interface to a
% \pkg{fancyhdr} user interface is the decision whether or not
% automatic running heads are used. \pkg{scrlayer} provides the
% options \opt{automark} and \opt{manualmark} and commands
% \cs{automark} and \cs{manualmark} to do this decision and also to
% configure commands like \cs{partmark}, \cs{chaptermark},
% \cs{sectionmark} etc. With \pkg*{scrlayer-fancyhdr} already using page
% style \pstyle{@fancy} (up to \pkg{fancyhdr} version 3.10)
% resp. \pstyle{f@nch@fancycore} (from \pkg{fancyhdr} version 4)
% does switch to automatic running heads. The first activation of page style
% \pstyle{fancy} still redefines \cs{chaptermark} and
% \cs{sectionmark}, if a class with \cs{chapter} is used, or
% \cs{sectionmark} and \cs{subsectionmark}, if a class without
% \cs{chapter} is used. However, you still can use \cs{manualmark} and
% \cs{automark} after switching to a \pkg{fancyhdr} page style
% to configure the running heads. So this movement is only partial.
%
% \DescribePageStyle{headings}
% \DescribePageStyle{myheadings}
% \DescribePageStyle{plain}
% Note: Currently, neither \pkg{scrlayer} nor
% \pkg{fancyhdr} nor \pkg*{scrlayer-fancyhdr} do redefine page
% styles \pstyle{headings} or \pstyle{myheadings} by default. And
% neither \pkg{scrlayer} nor \pkg{fancyhdr} nor
% \pkg*{scrlayer-fancyhdr} do redefine page style \pstyle{plain} unless
% you are activating the deprecated \pkg{fancyhdr} page style
% \pstyle{fancyplain}. So if you like to use layers on \pstyle{plain}
% pages, i.\,e. usually the first page of a chapter or part or the page with a
% title head, you have to either use \pkg{fancyhdr}'s deprecated
% page style \pstyle{fancyplain} or redefine page style \pstyle{plain}
% either using \cs{fancypagestyle} as documented in the
% \pkg{fancyhdr} manual or using \cs{DeclarePageStyleByLayers},
% documented in the \KOMAScript{} manual.
% \DescribeOption{myheading}%
% \DescribeOption{heading}%
% However from version 4.0 \pkg{fancyhdr} provides options
% \opt{myheadings} and \opt{headings} to redefine the corresponding page
% style. \pkg*{scrlayer-fancyhdr} also provides these options and passes
% them to \pkg{fancyhdr}.
%
% \DescribePageStyle{empty}
% \DescribeiPageStyle{@empty}
% Note: Pagestyle \pstyle{empty} is somehow
% special. \pkg{scrlayer} redefines it to be a layer page
% style. And \pkg{fancyhdr}'s internal page style
% \pstyle{@empty} is the same like \pstyle{empty}. So \pstyle{@empty}
% also uses the layers of \pstyle{empty} but you should not try to modify
% it directly using the interface of \pkg{scrlayer}. Moreover, if
% \pkg{fancyhdr} is loaded before \pkg*{scrlayer-fancyhdr},
% \pkg{fancyhdr}'s internal page style \pstyle{@empty} is not a
% copy of \pkg{scrlayer}'s layer page style \pstyle{empty} but
% the original standard page style \pstyle{empty}. However, with
% \pkg*{scrlayer-fancyhdr} package \pkg{fancyhdr} does not
% longer use the internal page style \pstyle{@empty}. So you would not need
% to know this.
%
% \section{How to use the Package}
% \label{sec:howtouse}
%
% To use the package you have to load it, e.\,g., using:
%\begin{verbatim}
% \usepackage{scrlayer-fancyhdr}
%\end{verbatim}
% instead of loading \pkg{scrlayer} and \pkg{fancyhdr}
% or before or after loading one of these packages. However it is recommended
% to replace loading \pkg{scrlayer} and \pkg{fancyhdr}
% by loading \pkg*{scrlayer-fancyhdr} because this avoids option
% clashes. \pkg*{scrlayer-fancyhdr} provides all options of
% \pkg{scrlayer} and \pkg{fancyhdr} and passes them to
% \pkg{scrlayer} resp. \pkg{fancyhdr}. Nevertheless
% sometimes it may be useful to be able to additionally load
% \pkg{scrlayer} or \pkg{fancyhdr}. In this case you
% should first load \pkg{scrlayer} next \pkg{fancyhdr}
% and last \pkg*{scrlayer-fancyhdr}.
%
% \DescribeiPageStyle{@fancy}
% \DescribeiPageStyle{f@nch@fancycore}
% \DescribePageStyle{fancy}
% \DescribePageStyle{fancyplain}
% \DescribeiPageStyle{plain@fancy}
% \DescribeCommand\fancypagestyle
% After loading the package you should be able to use the page styles and
% commands of \pkg{fancyhdr} and to add layers to or remove layers
% from the \pkg{fancyhdr}'s internal basic page style
% \pstyle{@fancy} (up to \pkg{fancyhdr} version 3.10)
% resp. \pstyle{f@nch@fancycore} (from \pkg{fancyhdr} version
% 4). Note, you are not able to add layers to or remove layers from
% \pkg{fancyhdr}'s page styles \pstyle{fancy},
% \pstyle{fancyplain}, \pstyle{plain@fancy} or page styles defined by
% \cs{fancypagestyle}. However adding layers to or removing layers from
% \pstyle{@fancy} (up to \pkg{fancyhdr} version 3.10)
% resp. \pstyle{f@nch@fancycore} (from \pkg{fancyhdr} version 4)
% will always change all these page styles!
%
% \DescribePageStyle{plain}
% \DescribePageStyle{headings}
% \DescribePageStyle{myheadings}
% \DescribePageStyle{empty}
% Note: Loading \pkg*{scrlayer-fancyhdr} will not make page style
% \pstyle{plain} nor \pstyle{headings} nor \pstyle{myheadings} or any
% other page style but \pstyle{empty} to automatically be a layer page
% style! But if you are using option \opt{headings} or \opt{myheadings},
% package \pkg{fancyhdr} redefines the corresponding page styles to
% be \pkg{fancyhdr} page styles\,---\,and so relate to the same
% internal layer page style, either \pstyle{@fancy} (up to
% \pkg{fancyhdr} version 3.10) or \pstyle{@f@nch@fancycore}
% (from \pkg{fancydr} version 4.0).
%
%
% \section{Hint}
% \label{sec:hint}
%
% To become independent from the used version of \pkg{fancyhdr} you
% can use:
% \begin{verbatim}
% \IfPackageAtLeastTF{fancyhdr}{2019/03/21}{%
%   \DeclarePageStyleAlias{@fancy}{f@nch@fancycore}%
% }{%
%   \DeclarePageStyleAlias{f@nch@fancycore}{@fancy}%
% }
% \end{verbatim}^^A
% \unskip after loading \pkg*{scrlayer-fancyhdr} and before adding a layer
% to the internal layer page style. This code defines page style
% \pstyle{@fancy} to be an alias of \pstyle{f@nch@fancycore} if
% \pkg{fancyhdr} from version 4.0 is used or vise versa
% \pstyle{f@nch@fancycore} as an alias of \pstyle{@fancy} if
% \pkg{fancyhdr} before version 4.0 is used. So after this code
% using either
% \begin{verbatim}
% \AddLayersToPageStyle{@fancy}{...}
% \end{verbatim}^^A
% \unskip or
% \begin{verbatim}
% \AddLayersToPageStyle{f@nch@fancycore}{...}
% \end{verbatim}^^A
% \unskip would both result in adding the layers to the internal layer page
% style.
%
%
% \section{Known Issues}
% \label{sec:issues}
%
% Please note, the follow issues are either notes to the package author or
% notes to the user to avoid them reporting the same issues again and
% again. Listing these issues does not say they are bugs or features.
% \begin{itemize}
% \item
%   \DescribePageStyle{fancy}
%   \DescribeiPageStyle{f@nch@fancycore}
%   \DescribePageStyle{fancyplain}
%   \DescribeCommand\fancypagestyle
%   \DescribeiPageStyle{@fancy}
%   You are not able to add layers to the user level page style
%   \pstyle{fancy} or \pstyle{fancyplain} or any page style defined by
%   \cs{fancypagestyle} but only to the internal page style
%   \pstyle{@fancy} (if you are using \pkg{fancyhdr} up to
%   version 3.10) resp. \pstyle{f@nch@fancycore} (if you are using
%   \pkg{fancyhdr} from version 4). This is intended as explained
%   in this manual (see also section~\ref{sec:hint}).
% \item
%   \DescribeiPageStyle{@empty}
%   Using \pkg{fancyhdr}'s internal page style \pstyle{@empty}
%   could have strange results. However, there is a simple solution for this:
%   Don't use the internal \pstyle{@empty} but always the user level page
%   style \pstyle{empty}!
% \item
%   \DescribeiPageStyle{@fancy}
%   \DescribeiPageStyle{f@nch@fancycore}
%   The vertical position of the page header does differ a little bit, if
%   \pkg*{scrlayer-fancyhdr} is used instead of
%   \pkg{fancyhdr}. This could be fixed by a modification of the
%   layers \texttt{fancy.head.odd} and \texttt{fancy.head.even} using
%   \opt{addvoffset}. More tests are needed.
% \item
%   Not all ew features of \pkg{fancyhdr} v5 have been tested yet.
% \end{itemize}
% See \url{https://github.com/komascript/scrlayer-fancyhdr/issues} for more
% issues.
%
% \selectlanguage{ngerman}
% \part{Benutzeranleitung auf Deutsch}
% \section{Der Sinn dieses Pakets}
% \label{sec:sinn}
% Dieses Paket wurde entwickelt, um den Anwendern die Möglichkeit zu geben,
% die Fähigkeiten von Piet van Oostrums \pkg{fancyhdr}
% \autocite{package:fancyhdr} mit den Fähigkeiten von
% \pkg{scrlayer} \autocite{package:scrlayer} zu kombinieren. In
% anderen Worten: Es wurde geschaffen, um die Seiten-Ebenen von
% \pkg{scrlayer} mit den Seiten-Stilen von
% \pkg{fancyhdr} zu kombinieren.
%
% In dieser Kombination ist Kompatibilität mit \pkg{fancyhdr} das
% oberste Ziel! Verwendbarkeit und die Freiheiten, die von
% \pkg{scrlayer} geboten werden, ist das zweite
% Ziel. Kompatibilität mit anderen Paketen oder Klassen von \KOMAScript{}
% \cite{package:koma-script} ist kein primäres Ziel. Vielleicht wird dies in
% Zukunft eine optionale Fähigkeit werden. Die Aufhebung irgendwelcher realen
% oder eingebildeter Beschränkungen von \pkg{fancyhdr}, die darüber
% hinaus gehen, die Verwendung von Ebenen zu ermöglichen, ist kein Ziel und
% wird auch in Zukunft kein Ziel werden.
%
% Wenn Sie eine bessere Kombination von Seitenstilen und Ebenen benötigen, so
% sollten Sie entweder die Low-Level-Schnittstelle von
% \pkg{scrlayer} zur Definition von Seitenstilen oder ---~und das
% ist die Empfehlung des Autors~--- das Paket \pkg{scrlayer-scrpage}
% anstelle von \pkg*{scrlayer-fancyhdr} oder \pkg{fancyhdr}
% verwenden. Wenn Sie bessere Kompatibilität mit anderen Teilen von
% \KOMAScript, beispielsweise mit den \KOMAScript-Klassen. benötigen, sollten
% Sie \pkg{scrlayer-scrpage} anstelle von \pkg*{scrlayer-fancyhdr} oder
% \pkg{fancyhdr} verwenden.
%
% \section{Wie es funktioniert}
% \label{sec:funktion}
% Zur Kombination von \pkg{fancyhdr} mit \pkg{scrlayer}
% lädt \pkg{scrlayer-scrpage} beide Pakete. Nach dem Laden von
% \pkg{fancyhdr} definiert es den Seitenstil \pstyle{@fancy}
% (bis einschließlich \pkg{fancyhdr} Version 3.10)
% bzw. \pstyle{f@nch@fancycore} (ab \pkg{fancyhdr} Version 4.0)
% in einen Ebenen-Seitenstil von \pkg{scrlayer} um, bestehend aus
% den neu definierten Ebenen \texttt{fancy.head.even},
% \texttt{fancy.head.odd}, \texttt{fancy.foot.even} und
% \texttt{fancy.foot.odd}. Die \texttt{\dots head\dots}-Ebenen sind
% Hintergrund-Ebenen entsprechend dem Seitenkopf von
% \pkg{fancyhdr}-Seiten\-stilen (oder anderen gebräuchlichen
% Seitenstilen). Die \texttt{\dots foot\dots}-Ebenen sind Vordergrund-Ebenen
% entsprechend dem Seitenfuß von
% \linebreak\pkg{fancyhdr}-Seitenstilen (oder anderen
% gebräuchlichen Seitenstilen). Die \texttt{\dots even}-Ebenen sind auf gerade
% Seiten, also linke Seiten von doppelseitigen Dokumenten, beschränkt. Die
% \texttt{\dots odd}-Ebenen sind auf ungerade Seiten, also rechte Seiten bei
% doppelseitigen Dokumenten oder alle Seiten bei einseitigen Dokumenten,
% beschränkt.
%
% \DescribeiPageStyle{@fancy}
% \DescribeiPageStyle{f@nch@fancycore}
% \DescribePageStyle{fancyplain}
% \DescribeiPageStyle{plain@fancy}
% Bis Version 3.10 von \pkg{fancyhdr} war Seitenstil
% \pstyle{@fancy} ein interner Seitenstil, den Anwender selbst nicht direkt
% verwenden sollten. Ab Version 4.0 wird \pstyle{f@nch@fancycore} als
% interner Seitenstil von Paket \pkg{fancyhdr} genutzt. In beiden
% Fällen wird der interne Seitenstil für den Benutzer\-seiten\-stil
% \pstyle{fancy} verwendet. Der Benutzerseitenstil \pstyle{fancy} wird
% ebenfalls für den veralteten Seitenstil \pstyle{fancyplain} des Pakets
% \pkg{fancyheadings} verwendet, der zusätzlich den Seitenstil
% \pstyle{plain} in \pkg{fancyhdr}s internen Seitenstil
% \pstyle{plain@fancy} ändert, der ebenfalls \pstyle{fancy} verwendet,
% wobei allerdings \cs{if@fancyplain} auf \cs{iftrue} gesetzt ist. Es
% gibt eine weitere überholte Anweisung
% \cs{fancyplain}\marg{plain-Code}\marg{fancy-Code}. Diese
% Anweisung verwendet \meta{plain-Code}, wenn \cs{if@fancyplain}
% \cs{iftrue} ist, aber \meta{fancy-Code}, wenn \cs{if@fancyplain}
% \cs{iffalse} ist. Sie kann innerhalb der Definition der
% Seitenstilelemente verwendet werden um zwischen den Einstellung für
% \pstyle{fancy} und \pstyle{plain} zu unterscheiden.
%
% Seitenstile, die mit der \pkg{fancyhdr}-Anweisung
% \cs{fancypagestyle} definiert wurden, verwenden ebenfalls immer den
% Seitenstil \pstyle{fancy} und damit den internen grundlegenden Seitenstil
% \pstyle{@fancy} (bis einschließlich \pkg{fancyhdr} Version
% 3.10) bzw. \pstyle{f@nch@fancycore} (ab \pkg{fancyhdr} Version
% 4).
%
% Als Ergebnis der beiden obigen Anmerkungen, verwenden alle Seitenstile von
% \pkg{fancyhdr} immer denselben internen grundlegenden Seitenstil
% \pstyle{@fancy} (bis einschließlich \pkg{fancyhdr} Version
% 3.10) bzw. \pstyle{f@nch@fancycore} (ab \pkg{fancyhdr} Version
% 4). Als Ergebnis daraus resultiert aus der Umdefinierung des Seitenstils
% \pstyle{@fancy} (bis einschließlich \pkg{fancyhdr} Version
% 3.10) bzw. \pstyle{f@nch@fancycore} (ab \pkg{fancyhdr} Version
% 4) in einen Ebenen-Seitenstil, dass Anwender Ebenen zu allen Seitenstilen
% von \pkg{fancyhdr} hinzufügen oder daraus löschen können, indem
% sie Ebenen zu \pstyle{@fancy} (bis einschließlich
% \pkg{fancyhdr} Version 3.10) bzw. \pstyle{f@nch@fancycore} (ab
% \pkg{fancyhdr} Version 4) hinzufügen oder daraus löschen. Sie
% können keine Ebenen unmittelbar zu einzelnen Seitenstilen von
% \pkg{fancyhdr} wie \pstyle{fancy}, \pstyle{fancyplain},
% \pstyle{plain@fancy} oder anderen mit \cs{fancypagestyle} definierten
% Seitenstilen hinzufügen oder daraus löschen. Aber natürlich können Sie das
% zweite Argument von \cs{fancypagestyle} nutzen, um Ebenen zum Zeitpunkt
% der Aktivierung eines \pkg{fancyhdr}-Seitenstils hinzuzufügen
% oder zu entfernen. Dies stellt eine Verschiebung dar weg von der
% \pkg{scrlayer}-Schnittstelle zum Hinzufügen oder Entfernen von
% Ebenen hin zur \pkg{fancyhdr}-Schnittstelle zur Definition von
% Änderungen des Seitenstils \pstyle{fancy}.
%
% Ein weitere solche Verschiebung von der Anwenderschnittstelle von
% \pkg{scrlayer} zur Anwenderschnittstelle von
% \pkg{fancyhdr} ist die Entscheidung, ob automatische, lebende
% Kolumnentitel verwendet werden sollen oder nicht. \pkg{scrlayer}
% bietet dafür die Optionen \opt{automark} und \opt{manualmark} und die
% Anweisungen \cs{automark} und \cs{manualmark}. Diese konfigurieren
% gleichzeitig Anweisungen wie \cs{partmark}, \cs{chaptermark},
% \cs{sectionmark} etc. Mit \pkg*{scrlayer-fancyhdr} wird bereits durch
% Verwendung von Seitenstil \pstyle{@fancy} (bis einschließlich
% \pkg{fancyhdr} Version 3.10) bzw. \pstyle{f@nch@fancycore} (ab
% \pkg{fancyhdr} Version 4) auf automatische, lebende Kolumnentitel
% umgeschaltet. Die erste Aktivierung von \pstyle{fancy} definiert auch
% weiterhin \cs{chaptermark} und \cs{sectionmark}, wenn eine Klasse mit
% \cs{chapter} verwendet wird, oder \cs{sectionmark} und
% \cs{subsectionmark}, wenn eine Klasse ohne \cs{chapter} verwendet
% wird. Dennoch können Sie weiterhin \cs{manualmark} und \cs{automark}
% nach der Umschaltung zu einem \pkg{fancyhdr}-Seitenstil
% verwenden, um die lebenden Kolumnentitel zu konfigurieren. Diese
% Verschiebung ist also nur partiell.
%
% \DescribePageStyle{headings}
% \DescribePageStyle{myheadings}
% \DescribePageStyle{plain}
% Hinweis: Derzeit definieren weder \pkg{scrlayer} noch
% \pkg{fancyhdr} noch \pkg*{scrlayer-fancyhdr} die Seitenstile
% \pstyle{headings} oder \pstyle{myheadings} in der Voreinstellung
% um. Und weder \pkg{scrlayer} noch \pkg{fancyhdr} oder
% \pkg*{scrlayer-fancyhdr} definieren den Seitenstil \pstyle{plain} um,
% solange nicht der veraltete \pkg{fancyhdr}-Seitenstil
% \pstyle{fancyplain} aktiviert wird. Wenn Sie also einen Ebeneseitenstil
% für \pstyle{plain}-Seiten wünschen, insbesondere für die erste Seite
% eines Kapitels oder Teils oder die Seiten mit dem Titelkopf, so müssen Sie
% entweder den veralteten \pkg{fancyhdr}-Seitenstil
% \pstyle{fancyplain} verwenden oder den Seitenstil \pstyle{plain}
% entweder per \cs{fancypagestyle} umdefinieren, wie dies in der
% \pkg{fancyhdr}-Anleitung beschrieben ist, oder per
% \cs{DeclarePageStyleByLayers}, wie dies in der \KOMAScript-Anleitung
% dokumentiert ist.
% \DescribeOption{myheading}%
% \DescribeOption{headings}%
% Darüber hinaus bietet \pkg{fancyhdr} ab Version 4.0 die Optionen
% \opt{myheadings} und \opt{headings}, um die entsprechenden Seitenstile
% umzudefinieren. \pkg*{scrlayer-fancyhdr} bietet diese Optionen ebenfalls
% und leitet sie an \pkg{fancyhdr} weiter.
%
% \DescribePageStyle{empty}
% \DescribeiPageStyle{@empty}
% Hinweis: Der Seitenstil \pstyle{empty} ist etwas
% speziell. \pkg{scrlayer} definiert diesen in einen
% Ebenen-Seitenstil um. Und \pkg{fancyhdr}s interner Seitenstil
% \pstyle{@empty} ist ebenfalls identisch mit \pstyle{empty}. Daher
% verwendet auch \pstyle{@empty} die Ebenen von \pstyle{empty}, aber Sie
% sollten nicht versuchen, diese direkt mit der Schnittstelle von
% \pkg{scrlayer} zu verändern. Mehr noch, wenn
% \pkg{fancyhdr} vor \pkg*{scrlayer-fancyhdr} geladen wird, ist
% der interne Seitenstil \pstyle{@empty} von \pkg{fancyhdr}
% nicht länger eine Kopie des Ebenen-Seitenstils \pstyle{empty} von
% \pkg{scrlayer}, sondern weiterhin des Standard-Seitenstils
% \pstyle{empty}. Allerdings verwendet \pkg{fancyhdr} mit
% \pkg*{scrlayer-fancyhdr} selbst den internen Seitenstil
% \pstyle{@empty} gar nicht mehr. Daher brauchen Sie das eigentlich auch
% nicht zu wissen.
%
% \section{Wie man das Paket verwendet}
% \label{sec:verwendung}
%
% Um das Paket zu verwenden, muss man es laden, beispielsweise per:
%\begin{verbatim}
% \usepackage{scrlayer-fancyhdr}
%\end{verbatim}
% an Stelle von \pkg{scrlayer} oder \pkg{fancyhdr} oder
% vor dem Laden eines dieser Pakete. Empfohlen wird das komplette Ersetzen von
% \pkg{scrlayer} und \pkg{fancyhdr} durch das Laden von
% \pkg*{scrlayer-fancyhdr}, weil dadurch Optionskonflikte
% (engl. \emph{option clash}) vermieden wird. \pkg*{scrlayer-fancyhdr}
% stellt alle Optionen von \pkg{scrlayer} und
% \pkg{fancyhdr} bereit und leitet diese an
% \pkg{scrlayer} bzw. \pkg{fancyhdr}
% weiter. Nichtsdestotrotz kann es in seltenen Fällen nützlich sein, dass man
% das Paket auch zusätzlich nach \pkg{scrlayer} und
% \pkg{fancyhdr} laden kann. In diesem Fall sollte
% \pkg{scrlayer} vor \pkg{fancyhdr} und zuletzt
% \pkg*{scrlayer-fancyhdr} geladen werden.
%
% \DescribeiPageStyle{@fancy}
% \DescribeiPageStyle{f@nch@fancycore}
% \DescribePageStyle{fancy}
% \DescribePageStyle{fancyplain}
% \DescribeiPageStyle{plain@fancy}
% \DescribeCommand\fancypagestyle
% Nach dem Laden des Pakets sollten Sie in der Lage sein, die Seitenstile und
% Befehle von \pkg{fancyhdr} zu verwenden und Ebenen zum internen
% \pkg{fancyhdr}-Seitenstil \pstyle{@fancy} (bis einschließlich
% \pkg{fancyhdr} Version 3.10) bzw. \pstyle{f@nch@fancycore} (ab
% \pkg{fancyhdr} Version 4) hinzuzufügen oder davon zu
% entfernen. Hinweis: Es ist Ihnen nicht möglich, Ebenen zu den
% \pkg{fancyhdr}-Seitenstilen \pstyle{fancy},
% \pstyle{fancyplain}, \pstyle{plain@fancy} oder jedem anderen mit
% \cs{fancypagestyle} definierten Seitenstil hinzuzufügen. Jedoch wird das
% Hinzufügen oder Entfernen von Ebenen zu bzw. von \pstyle{@fancy} (bis
% einschließlich \pkg{fancyhdr} Version 3.10)
% bzw. \pstyle{f@nch@fancycore} (ab \pkg{fancyhdr} Version 4)
% immer alle diese Seitenstile mit ändern!
%
% \DescribePageStyle{plain}
% \DescribePageStyle{headings}
% \DescribePageStyle{myheadings}
% \DescribePageStyle{empty}
% Hinweis: Das Laden von Paket \pkg*{scrlayer-fancyhdr} wird weder den
% Seitenstil \pstyle{plain} noch \pstyle{headings} noch
% \pstyle{myheadings} noch irgend einen anderen Seitenstil außer
% \pstyle{empty} automatisch in einen Ebenen-Seitenstil umwandeln! Wenn Sie
% aber Option \opt{headings} oder \opt{myheadings} angeben, definiert
% \pkg{fancyhdr} die entsprechenden Seitenstile in
% \pkg{fancyhdr}-Seitenstil um --~somit hängen diese dann von
% demselben internen Seitenstil, entweder \pstyle{@fancy} (bis einschließlich
% \pkg{fancyhdr} Version 3.10) oder \pstyle{f@nch@fancycore} (ab
% \pkg{fancyhdr} Version 4), ab.
%
%
%
% \section{Tipp}
% \label{sec:tipp}
%
% Um unabhängig von der verendeten Version von \pkg{fancyhdr} zu
% werden, kann man:
% \begin{verbatim}
% \IfPackageAtLeastTF{fancyhdr}{2019/03/21}{%
%   \DeclarePageStyleAlias{@fancy}{f@nch@fancycore}%
% }{%
%   \DeclarePageStyleAlias{f@nch@fancycore}{@fancy}%
% }
% \end{verbatim}^^A
% \unskip nach dem Laden von \pkg*{scrlayer-fancyhdr} verwendenm, bevor man
% irgendwelche Ebenen zu dem internen Seitenstil hinzufügt oder davon
% entfernt. Diese Codezeilen definieren bei Verwendung von
% \pkg{fancyhdr} aber Version 4.0 Seitenstil \pstyle{@fancy} als
% Alias für Seitenstil \pstyle{f@nch@fancycore} und umgekehrt für
% \pkg{fancyhdr} bis einschließlich Version 3.10
% \pstyle{f@ch@fancycore} als Alias für Seitenstil \pstyle{@fancy}. Damit
% führt dann sowohl:
% \begin{verbatim}
% \AddLayersToPageStyle{@fancy}{...}
% \end{verbatim}^^A
% \unskip als auch
% \begin{verbatim}
% \AddLayersToPageStyle{f@nch@fancycore}{...}
% \end{verbatim}^^A
% \unskip dazu, dass die Ebenen zum internen Ebenen-Seitenstil hinzugefügt
% werden.
%
%
%
% \section{Bekannte Probleme}
% \label{sec:probleme}
%
% Bitte beachten Sie, dass die folgenden Hinweise entweder Notizen für den
% Paketautor oder Hinweise für die Anwender darstellen und verhindern sollen,
% dass dieselben Probleme immer wieder gemeldet werden. Die Auflistung sagt
% nichts darüber aus, ob es sich dabei um Fehler oder Eigenschaften handelt:
% \begin{itemize}
% \item
%   \DescribePageStyle{fancy}
%   \DescribeiPageStyle{f@nch@fancycore}
%   \DescribePageStyle{fancyplain}
%   \DescribeCommand\fancypagestyle
%   \DescribeiPageStyle{@fancy}
%   Sie können keine Ebenen zu den Seitenstilen auf Benutzerebene
%   \pstyle{fancy} oder \pstyle{fancyplain} oder irgendwelchen anderen
%   Seitenstilen, die mit \cs{fancypagestyle} definiert wurden,
%   hinzufügen. Dies ist nur für den internen Seitenstil \pstyle{@fancy} (bis
%   einschließlich \pkg{fancyhdr} Version 3.10)
%   bzw. \pstyle{f@nch@fancycore} (ab \pkg{fancyhdr} Version 4)
%   möglich (see auch Abschnitt~\ref{sec:tipp}).
% \item 
%   \DescribeiPageStyle{@empty}
%   Die Verwendung des internen \pkg{fancyhdr}-Seitenstils
%   \pstyle{@empty} kann zu unerwarteten Ergebnissen führen. Es gibt jedoch
%   eine einfache Lösung für dieses Problem: Verwenden Sie nicht den internen
%   Seitenstile \pstyle{@empty}, sondern immer den Seitenstile
%   \pstyle{empty} der Benutzerebene.
% \item
%   \DescribeiPageStyle{@fancy}
%   \DescribeiPageStyle{f@nch@fancycore}
%   Die vertikale Position des Seitenkopfes weicht ein wenig ab, wenn
%   \pkg*{scrlayer-fancyhdr} an Stelle von \pkg{fancyhdr}
%   verwendet wird. Dies kann durch leichte Modifikation der Ebenen
%   \texttt{fancy.head.odd} und \texttt{fancy.head.even} mit Hilfe von
%   \opt{addvoffset} behoben werden. Weitere Tests sind hier erforderlich.
% \item
%   Die neuen Möglichkeiten von \pkg{fancyhdr} v5 sind weitgehend ungetested.
% \end{itemize}
% Siehe \url{https://github.com/komascript/scrlayer-fancyhdr/issues} für
% weitere bekannte Probleme.
%
%\iffalse
%</dtx>
%\fi
%
% \StopEventually{}
%
% \selectlanguage{english}
% \part{Implementation of \pkg{scrlayer-fancyhdr}}
% \label{sec:scrlayer-fancyhdr}
%
% \sloppy^^A Good paragraph breaking is not the purpose of implementation
%        ^^A documentation.
% \iffalse
%<*package>
% \fi
%
% This section if for developers only.
%
% We need \pkg{scrlayer} at least version 2021/02/15,
%    \begin{macrocode}
%<*init>
\RequirePackage{scrlayer}[2021/02/15]
%</init>
%    \end{macrocode}
% Because before \cs{scrlayer@do@inherited@options} would not be defined. And
% we need it, to inherit all options of \pkg{scrlayer}.
%    \begin{macrocode}
%<*options>
\scrlayer@do@inherited@options{\scrlayer@inherit@option}
%</options>
%    \end{macrocode}
%
% And the very first thing at the body, after definition of the options is to
% process the options.
%    \begin{macrocode}
%<*body>
\KOMAProcessOptions
%</body>
%    \end{macrocode}
%
% Note: The main problem of this interface is, that it tries to implement the
% user interface of package \pkg{fancyhdr} by Piet van Oostrum, that is
% completely different from \pkg{scrlayer} and not really compatible with
% \pkg{scrlayer}, using \pkg{scrlayer}. This means, that
% \pkg*{scrlayer-fancyhdr} never can be a drop-in replacement of
% \pkg{fancyhdr}. Nevertheless it can help to let \pkg{scrlayer} and
% \pkg{fancyhdr} coexist. To do so
% \begin{itemize}
% \item the lowest level of \pkg{fancyhdr} should not be the page style
% but a layer
% \item the page styles of \pkg{fancyhdr} should be layer page styles
% \item init code of the page styles of \pkg{fancyhdr} should use the
% layer page init code
% \end{itemize}
% Currently it is unsure whether it would be best to do a new implementation
% or to load original \pkg{fancyhdr} and to only modify some things. First
% I'll try the second method. Currently we explicitly provide the options of
% \pkg{fancyhdr}.
% \changes{v0.3}{2025-01-07}{new \pkg{fancyhdr} option \opt{twoside}}
%    \begin{macrocode}
%<*options>
\DeclareOption{nocheck}{\PassOptionsToPackage{nocheck}{fancyhdr}}
\DeclareOption{compatV3}{\PassOptionsToPackage{compatV3}{fancyhdr}}
\DeclareOption{myheadings}{\PassOptionsToPackage{myheadings}{fancyhdr}}
\DeclareOption{headings}{\PassOptionsToPackage{headings}{fancyhdr}}
\DeclareOption{twoside}{\PassOptionsToPackage{twoside}{fancyhdr}}
%</options>
%    \end{macrocode}
%    \begin{macrocode}
%<*body>
\RequirePackage{fancyhdr}
%</body>
%    \end{macrocode}
%
% We need at least one new layer for the new layer page style
% \pstyle{fancy}. However, it could be useful to have not only one but
% four layers (even side head, odd side head, even side foot, odd side foot).
% \changes{v0.3}{2025-01-07}{\cs{f@nch@head} and \cs{f@nch@foot} have 8
%   arguments with \pkg{fancyhdr} v5}
% \changes{v0.3.1}{2025-01-07}{missing backslashs added}
% \changes{v0.4}{2025-02-10}{\cs{f@nch@head} and \cs{f@nch@foot} have 6
%   arguments with \pkg{fancyhdr} v5.2}
%    \begin{macrocode}
%<*body>
\IfPackageAtLeastTF{fancyhdr}{2025/02/07}{%
  \DeclareNewLayer[%
    background,oddpage,
    head,
    contents={\hb@xt@ \layerwidth{%
        \f@nch@head\f@nch@Oolh\f@nch@olh\f@nch@och\f@nch@orh\f@nch@Oorh{o}%
    }}%
  ]{fancy.head.odd}
  \DeclareNewLayer[%
    background,evenpage,
    head,
    contents={\hb@xt@ \layerwidth{%
        \f@nch@head\f@nch@Oelh\f@nch@elh\f@nch@ech\f@nch@erh\f@nch@Oerh{e}%
    }}%
  ]{fancy.head.even}
  \DeclareNewLayer[%
    foreground,oddpage,
    foot,
    contents={\hb@xt@ \layerwidth{%
        \f@nch@foot\f@nch@Oolf\f@nch@olf\f@nch@ocf\f@nch@orf\f@nch@Oorf{o}%
    }}%
  ]{fancy.foot.odd}
  \DeclareNewLayer[%
    foreground,evenpage,
    foot,
    contents={\hb@xt@ \layerwidth{%
        \f@nch@foot\f@nch@Oelf\f@nch@elf\f@nch@ecf\f@nch@erf\f@nch@Oerf{e}%
    }}%
  ]{fancy.foot.even}
}{%
  \IfPackageAtLeastTF{fancyhdr}{2025/01/01}{%
    \DeclareNewLayer[%
      background,oddpage,
      head,
      contents={\hb@xt@ \layerwidth{%
          \f@nch@head\f@nch@Oolh\f@nch@olh\f@nch@och\f@nch@orh\f@nch@Oorh
                     \f@nch@width@olh\f@nch@width@och\f@nch@width@orh
      }}
    ]{fancy.head.odd}
    \DeclareNewLayer[%
      background,evenpage,
      head,
      contents={\hb@xt@ \layerwidth{%
          \f@nch@head\f@nch@Oelh\f@nch@elh\f@nch@ech\f@nch@erh\f@nch@Oerh
                     \f@nch@width@elh\f@nch@width@ech\f@nch@width@erh
      }}
    ]{fancy.head.even}
    \DeclareNewLayer[%
      foreground,oddpage,
      foot,
      contents={\hb@xt@ \layerwidth{%
          \f@nch@foot\f@nch@Oolf\f@nch@olf\f@nch@ocf\f@nch@orf\f@nch@Oorf
                     \f@nch@width@olf\f@nch@width@ocf\f@nch@width@orf
      }}
    ]{fancy.foot.odd}
    \DeclareNewLayer[%
      foreground,evenpage,
      foot,
      contents={\hb@xt@ \layerwidth{%
          \f@nch@foot\f@nch@Oelf\f@nch@elf\f@nch@ecf\f@nch@erf\f@nch@Oerf
          \f@nch@width@elf\f@nch@width@ecf\f@nch@width@erf
      }}
    ]{fancy.foot.even}
  }{%
    \DeclareNewLayer[%
      background,oddpage,
      head,
      contents={\hb@xt@ \layerwidth{%
          \f@nch@head\f@nch@Oolh\f@nch@olh\f@nch@och\f@nch@orh\f@nch@Oorh
      }}
    ]{fancy.head.odd}
    \DeclareNewLayer[%
      background,evenpage,
      head,
      contents={\hb@xt@ \layerwidth{%
          \f@nch@head\f@nch@Oelh\f@nch@elh\f@nch@ech\f@nch@erh\f@nch@Oerh
      }}
    ]{fancy.head.even}
    \DeclareNewLayer[%
      foreground,oddpage,
      foot,
      contents={\hb@xt@ \layerwidth{%
          \f@nch@foot\f@nch@Oolf\f@nch@olf\f@nch@ocf\f@nch@orf\f@nch@Oorf
      }}
    ]{fancy.foot.odd}
    \DeclareNewLayer[%
      foreground,evenpage,
      foot,
      contents={\hb@xt@ \layerwidth{%
          \f@nch@foot\f@nch@Oelf\f@nch@elf\f@nch@ecf\f@nch@erf\f@nch@Oerf
      }}
    ]{fancy.foot.even}
  }%
}
%    \end{macrocode}
% \begin{ipgstyle}{f@nch@fancycore}
% \changes{0.1.3558}{2021/02/15}{support for \pkg{fancyhdr} 4}
% \begin{ipgstyle}{@fancy}
% \begin{macro}{\@mkboth}
% And have to create a layer page style from this new layers, but we do not
% redefine page style \pstyle{fancy} but the low level page style
% \pstyle{@fancy} (up to \pkg{fancyhdr} version 3.10)
% resp. \pstyle{f@nch@fancycore} (from \pkg{fancyhdr} version 4.0).
%
% \pkg{fancyhdr} does some initialization at the very first call
% of \cs{pagestyle{fancy}}. To do so \pkg{fancyhdr} first uses a different
% page style definition, that does the initialization and redefines the page
% style afterwards. This is still active with \pkg*{scrlayer-fancyhdr}.
% Additionally, \pkg{fancyhdr} redefines \cs{@mkboth} at every selection
% of the internal page style \pstyle{@fancy}
% resp. \pstyle{f@nch@fancycore}. This can be adapted using the
% \opt{onselect} feature of the new layer page style \pstyle{@fancy}
% resp. \pstyle{f@nch@fancycore}. In my opinion, the
% |\let\@mkboth\markboth| used by page style \pstyle{headings} of, e.\,g.,
% the standard classes or the \KOMAScript{} classes would be best
% here. However, \pkg{fancyhdr} uses the uncommon
% |\def\@mkboth{\protect\markboth}|, which would fail if a class or package
% tests \cs{@mkboth} using |\ifx\@mkboth\markboth|. However, \KOMAScript's
% \cs{IfActiveMkBoth} (see the \pkg{scrbase} chapter in the \KOMAScript{}
% manual) does also recognize the \pkg{fancyhdr} definition and copying
% this is more compatible with \pkg{fancyhdr}.
%    \begin{macrocode}
\IfPackageAtLeastTF{fancyhdr}{2019/03/21}{%
  \DeclarePageStyleByLayers[
    onselect={\def\@mkboth{\protect\markboth}},
  ]{f@nch@fancycore}{%
    fancy.head.odd,fancy.head.even,fancy.foot.odd,fancy.foot.even
  }%
}{%
  \DeclarePageStyleByLayers[
    onselect={\def\@mkboth{\protect\markboth}},
  ]{@fancy}{%
    fancy.head.odd,fancy.head.even,fancy.foot.odd,fancy.foot.even
  }%
}
%</body>
%    \end{macrocode}
% Note: Redefining page style \pstyle{@fancy}
% resp. \pstyle{f@nch@fancycore} instead of \pstyle{fancy}
% does also mean, that features like options \opt{automark} and
% \opt{manualmark} resp. \cs{automark} and \cs{manualmark} are not fully
% supported by \pkg*{scrlayer-fancyhdr}. Also currently the font features
% of the \KOMAScript{} classes are not supported by
% \pkg*{scrlayer-fancyhdr}. However you are now able to combine other
% features of \pkg{scrlayer} with features of
% \pkg{fancyhdr} and you can, e.g., use
% \pkg{scrlayer-notecolumn} with \pkg*{scrlayer-fancyhdr}.
% \end{macro}%^^A \@mkboth
% \end{ipgstyle}%^^A @fancy
% \end{ipgstyle}%^^A f@nch@fancycore
%
% A future release of \pkg*{scrlayer-fancyhdr} may even provide the font
% features of the \KOMAScript{} classes and a working
% \opt{markcase}. However, in this case I would have to redefine the
% initial page style \pstyle{fancy} and the layers above.
%
% \iffalse
%</package>
% \fi
%
% \Finale
%
\endinput
%
% End of file `scrlayer-fancyhdr.dtx'.
%

%%% Local Variables:
%%% mode: doctex
%%% eval: (flyspell-mode 1)
%%% ispell-local-dictionary: "en_US"
%%% TeX-master: t
%%% End:
