summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/source/latex/koma-script/scrlayer-fancyhdr.dtx
blob: 830d9f20526e308b784a2497faf38678d4c2b54c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
% \iffalse^^A meta-comment
% ======================================================================
% scrlayer-fancyhdr.dtx
% Copyright (c) Markus Kohm, 2019
%
% This file is part of the LaTeX2e KOMA-Script bundle.
%
% 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 all files listed in manifest.txt and
% `scrlayer-fancyhdr.dtx'.
% ----------------------------------------------------------------------
% scrlayer-fancyhdr.dtx
% Copyright (c) Markus Kohm, 2019
%
% Diese Datei ist Teil der LaTeX2e KOMA-Script-Sammlung.
%
% Dieses Werk darf nach den Bedingungen der LaTeX Project Public Lizenz,
% Version 1.3c.
% Die neuste Version dieser Lizenz ist
%   http://www.latex-project.org/lppl.txt
% und Version 1.3c ist Teil aller Verteilungen von LaTeX
% Version 2005/12/01 und dieses Werks.
%
% Dieses Werk hat den LPPL-Verwaltungs-Status "author-maintained"
% (allein durch den Autor verwaltet).
%
% Der Aktuelle Verwalter und Autor dieses Werkes ist Markus Kohm.
%
% Dieses Werk besteht aus den in manifest.txt aufgefuehrten Dateien
% sowie `scrlayer-fancyhdr.dtx'.
% ======================================================================
% \fi^^A meta-comment
%
% \CharacterTable
%  {Upper-case    \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
%   Lower-case    \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z
%   Digits        \0\1\2\3\4\5\6\7\8\9
%   Exclamation   \!     Double quote  \"     Hash (number) \#
%   Dollar        \$     Percent       \%     Ampersand     \&
%   Acute accent  \'     Left paren    \(     Right paren   \)
%   Asterisk      \*     Plus          \+     Comma         \,
%   Minus         \-     Point         \.     Solidus       \/
%   Colon         \:     Semicolon     \;     Less than     \<
%   Equals        \=     Greater than  \>     Question mark \?
%   Commercial at \@     Left bracket  \[     Backslash     \\
%   Right bracket \]     Circumflex    \^     Underscore    \_
%   Grave accent  \`     Left brace    \{     Vertical bar  \|
%   Right brace   \}     Tilde         \~}
%
% \iffalse^^A meta-comment
%%% From File: $Id: scrlayer-fancyhdr.dtx 3138 2019-04-04 06:24:53Z kohm $
%<identify>%%%            (run: identify)
%<init>%%%            (run: init)
%<options>%%%            (run: options)
%<body>%%%            (run: body)
%<*dtx>
\ifx\ProvidesFile\undefined\def\ProvidesFile#1[#2]{}\fi
\begingroup
  \def\filedate$#1: #2-#3-#4 #5${\gdef\filedate{#2/#3/#4}}
  \filedate$Date: 2019-04-04 08:24:53 +0200 (Thu, 04 Apr 2019) $
  \def\filerevision$#1: #2 ${\gdef\filerevision{v0.1.#2 ALPHA}}
  \filerevision$Revision: 3138 $
  \edef\reserved@a{%
    \noexpand\endgroup
    \noexpand\ProvidesFile{scrlayer-fancyhdr.dtx}%
                          [\filedate\space\filerevision\space
                           KOMA-Script package source
  }%
\reserved@a
%</dtx>
%<*identify>
%<interface>\NeedsTeXFormat{LaTeX2e}[1995/12/01]
%<interface>\ProvidesPackage{scrlayer-fancyhdr}[%
% Sometimes following will be replaced by !KOMAScriptVersion:
%!SCRLAYERFANCYHDRVERSION
%<interface>  package
%</identify>
%<*dtx|identify>
  (end user interface for scrlayer)]
%</dtx|identify>
%<*dtx>
\ifx\documentclass\undefined
  \input scrdocstrip.tex
  \@@input scrkernel-version.dtx
  \@@input scrstrip.inc
  \KOMAdefVariable{COPYRIGHTFROM}{2018}
  \KOMAdefVariable{SCRLAYERFANCYHDRVERSION}{%
    \space\space\filedate\space\filerevision\space KOMA-Script
  }%
  \expandafter\let\csname ifbetawas\expandafter\endcsname
  \csname ifbeta\endcsname
  \expandafter\let\csname ifbeta\expandafter\endcsname
  \csname iftrue\endcsname
  \generate{\usepreamble\defaultpreamble
    \file{scrlayer-fancyhdr.sty}{%
      \from{scrlayer-fancyhdr.dtx}{interface,trace,fancyhdr,identify}%
      \from{scrlayer.dtx}{interface,trace,fancyhdr,init}%
      \from{scrlayer-fancyhdr.dtx}{interface,trace,fancyhdr,init}%
      \from{scrlayer.dtx}{interface,trace,fancyhdr,options}%
      \from{scrlayer-fancyhdr.dtx}{interface,trace,fancyhdr,options}%
      \from{scrlayer.dtx}{interface,trace,fancyhdr,body}%
      \from{scrlayer-fancyhdr.dtx}{interface,trace,fancyhdr,body}%
      \from{scrlogo.dtx}{logo}%
    }%
  }
  \expandafter\let\csname ifbeta\expandafter\endcsname
  \csname ifbetawas\endcsname
  \@@input scrstrop.inc
\else
  \let\endbatchfile\relax
\fi
\endbatchfile
  \documentclass{scrdoc}
  \addtolength{\textwidth}{-1em}
  \addtolength{\marginparwidth}{2em}
  \addtolength{\oddsidemargin}{2em}
  \usepackage[ngerman,english]{babel}
  \usepackage{url,babelbib}\bibliographystyle{babalpha-fl}
  \usepackage{listings}
  \usepackage{scrhack}
  \usepackage{etoolbox}
  \pretocmd\DescribeMacro{\ifhmode\else\bigskip\noindent\fi}{}{}
  \pretocmd\DescribeEnv{\ifhmode\else\bigskip\noindent\fi}{}{}
  \pretocmd\DescribeOption{\ifhmode\else\bigskip\noindent\fi}{}{}

  \CodelineIndex
  \RecordChanges
  \GetFileInfo{scrlayer-fancyhdr.dtx}
  \title{The \texttt{scrlayer} interface \texttt{scrlayer-fancyhdr}%
    \footnote{This is version \fileversion\ of file \texttt{\filename}.}}
  \date{\filedate}
  \author{Markus Kohm}

  \newenvironment{Explain}{\par}{\par}
  \newcommand*{\length}{}
  \let\length\Length
  \let\endlength\endLength
  \let\Macro\cs
  \let\Length\Macro
  \let\Package\textsf
  \let\Class\Package
  \let\File\texttt
  \let\Option\texttt
  \newcommand*{\KOption}[1]{\Option{#1}\texttt{=}}
  \newcommand*{\OptionValue}[2]{\Option{#1}\texttt{=}\PValue{#2}}
  \let\Counter\texttt
  \let\Environment\texttt
  \let\ShowOutput\quote
  \let\endShowOutput\endquote
  \let\Pagestyle\texttt
  \newcommand*{\Parameter}[1]{\texttt{\marg{#1}}\linebreak[1]}
  \newcommand*{\OParameter}[1]{\texttt{\oarg{#1}}\linebreak[1]}
  \newcommand*{\MParameter}[2]{\texttt{(\meta{#1},\meta{#2})}\linebreak[1]}
  \providecommand\PParameter[1]{\mbox{\texttt{\{#1\}}}\linebreak[1]}
  \let\PName\meta
  \let\PValue\texttt
  \providecommand*{\autoref}[1]{\expandafter\AUTOREF#1:}
  \providecommand*{\AUTOREF}{}
  \makeatletter
  \def\AUTOREF#1:#2:{%
    \edef\@tempa{#1}%
    \edef\@tempb{tab}\ifx\@tempa\@tempb table~\fi
    \edef\@tempb{sec}\ifx\@tempa\@tempb section~\fi
    \ref{#1:#2}%
  }
  \providecommand*{\IndexCmd}[2][]{}
  \providecommand*{\textnote}[2][]{}
  \providecommand*\eTeX{\leavevmode\hbox{$\varepsilon$}-\TeX}
  \providecommand*\NTS{%
    \leavevmode\hbox{$\cal N\kern-0.35em\lower0.5ex\hbox{$\cal T$}%
      \kern-0.2emS$}}

  \lstnewenvironment{lstcode}{\lstset{language=[LaTeX]TeX}}{}
  \makeatother
  \sloppy% YOU SHOULD NOT DO THIS!!!

  \begin{document}
  \maketitle
  \tableofcontents
  \DocInput{\filename}
  \PrintChanges
  \PrintIndex
  \end{document}
% \fi^^A meta-comment
%
% \selectlanguage{english}
%
% \changes{v0.0}{2018/09/01}{start of interface}
% \let\restorechapter\chapter
% \let\chapter\section
% \let\section\subsection
% \let\subsection\subsubsection
%
% \changes{v0.0}{2018/09/05}{some user documentation}
% \chapter{The Purpose of this Package}
% This package has been made to give users a chance to combine the features of
% Piet van Oostrum's \Package{fancyhdr} \cite{pkg:fancyhdr} with the features
% of \Package{scrlayer} \cite{pkg:komascript}. In other words: It has been
% made to combine the page layers of \Package{scrlayer} with the page styles
% of \Package{fancyhdr}.
%
% In this combination compatibility with \Package{fancyhdr} is the first
% aim! Usability and the freedom provided by \Package{scrlayer} is only the
% second one. Compatibility with other parts of \KOMAScript{} is not a primary
% aim. Perhaps it will become an optional feature in future. Abolishing any
% real or virtual limitations of \Package{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 \Package{scrlayer} to define your page
% styles or\,---\,and this is the recommendation of the author\,---\,use
% \Package{scrlayer-scrpage} instead of \Package{scrlayer-fancyhdr} or
% \Package{fancyhdr}. If you need more compatibility with other parts of
% \KOMAScript, i.\,e.\@ with the \KOMAScript{} classes, you should use
% \Package{scrlayer-scrpage} instead of \Package{scrlayer-fancyhdr} or
% \Package{fancyhdr}.
%
%
% \chapter{How it works}
% To combine \Package{fancyhdr} and \Package{scrlayer},
% \Package{scrlayer-scrpage} loads both packages. After loading
% \Package{fancyhdr} it redefines page style \Pagestyle{@fancy} to make it a
% layer page style of \Package{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 \Package{fancyhdr}'s page styles (or
% other usual page styles). The \texttt{\dots foot\dots} layers are foreground
% layers like the page footer of \Package{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.
%
% \DescribeMacro\ps@@fancy
% \DescribeMacro\ps@fancyplain
% \DescribeMacro\ps@plain@fancy
% Note: Page style \Pagestyle{@fancy} is an internal basic page style of
% package \Package{fancyhdr}. It is used for the user page style
% \Pagestyle{fancy}. The user page style \Pagestyle{fancy} is also used for
% \Package{fancyhdr}'s undocumented page style \Pagestyle{fancyplain}, that
% also redefines page style \Pagestyle{plain} to be \Package{fancyhdr}'s
% internal page style \Pagestyle{plain@fancy}, that also uses
% \Pagestyle{fancy} but with \Macro{if@fancyplain} set to
% \Macro{iftrue}. There is also an undocumented command
% \Macro{fancyplain}\Parameter{plain code}\Parameter{fancy code}, that uses
% the \meta{plain code} if \Macro{if@fancyplain} is \Macro{iftrue} and
% \meta{fancy code} if \Macro{if@fancyplain} is \Macro{iffalse}.
%
% Note: Page styles defined using \Package{fancyhdr}'s command
% \Macro{fancypagestyle} also always use page style \Pagestyle{fancy} and so
% the internal basic page style \Pagestyle{@fancy}.
%
% As a result of the two notes above, every page style of \Package{fancyhdr}
% always uses page style \Pagestyle{fancy} and the same internal basic page
% style \Pagestyle{@fancy}. As a result of redefining page style
% \Pagestyle{@fancy} to be a layer page style, users can add layers to or
% remove layers from all \Package{fancyhdr} page styles by adding layers to or
% remove layers from page style \Pagestyle{@fancy}. You cannot add layers to
% or remove layers from \Package{fancyhdr}'s single page styles
% \Pagestyle{fancy}, \Pagestyle{fancyplain}, \Pagestyle{plain@fancy} or the
% page styles defined using \Macro{fancypagestyle} directly. So using layers
% is a all or nothing feature with \Package{scrlayer-scrpage}. However, you
% can use the second argument of \Macro{fancypagestyle} to add or remove
% layers whenever one of the \Package{fancyhdr} page styles is activated. So
% this is a move from the \Package{scrlayer} interface of adding or removing
% layers to single page styles to the \Package{fancyhdr} interface of defining
% modifications of page style \Pagestyle{fancy}.
%
% Another such movement from an \Package{scrlayer} user interface to a
% \Package{fancyhdr} user interface it the decision whether or not automatic
% running heads are used. \Package{scrlayer} provides the options
% \Option{automark} and \Option{manualmark} and commands \Macro{automark} and
% \Macro{manualmark} to do this decision and also to configure commands like
% \Macro{partmark}, \Macro{chaptermark}, \Macro{sectionmark} etc. With
% \Package{scrlayer-fancyhdr} also using page style \Pagestyle{@fancy} does
% switch to automatic running heads. The first activation of page style
% \Pagestyle{fancy} still redefines \Macro{chaptermark} and
% \Macro{sectionmark}, if a class with \Macro{chapter} is used, or
% \Macro{sectionmark} and \Macro{subsectionmark}, if a class without
% \Macro{chapter} is used. However, you still can use \Macro{manualmark} and
% \Macro{automark} after switching to a \Package{fancyhdr} page style to
% configure the running heads. So this movement is only partial.
%
% \DescribeMacro\ps@headings
% \DescribeMacro\ps@myheadings
% \DescribeMacro\ps@plain
% Note: Currently, neither \Package{scrlayer} nor \Package{fancyhdr} nor
% \Package{scrlayer-fancyhdr} do redefine page styles \Pagestyle{headings} or
% \Pagestyle{myheadings}. And neither \Package{scrlayer} nor
% \Package{fancyhdr} nor \Package{scrlayer-fancyhdr} do redefine page style
% \Pagestyle{plain} unless you are activating the undocumented
% \Package{fancyhdr} page style \Pagestyle{fancyplain}. So if you like to use
% layers on \Pagestyle{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
% \Package{fancyhdr}'s undocumented page style \Pagestyle{fancyplain} or
% redefine page style \Pagestyle{plain} either using \Macro{fancypagestyle} as
% documented in the \Package{fancyhdr} manual or using
% \Macro{DeclareNewPageStyleByLayers}, documented in the \KOMAScript{} manual.
%
% \DescribeMacro\ps@empty
% \DescribeMacro\ps@@empty
% Note: Pagestyle \Pagestyle{empty} is somehow special. \Package{scrlayer}
% redefines it to be a layer page style. And \Package{fancyhdr}'s internal
% page style \Pagestyle{@empty} is the same like \Pagestyle{empty}. So
% \Pagestyle{@empty} also uses the layers of \Pagestyle{empty} but you should
% not try to modify it directly using the interface of
% \Package{scrlayer}. Moreover, if \Package{fancyhdr} is loaded before
% \Package{scrlayer-scrpage}, \Package{fancyhdr}'s internal page style
% \Pagestyle{@empty} is not a copy of \Package{scrlayer}'s layer page style
% \Pagestyle{empty} but the original standard page style
% \Pagestyle{empty}. However, with \Package{scrlayer-fancyhdr} package
% \Package{fancyhdr} does not longer use the internal page style
% \Pagestyle{@empty}. So you would not need to know this.
%
% \chapter{How to use the Package}
%
%^^A TODO: Remove the following alpha note.
% First of all, this package is experimental and should not be used for
% anything else but testing whether or not it works as documented! This
% package even is not an official part of \KOMAScript!
%
% To use the package you have to load it, e.\,g., using:
%\begin{verbatim}
% \usepackage{scrlayer-fancyhdr}
%\end{verbatim}
% instead of loading \Package{scrlayer} and \Package{fancyhdr} or before or
% after loading one of these packages. However it is recommended to replace
% loading \Package{scrlayer} and \Package{fancyhdr} by loading
% \Package{scrlayer-fancyhdr} because this avoids option
% clashes. \Package{scrlayer-fancyhdr} provides all options of
% \Package{scrlayer} and passes them to \Package{scrlayer}. Nevertheless
% sometimes it may be useful to be able to additionally load
% \Package{scrlayer} or \Package{fancyhdr}.
%
% \DescribeMacro\ps@@fancy
% \DescribeMacro\ps@fancy
% \DescribeMacro\ps@fancyplain
% \DescribeMacro\ps@plain@fancy
% \DescribeMacro\fancypagestyle
% After this you should be able to use the page styles and commands of
% \Package{fancyhdr} and to add layers to or remove layers from the
% \Package{fancyhdr}'s internal basic page style \Package{@fancy}. Note, you
% are not able to add layers to or remove layers from \Package{fancyhdr}'s
% page styles \Pagestyle{fancy}, \Pagestyle{fancyplain},
% \Pagestyle{plain@fancy} or page styles defined by
% \Macro{fancypagestyle}. However adding layers to or removing layers from
% \Pagestyle{@fancy} will always change all these page styles!
%
% \DescribeMacro\ps@plain
% \DescribeMacro\ps@headings
% \DescribeMacro\ps@myheadings
% \DescribeMacro\ps@empty
% Note: Loading \Package{scrlayer-fancyhdr} will not make page style
% \Pagestyle{plain} nor \Pagestyle{headings} nor \Pagestyle{myheadings} or any
% other page style but \Pagestyle{empty} to automatically be a layer page
% style!
%
% \chapter{Known 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
%   \DescribeMacro\ps@fancy
%   \DescribeMacro\ps@fancyplain
%   \DescribeMacro\fancypagestyle
%   \DescribeMacro\ps@@fancy
%   You are not able to add layers to the user level page style
%   \Pagestyle{fancy} or \Pagestyle{fancyplain} or any page style defined by
%   \Macro{fancypagestyle} but only to the internal page style
%   \Pagestyle{@fancy}. This is intended as explained in this manual.
% \item
%   \DescribeMacro\ps@@empty
%   Using \Package{fancyhdr}'s internal page style \Pagestyle{@empty}
%   could have strange results. However, there is a simple solution for this:
%   Don't use the internal \Pagestyle{@empty} but always the user level page
%   style \Pagestyle{empty}!
% \item
%   \DescribeMacro\ps@@fancy
%   The vertical position of the page header does differ a little bit, if
%   \Package{scrlayer-fancyhdr} is used instead of \Package{fancyhdr}. This
%   could be fixed by a modification of the layers \texttt{fancy.head.odd} and
%   \texttt{fancy.head.even} using \Option{addvoffset}. More tests are needed.
% \end{itemize}
%
%\iffalse
%</dtx>
%\fi
%
% \StopEventually{}
%
% \chapter{Implementation of \Package{scrlayer-fancyhdr}}
% \label{sec:scrlayer-fancyhdr}
%
% This section if for developers only.
%
% \iffalse
% TODO: Remove this alpha warning (but not the markers)!
%<*interface>
%<*identify>
\PackageWarningNoLine{scrlayer-fancyhdr}{%
  THIS IS AN ALPHA VERSION OF AN\MessageBreak
  EXPERIMENTAL PACKAGE!\MessageBreak
  YOU SHOULD NOT USE THIS PACKAGE FOR\MessageBreak
  ANYTHING ELSE BUT TESTING%
}
%</identify>
%\fi
%
% Note: The main problem of this interface is, that it tries to implement the
% user interface of package \Package{fancyhdr} by Piet van Oostrum, that is
% completely different from \Package{scrlayer} and not really compatible with
% \Package{scrlayer}, using \Package{scrlayer}. This means, that
% \Package{scrlayer-fancyhdr} never can be a drop-in replacement of
% \Package{fancyhdr}. Nevertheless it can help to let \Package{scrlayer} and
% \Package{fancyhdr} coexist. To do so
% \begin{itemize}
% \item the lowest level of \Package{fancyhdr} should not be the page style
% but a layer
% \item the page styles of \Package{fancyhdr} should be layer page styles
% \item init code of the page styles of \Package{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 \Package{fancyhdr} and to only modify some things. First
% I'll try the second method and therefore:
%    \begin{macrocode}
%<*body>
\RequirePackage{fancyhdr}
%</body>
%    \end{macrocode}
%
% We need at least one new layer for the new layer page style
% \Pagestyle{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).
%    \begin{macrocode}
%<*body>
\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{macro}{\ps@@fancy}
% \begin{macro}{\@mkboth}
% And have to create a layer page style from this new layers, but we do not
% redefine page style \Pagestyle{fancy} but the low level page style
% \Pagestyle{@fancy}. 
%    \begin{macrocode}
\DeclarePageStyleByLayers[
%    \end{macrocode}
% \Package{fancyhdr} does some initialization at the very first call
% of \cs{pagestyle{fancy}}. To do so \Package{fancyhdr} first uses a different
% page style definition, that does the initialization and redefines the page
% style afterwards. This is still active with \Package{scrlayer-fancyhdr}.
% Additionally, \Package{fancyhdr} redefines \cs{@mkboth} at every selection
% of the internal page style \Pagestyle{@fancy}. This can be adapted using the
% \Option{onselect} feature of the new layer page style \Pagestyle{@fancy}. In
% my opinion, the |\let\@mkboth\markboth| used by page style
% \Pagestyle{headings} of, e.\,g., the standard classes or the \KOMAScript{}
% classes would be best here. However, \Package{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 \Package{scrbase} chapter in the \KOMAScript{}
% manual) does also recognize the \Package{fancyhdr} definition and copying
% this is more compatible with \Package{fancyhdr}.
%    \begin{macrocode}
  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 \Pagestyle{@fancy} instead of \Pagestyle{fancy}
% does also mean, that features like options \Option{automark} and
% \Option{manualmark} resp. \cs{automark} and \cs{manualmark} are not fully
% supported by \Package{scrlayer-fancyhdr}. Also currently the font features
% of the \KOMAScript{} classes are not supported by
% \Package{scrlayer-fancyhdr}. However you are now able to combine other
% features of \Package{scrlayer} with features of \Package{fancyhdr} and you
% can, e.g., use \Package{scrlayer-notecolumn} with
% \Package{scrlayer-fancyhdr}.
% \end{macro}%^^A \@mkboth
% \end{macro}%^^A \ps@@fancy
%
% A future release of \Package{scrlayer-fancyhdr} may even provide the font
% features of the \KOMAScript{} classes and a working
% \Option{markcase}. However, in this case I would have to redefine the
% initial page style \Pagestyle{fancy} and the layers above.
%
% \iffalse
%</interface>
% \fi
%
% \begin{thebibliography}{99}
% \raggedright
% \bibitem[1]{pkg:fancyhdr} Piet van Oostrum: \emph{Page layout in \LaTeX},
%   release 3.9a 2017-06-30,
%   \url{https://ctan.org/tex-archive/macros/latex/contrib/fancyhdr},
%   last visited: 2018-09-06.
% \bibitem[2]{pkg:komascript} Markus Kohm: \emph{\KOMAScript},
%   release 3.25 2018-03-30,
%   \url{https://ctan.org/tex-archive/macros/latex/contrib/koma-script},
%   last visited: 2018-09-06.
% \end{thebibliography}
%
% \Finale
% \let\subsection\section
% \let\section\chapter
% \let\chapter\restorechapter
%
\endinput
%
% End of file `scrlayer-fancyhdr.dtx'.
%

%%% Local Variables:
%%% mode: doctex
%%% mode: flyspell
%%% ispell-local-dictionary: "en_GB"
%%% TeX-master: t
%%% End: