% \CheckSum{2389}
% \iffalse
% ======================================================================
% scrpage.dtx
% Copyright (c) Markus Kohm, 1995-2017
%
% 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 or later 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.
% ----------------------------------------------------------------------
% scrpage.dtx
% Copyright (c) Markus Kohm, 1995-2017
%
% Dieses Werk darf nach den Bedingungen der LaTeX Project Public Lizenz,
% Version 1.3c, verteilt und/oder veraendert werden.
% 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 oder spaeter 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.
% ======================================================================
% \fi
%
% \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
%%% From File: $Id: scrpage.dtx 2640 2017-05-08 09:36:55Z kohm $
%<scrpage>\NeedsTeXFormat{LaTeX2e}[1995/06/01]
%<*dtx>
\ifx\ProvidesFile\undefined\def\ProvidesFile#1[#2]{}\fi
\begingroup
  \def\filedate$#1: #2-#3-#4 #5${\gdef\filedate{#2/#3/#4}}
  \filedate$Date: 2017-05-08 11:36:55 +0200 (Mon, 08 May 2017) $
  \def\filerevision$#1: #2 ${\gdef\filerevision{r#2}}
  \filerevision$Revision: 2631 $
  \edef\reserved@a{%
    \noexpand\endgroup
    \noexpand\ProvidesFile{scrpage.dtx}%
                          [\filedate\space\filerevision\space
                           KOMA-Script package source
  }%
\reserved@a
%</dtx>
%<*dtx|scrpage>
%<scrpage>\ProvidesPackage{scrpage2}[%
%!KOMAScriptVersion
%<scrpage>  package
  (page head and foot)]
%</dtx|scrpage>
%<*dtx>
\ifx\documentclass\undefined
  \input scrdocstrip.tex
  \@@input scrkernel-version.dtx
  \@@input scrstrip.inc
  \KOMAdefVariable{COPYRIGHFROM}{1995}
  \generate{\usepreamble\defaultpreamble
    \file{scrpage2.sty}{%
      \from{scrpage.dtx}{scrpage}%
      \from{scrlogo.dtx}{logo}%
    }%
  }
  \@@input scrstrop.inc
\else
  \let\endbatchfile\relax
\fi
\endbatchfile
\documentclass{scrdoc}
\usepackage[ngerman,english]{babel}
\usepackage[latin1]{inputenc}
\CodelineIndex
\RecordChanges
\GetFileInfo{scrpage.dtx}
\title{\KOMAScript{} \partname\ \texttt{\filename}\thanks{This file has
    revision number \fileversion, last revised \filedate.}}
\date{\filedate}
\author{Markus Kohm}
\begin{document}
  \maketitle
  \tableofcontents
  \DocInput{\filename}
\end{document}
%</dtx>
% \fi
%
% \section{Page Layout Package}
%
% This is the \KOMAScript{} package \textsf{scrpage2}.  You may find the user
% documentation of this package in the English \KOMAScript{} guide,
% \texttt{scrguien.pdf}, and in the German \KOMAScript{} guide,
% \texttt{scrguide.pdf}.
%
% \StopEventually{\PrintIndex\PrintChanges}
%
% \section{Implementation}
%
% Currently this package doesn't share any code but the \KOMAScript{} logo
% with other packages.  So all the code of this package but the implementation
% of the \KOMAScript{} logo is at this file and their is nor more code at this
% file.
%
% \changes{v3.24}{2017/05/08}{warning about obsolete package added}
%    \begin{macrocode}
%<*scrpage>
\PackageWarning{scrpage2}{usage of obsolete package!\MessageBreak
  Package `scrpage2' is obsolete.\MessageBreak
  You should not longer use package `scrpage2'.\MessageBreak
  You should replace usage of package `scrpage2'\MessageBreak
  by `scrlayer-scrpage'}
%    \end{macrocode}
% \changes{v1.1}{1995/06/27}{\cs{hbox to} changed into \cs{hb@xt@}.}
% \changes{v2.2c}{2007/07/23}{a lot of \% added and removed}
%
% \subsection{Options}
% \begin{option}{headinclude}
%   \changes{v2.3}{2008/12/08}{obsolete}%
% \begin{option}{headexclude}
%   \changes{v2.3}{2008/12/08}{obsolete}%
% \begin{option}{footinclude}
%   \changes{v2.3}{2008/12/08}{obsolete}%
% \begin{option}{footexclude}
%   \changes{v2.3}{2008/12/08}{obsolete}%
% \texttt{scrpage} has known some options. They are similar to the
% old \KOMAScript{} classes. To work with and without the \KOMAScript{}
% classes their definitions are not quite simple.
%    \begin{macrocode}
\newcommand*{\@Pass@Obsolete@Option@To@Typearea}[1]{%
  \@expandtwoargs\in@{,\CurrentOption,}{,\@curroptions,}%
  \ifin@
    \PackageWarningNoLine{scrpage2}{%
      deprecated passing option `\CurrentOption' to scrpage2.\MessageBreak
      If you are using package typearea or\MessageBreak
      a KOMA-Script class since version 3.00\MessageBreak
      you may use `\string\KOMAoptions{#1}' and\MessageBreak
      remove passing `\CurrentOption' to scrpage2%
    }%
    \begingroup\expandafter\expandafter\expandafter\endgroup
    \expandafter\ifx\csname KOMAoptions\endcsname\relax
      \PassOptionsToPackage{#1}{typearea}%
    \else
      \KOMAoptions{#1}\csname relcalctypearea\endcsname
    \fi
  \fi
}
\DeclareOption{headinclude}{%
  \@Pass@Obsolete@Option@To@Typearea{headinclude}%
}
\DeclareOption{headexclude}{%
  \@Pass@Obsolete@Option@To@Typearea{headinclude=false}%
}
\DeclareOption{footinclude}{%
  \@Pass@Obsolete@Option@To@Typearea{footinclude}%
}
\DeclareOption{footexclude}{%
  \@Pass@Obsolete@Option@To@Typearea{footinclude=false}%
}
%    \end{macrocode}
% We do so, because we want so set |headinclude|, |footinclude| by
% default at old version (see below)!
% \end{option}
% \end{option}
% \end{option}
% \end{option}
%
% We have additional options designed for the additional interface.
% \begin{option}{mpinclude}
%   \changes{v2.8q}{2002/03/28}{New option}
% \begin{option}{mpexclude}
%   \changes{v2.8q}{2002/03/28}{New option}
% There are documents where the head and foot should span not only the
% text but also the marginpar. We have an option to do this at
% initialization. This option corresponds with the option of package
% \texttt{typearea} and the classes.
% \begin{macro}{\if@mincl}
% \begin{macro}{\@mincltrue}
% \begin{macro}{\@minclfalse}
%   \changes{v2.2g}{2008/11/19}{Test fixed}
%    \begin{macrocode}
\@ifundefined{@mincltrue}{\newif\if@mincl}{}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
%    \begin{macrocode}
\DeclareOption{mpinclude}{\@mincltrue}
\DeclareOption{mpexclude}{\@minclfalse}
%    \end{macrocode}
% \end{option}
% \end{option}
%
% Other new options redefine macros, so we have to define them first.
% \begin{macro}{\scr@headabove@linethickness}
%   \changes{v2.0}{2001/04/20}{New}
% \begin{macro}{\scr@headbelow@linethickness}
%   \changes{v2.0}{2001/03/30}{New}
% \begin{macro}{\scr@footabove@linethickness}
%   \changes{v2.0}{2001/04/20}{New}
% \begin{macro}{\scr@footbelow@linethickness}
%   \changes{v2.0}{2001/04/20}{New}
% These macros define the thickness of the line above and below the head
% and the foot.
%    \begin{macrocode}
\newcommand*{\scr@headabove@linethickness}{0pt}
\newcommand*{\scr@headbelow@linethickness}{0pt}
\newcommand*{\scr@footabove@linethickness}{0pt}
\newcommand*{\scr@footbelow@linethickness}{0pt}
%    \end{macrocode}
% \begin{macro}{\scr@headabove@linelength}
%   \changes{v2.0}{2001/04/20}{New}
% \begin{macro}{\scr@headbelow@linelength}
%   \changes{v2.0}{2001/04/20}{New}
% \begin{macro}{\scr@footabove@linelength}
%   \changes{v2.0}{2001/04/20}{New}
% \begin{macro}{\scr@footbelow@linelength}
%   \changes{v2.0}{2001/04/20}{New}
% \begin{macro}{\scrplain@headabove@linelength}
%   \changes{v2.0}{2001/04/20}{New}
% \begin{macro}{\scrplain@headbelow@linelength}
%   \changes{v2.0}{2001/04/20}{New}
% \begin{macro}{\scrplain@footabove@linelength}
%   \changes{v2.0}{2001/04/20}{New}
% \begin{macro}{\scrplain@footbelow@linelength}
%   \changes{v2.0}{2001/04/20}{New}
% Because we want to have the ``line definitions'' at one place, we
% also define the length of the lines here. We have own length at to
% be used at pagestyle \texttt{scrplain}.
%    \begin{macrocode}
\newcommand*{\scr@headabove@linelength}{\@headwidth}
\newcommand*{\scr@headbelow@linelength}{\@headwidth}
\newcommand*{\scr@footabove@linelength}{\@footwidth}
\newcommand*{\scr@footbelow@linelength}{\@footwidth}
\newcommand*{\scrplain@headabove@linelength}{0pt}
\newcommand*{\scrplain@headbelow@linelength}{0pt}
\newcommand*{\scrplain@footabove@linelength}{0pt}
\newcommand*{\scrplain@footbelow@linelength}{0pt}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% 
% \begin{option}{headtopline}
%   \changes{v2.0}{2001/04/20}{New option}
% \begin{option}{headsepline}
%   \changes{v2.0}{2001/04/20}{New option}
% \begin{option}{footsepline}
%   \changes{v2.0}{2001/04/20}{New option}
% \begin{option}{footbotline}
%   \changes{v2.0}{2001/04/20}{New option}
% \begin{option}{plainheadtopline}
%   \changes{v2.0}{2001/04/20}{New option}
% \begin{option}{plainheadsepline}
%   \changes{v2.0}{2001/04/20}{New option}
% \begin{option}{plainfootsepline}
%   \changes{v2.0}{2001/04/20}{New option}
% \begin{option}{plainfootbotline}
%   \changes{v2.0}{2001/04/20}{New option}
% The thickness can be set by four simple options:
%    \begin{macrocode}
\DeclareOption{headtopline}{%
  \renewcommand*{\scr@headabove@linethickness}{.4pt}
  \PassOptionsToPackage{headinclude}{typearea}}
\DeclareOption{headsepline}{%
  \renewcommand*{\scr@headbelow@linethickness}{.4pt}
  \PassOptionsToPackage{headinclude}{typearea}}
\DeclareOption{footsepline}{%
  \renewcommand*{\scr@footabove@linethickness}{.4pt}
  \PassOptionsToPackage{footinclude}{typearea}}
\DeclareOption{footbotline}{
  \renewcommand*{\scr@footbelow@linethickness}{.4pt}
  \PassOptionsToPackage{footinclude}{typearea}}
\DeclareOption{plainheadtopline}{%
  \renewcommand*{\scrplain@headabove@linelength}{\scr@headabove@linelength}
  \PassOptionsToPackage{headinclude}{typearea}}
\DeclareOption{plainheadsepline}{%
  \renewcommand*{\scrplain@headbelow@linelength}{\scr@headbelow@linelength}
  \PassOptionsToPackage{headinclude}{typearea}}
\DeclareOption{plainfootsepline}{%
  \renewcommand*{\scrplain@footabove@linelength}{\scr@footabove@linelength}
  \PassOptionsToPackage{footinclude}{typearea}}
\DeclareOption{plainfootbotline}{
  \renewcommand*{\scrplain@footbelow@linelength}{\scr@footbelow@linelength}
  \PassOptionsToPackage{footinclude}{typearea}}
%    \end{macrocode}
% \end{option}
% \end{option}
% \end{option}
% \end{option}
% \end{option}
% \end{option}
% \end{option}
% \end{option}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\hfline@adjust}
%   \changes{v2.0f}{2001/06/23}{New}
% \begin{option}{ilines}
%   \changes{v2.0f}{2001/06/23}{New}
% \begin{option}{clines}
%   \changes{v2.0f}{2001/06/23}{New}
% \begin{option}{olines}
%   \changes{v2.0f}{2001/06/23}{New}
% At Version 2 lines may be inner adjusted (0), centered (1) or outer
% adjusted (2):
%    \begin{macrocode}
\newcommand*{\hfline@adjust}{1}
\DeclareOption{ilines}{\renewcommand*{\hfline@adjust}{0}}
\DeclareOption{clines}{\renewcommand*{\hfline@adjust}{1}}
\DeclareOption{olines}{\renewcommand*{\hfline@adjust}{2}}
%    \end{macrocode}
% \end{option}
% \end{option}
% \end{option}
% \end{macro}
%
% \begin{option}{automark}
%   \changes{v2.0b}{2001/05/31}{use \cs{AtEndOfPackage} to run not yet
%     defined macro}
% \begin{option}{manualmark}
%   \changes{v2.0b}{2001/05/31}{use \cs{AtEndOfPackage} to run not yet
%     defined macro}
%   \changes{v2.0i}{2001/08/17}{don't ignore oneside any longer}
% At version 2 we want to distinguish between running headline and
% static headline not only using different pagestyles. We do this with
% options and commands. But here only the options are defined.
%    \begin{macrocode}
\DeclareOption{automark}{%
  \AtEndOfPackage{\if@twoside%
      \if@chapter\automark[section]{chapter}%
      \else\automark[subsection]{section}\fi%
    \else%
      \if@chapter\automark{chapter}\else\automark{section}\fi%
    \fi}}
\DeclareOption{manualmark}{\AtEndOfPackage{\manualmark}}
%    \end{macrocode}
% \end{option}
% \end{option}
%
% \begin{option}{autoonesize}
%   \changes{v2.0i}{2001/08/17}{New}
% \begin{macro}{\if@autooneside}
%   \changes{v2.0i}{2001/08/17}{New}
% If the optional argument of \cs{automark} should be irgnored at
% onside mode, use this option:
%    \begin{macrocode}
\newif\if@autooneside\@autoonesidefalse
\DeclareOption{autooneside}{\@autoonesidetrue}
%    \end{macrocode}
% \end{macro}
% \end{option}
%
% \begin{option}{markuppercase}
%   \changes{v2.0c}{2001/06/07}{New}
% \begin{option}{markusedcase}
%   \changes{v2.0c}{2001/06/07}{New}
% For use of running headlines there are also options to say ``class
% uses upper case at the automatic marks'' or ``class use same case at
% the automatic marks like used writing the heading''.  
%    \begin{macrocode}
\DeclareOption{markuppercase}{\let\MakeMarkcase\MakeUppercase}
\DeclareOption{markusedcase}{\let\MakeMarkcase\@empty}
%    \end{macrocode}
% \end{option}
% \end{option}
%
% \begin{macro}{\scr@nouppercase}
%   \changes{v2.0j}{2001/08/18}{New}
% \begin{option}{nouppercase}
%   \changes{v2.0j}{2001/08/18}{New}
% Sometimes scrpage may be used with a class, which uses
% \cs{uppercase} or \cs{MakeUppercase} at \cs{markboth} or
% \cs{markright}. But the author does not want upper case at the
% headlines. So we define an option, that simply deaktivates
% \cs{uppercase} and \cs{MakeUppercase} at all heads and foots,
% defined by scrpage2.
%    \begin{macrocode}
\newcommand*{\scr@nouppercase}{}
\DeclareOption{nouppercase}{\renewcommand*{\scr@nouppercase}{%
    \let\uppercase\relax\let\MakeUppercase\relax
    \expandafter\let\csname MakeUppercase \endcsname\relax}
  \ifx\MakeMarkcase\MakeUppercase
    \PackageWarning{scrpage2}{%
      Option 'markuppercase' will be ignored.\MessageBreak%
      You shouldn't use option 'markuppercase' together\MessageBreak%
      with option 'nouppercase'}
    \let\MakeMarkcase\@empty
  \fi}
%    \end{macrocode}
% \end{option}
% \end{macro}
%
% \begin{option}{komastyle}
% \begin{option}{standardstyle}
% At version 2 there is an predefined pagestyle ``scrheadings''. With
% the two options you may decide, wether it has to behave like
% ``headings'' at the standard classes or the KOMA-Script classes.
% The macro saves the name of the style.
%    \begin{macrocode}
\DeclareOption{komastyle}{\def\scrheadings@style{koma}
  \@ifundefined{MakeMarkcase}{\let\MakeMarkcase\relax}{}}
\DeclareOption{standardstyle}{\def\scrheadings@style{standard}
  \@ifundefined{MakeMarkcase}{\let\MakeMarkcase\MakeUppercase}{}}
%    \end{macrocode}
% \end{option}
% \end{option}
%
%
% We don't need default options.
%    \begin{macrocode}
\ExecuteOptions{}
%    \end{macrocode}
% But you may set other Options:
%    \begin{macrocode}
\ProcessOptions\relax
%    \end{macrocode}
%
%
% \subsection{Some Initialisation}
%
% For easier handling of the differences between article-, report- and
% book-classes we define some more switches.
%
% \begin{macro}{\if@chapter}
%   \changes{v2.1b}{2003/05/31}{more save test}
% First distinguish between article and others.
%    \begin{macrocode}
\newif\if@chapter
\begingroup\expandafter\expandafter\expandafter\endgroup
\expandafter\ifx\csname chapter\endcsname\relax 
  \@chapterfalse
\else
  \@chaptertrue
\fi
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\if@mainmatter}
%   \changes{v1.2}{1995/07/08}{Definition changed}
%   \changes{v2.1b}{2003/05/31}{more save test}
%   \changes{v2.2d}{2007/03/13}{additional \cs{if@mainmatter} test}
%   \changes{v2.2g}{2008/11/19}{usage of \cs{if@mainmatter} at message
%     removed}
% Next distinguish between matter- and nomatter-classes.
%    \begin{macrocode}
\def\@tempa{\newif\if@mainmatter\@mainmattertrue}
\begingroup\expandafter\expandafter\expandafter\endgroup
\expandafter\ifx\csname mainmatter\endcsname\relax
\else
  \@ifundefined{@mainmattertrue}{%
    \PackageWarningNoLine{scrpage2}{%
      \string\mainmatter\space defined without
      \expandafter\string\csname if@mainmatter\endcsname!\MessageBreak
      This switch is obligatory for scrpage2 to omit\MessageBreak
      running head chapter numbers in front and\MessageBreak
      back matter and will be defined now%
    }%
  }{%
    \let\@tempa\relax
  }%
\fi
\@tempa
%    \end{macrocode}
% \end{macro}
%
%
% \subsection{Predefinitions}
% There are some commands, you can use at pagestyle-definition.
%
% \begin{macro}{\headmark}
% This macro is |\rightmark| or |\leftmark|. But outside
% pagestyle-definition it's nothing.
%    \begin{macrocode}
\let\headmark\relax
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\pagemark}
% This macro is the number of the page at the pagenumberfont:
%    \begin{macrocode}
\DeclareRobustCommand\pagemark{{\pnumfont\thepage}}
%    \end{macrocode}
% \end{macro}
%
%
% \subsection{Expert-Pagestyle-Definition-Interface}
% The pagestyle-definition-interface for experts is not as easy as the
% simple interface we'll define later. But it's more flexible. We'll
% later use it to define the pagestyle-definition-interface for users.
%
% \begin{macro}{\if@automark}
%   \changes{v2.1}{2002/10/30}{New switch}
% \begin{macro}{\@automarktrue}
% \begin{macro}{\@automarkfalse}
% We need this switch to decide to switch on or off \cs{@mkboth} at the
% pagestyles.
%    \begin{macrocode}
\newif\if@automark\@automarkfalse
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\defpagestyle}
% First we define the simple definition-interface. There's no test, if
% the pagestyle's defined twice.
%
% First there has to be the definition of head and foot.
%    \begin{macrocode}
\def\defpagestyle{%
%    \end{macrocode}
% We have to decide, whether it is a my-version or not:
%    \begin{macrocode}
  \@ifstar
  {\@defpagestyle[-]}%
  {\@defpagestyle[+]}}
%    \end{macrocode}
% \begin{macro}{\@defpagestyle}
% Now the we can define the head and the foot.
%   \changes{v1.0b}{1995/05/25}{Dot deleted after number at
%     chapter- and sectionmark}
%   \changes{v1.0b}{1995/05/25}{Use CJK at \cs{chaptermark},
%     \cs{sectionmark} and \cs{subsectionmark}}
%   \changes{v1.3e}{2008/02/29}{usage of \cs{if@mainmatter} fixed}
%   \changes{v2.0}{2001/04/20}{Version 2 uses \cs{automark} and
%     \cs{manualmark}, so star and non-star version are same} 
%   \changes{v2.1a}{2002/10/30}{Use \cs{if@automark}}
%   \changes{v2.2d}{2007/06/14}{Support of article-classes with
%     \cs{if@mainmatter}}
%   \changes{v2.5}{2010/04/22}{moved \cs{if@twoside} inside of definition}
% Before version 2.5 we have distinguished one- and two-side definitions while
% loading the package and have had all the definitions of \cs{@mkboth},
% \cs{chaptermark}, \cs{sectionmark}, and \cs{subsectionmark} at the
% definition of the page style.
% Since version~2.5 the difference of one- and two-side is made at the
% definition of the heads and foots themself and \cs{chaptermark},
% \cs{sectionmark}, and \cs{subsectionmark} are defined by \cs{automark} and
% \cs{manualmark}. So the code is much easier.
%    \begin{macrocode}
\def\@defpagestyle[#1]#2#3#4{%
  \expandafter\def\csname ps@#2\endcsname{%
    \if@automark\let\@mkboth\markboth\else\let\@mkboth\@gobbletwo\fi
    \def@head#3
    \def@foot#4
  }%
}
%    \end{macrocode}
%
% \begin{macro}{\def@head}
%   \changes{v2.5}{2010/04/22}{new (internal)}
%   \changes{v3.20}{2016/04/12}{\cs{@ifnextchar} replaced by
%     \cs{kernel@ifnextchar}}^^A
% \begin{macro}{\def@@head}
%   \changes{v2.0}{2001/04/20}{Thickness and length of the lines are
%     optional}
%   \changes{v2.0j}{2001/08/18}{Use of \cs{scr@nouppercase}}
%   \changes{v2.5}{2010/04/22}{new (internal)}
%   \changes{v3.20}{2016/04/12}{\cs{@ifnextchar} replaced by
%     \cs{kernel@ifnextchar}}^^A
% This was real simple, but we already have to do the real definition
% of the heads and foots. First the head:
%    \begin{macrocode}
\def\def@head{%
  \kernel@ifnextchar(%)
  {\def@@head}%
  {\def@@head(\scr@headabove@linelength,%
              \scr@headabove@linethickness)}}
\def\def@@head(#1,#2)#3#4#5{%
  \kernel@ifnextchar(%)
  {\def@@@head({#1},{#2}){#3}{#4}{#5}}%
  {\def@@@head({#1},{#2}){#3}{#4}{#5}%
              (\scr@headbelow@linelength,%
               \scr@headbelow@linethickness)}}
\def\def@@@head(#1,#2)#3#4#5(#6,#7){%
  \def\@evenhead{%
    \if@twoside
      \let\headmark\leftmark%
      \hss\hskip\@evenheadshift\vbox{\hsize=\@headwidth\relax%
        \hf@rule{#1}{#2}{\@headwidth}{headabove}%
        \vskip#2
        \vskip\baselineskip
        \hb@xt@\@headwidth{{%
            \scr@nouppercase
            \headfont\strut #3}}%
        \hf@rule{#6}{#7}{\@headwidth}{headbelow}%
      }\hskip\@oddheadshift\hss
    \fi
  }%
  \def\@oddhead{\let\headmark\rightmark
    \hss\hskip\@oddheadshift\vbox{\hsize=\@headwidth\relax
      \hf@rule{#1}{#2}{\@headwidth}{headabove}%
      \vskip#2%
      \vskip\baselineskip
      \hb@xt@\@headwidth{{%
          \scr@nouppercase
          \headfont\strut \if@twoside #4\else #5\fi}}%
      \hf@rule{#6}{#7}{\@headwidth}{headbelow}%
  }\hskip\@evenheadshift\hss}%
}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \begin{macro}{\def@foot}
%   \changes{v2.0}{2001/04/20}{Thickness and length of the lines are
%     optional}  
%   \changes{v1.3}{2001/03/30}{Use of \cmd\@footwidth instead of
%     \cs{textwidth}}
%   \changes{v2.5}{2010/04/22}{new (internal)}
%   \changes{v3.20}{2016/04/12}{\cs{@ifnextchar} replaced by
%     \cs{kernel@ifnextchar}}^^A
% \begin{macro}{\def@@foot}
%   \changes{v2.5}{2010/04/22}{new (internal)}
%   \changes{v3.20}{2016/04/12}{\cs{@ifnextchar} replaced by
%     \cs{kernel@ifnextchar}}^^A
% \begin{macro}{\def@@@foot}
%   \changes{v2.0j}{2001/08/18}{Use of \cs{scr@nouppercase}}
%   \changes{v2.2f}{2008/02/14}{Use of \cs{footfont}}
%   \changes{v2.5}{2010/04/22}{new (internal)}
% And last twosided and onesided foot:
%    \begin{macrocode}
\def\def@foot{%
  \kernel@ifnextchar(%)
  {\def@@foot}
  {\def@@foot(\scr@footabove@linelength,%
                     \scr@footabove@linethickness)}}
\def\def@@foot(#1,#2)#3#4#5{%
  \kernel@ifnextchar(%)
  {\def@@@foot({#1},{#2}){#3}{#4}{#5}}%
  {\def@@@foot({#1},{#2}){#3}{#4}{#5}%
                     (\scr@footbelow@linelength,%
                      \scr@footbelow@linethickness)}}
\def\def@@@foot(#1,#2)#3#4#5(#6,#7){%
  \def\@evenfoot{%
    \if@twoside
      \let\headmark\leftmark
      \hss\hskip\@evenfootshift\vbox{\hsize=\@footwidth\relax
        \topfoot@rule{#1}{#2}\hb@xt@\@footwidth{{%
            \scr@nouppercase
            \headfont\footfont\strut #3}}%
        \botfoot@rule{#6}{#7}}\hskip\@oddfootshift\hss
    \fi
  }%
  \def\@oddfoot{\let\headmark\rightmark
    \hss\hskip\@oddfootshift\vbox{\hsize=\@footwidth\relax
      \topfoot@rule{#1}{#2}\hb@xt@\@footwidth{{%
          \scr@nouppercase
          \headfont\footfont\strut \if@twoside #4\else #5\fi}}%
      \botfoot@rule{#6}{#7}}\hskip\@evenfootshift\hss}%
}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
% We now define the rules used at head and foot.
% \begin{macro}{\topfoot@rule}
%    \begin{macrocode}
\newcommand\topfoot@rule[2]{%
  \@tempdima\baselineskip\advance\@tempdima by-.7\normalbaselineskip
  \advance\@tempdima by -#2
  \vskip\@tempdima\hf@rule{#1}{#2}{\@footwidth}{footabove}%
  \vskip-\@tempdima}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\botfoot@rule}
%    \begin{macrocode}
\newcommand\botfoot@rule[2]{%
  \@tempdima-\baselineskip\advance\@tempdima by .3\normalbaselineskip
  \advance\@tempdima by #2
  \vskip\@tempdima\hf@rule{#1}{#2}{\@footwidth}{footbelow}%
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\hf@rule}
%   \changes{v1.3}{2001/03/30}{New, third parameter ``boxwidth''}
%   \changes{v2.0f}{2001/06/23}{Rule can be adjusted at inner margine,
%     centered or adjusted at outer margine}
%   \changes{v2.2}{2004/07/05}{Last parameter of the rule tells, if it is a
%     headabove, headbelow, footabove or footbelow rule}
%   \changes{v2.2}{2005/07/05}{Precommands before the rules are allowed}
%   \changes{v2.2}{2005/07/05}{Macro is not longer long}
%   \changes{v2.2b}{2005/08/31}{No even alignment at oneside}
%    \begin{macrocode}
\newcommand*{\hf@rule}[4]{%
  \setlength{\@tempdimb}{#1}
  \begingroup
    \csname scr@pre@#4@line\endcsname
    \if@twoside
      \ifodd\c@page
        \edef\@tempa{\hfline@adjust}%
      \else
        \@tempcnta=2\advance\@tempcnta -\hfline@adjust
        \edef\@tempa{\the\@tempcnta}%
      \fi
    \else
      \edef\@tempa{\hfline@adjust}%
    \fi
    \ifnum\@tempa=1
      \setlength{\@tempdimb}{.5\@tempdimb}%
    \fi
    \hb@xt@#3{%
      \ifnum\@tempa>0
        \hfill%
        \llap{\vrule\@depth#2\@height\z@\@width\@tempdimb}%
      \fi
      \ifnum\@tempa<2
        \rlap{\vrule\@depth#2\@height\z@\@width\@tempdimb}%
        \hfill%
      \fi
    }%
  \endgroup
}
%    \end{macrocode}
% \begin{macro}{\scr@pre@headabove@line}
%   \changes{v2.2}{2004/07/05}{New internal}
% \begin{macro}{\scr@fnt@headtopline}
%   \changes{v2.2}{2004/07/05}{New KOMA-Script font command}
% \begin{macro}{\scr@pre@headbelow@line}
%   \changes{v2.2}{2004/07/05}{New internal}
% \begin{macro}{\scr@fnt@headsepline}
%   \changes{v2.2}{2004/07/05}{New KOMA-Script font command}
% \begin{macro}{\scr@pre@footabove@line}
%   \changes{v2.2}{2004/07/05}{New internal}
% \begin{macro}{\scr@fnt@footsepline}
%   \changes{v2.2}{2004/07/05}{New KOMA-Script font command}
% \begin{macro}{\scr@pre@footbelow@line}
%   \changes{v2.2}{2004/07/05}{New internal}
% \begin{macro}{\scr@fnt@footbottomrule}
%   \changes{v2.2}{2004/07/05}{New KOMA-Script font command}
% \begin{macro}{\scr@fnt@instead@footbotline}
%   \changes{v2.2}{2004/07/05}{New KOMA-Script font command}
%    \begin{macrocode}
\newcommand*{\scr@pre@headabove@line}{}
\newcommand*{\scr@fnt@headtopline}{\scr@pre@headabove@line}
\newcommand*{\scr@pre@headbelow@line}{}
\newcommand*{\scr@fnt@headsepline}{\scr@pre@headbelow@line}
\newcommand*{\scr@pre@footabove@line}{}
\newcommand*{\scr@fnt@footsepline}{\scr@pre@footabove@line}
\newcommand*{\scr@pre@footbelow@line}{}
\newcommand*{\scr@fnt@footbottomline}{\scr@pre@footbelow@line}
\newcommand*{\scr@fnt@instead@footbotline}{footbottomline}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
% Using these definitions, we can define the testing macros.
%
% \begin{macro}{\newpagestyle}
% First the simple star/starless-selection:
%    \begin{macrocode}
\def\newpagestyle{%
%    \end{macrocode}
% We have to decide, whether it is a my-version or not:
%    \begin{macrocode}
  \@ifstar
  {\@newpagestyle[-]}%
  {\@newpagestyle[+]}}
%    \end{macrocode}
% \begin{macro}{\@newpagestyle}
% There we have to distinguish, whether the pagestyle is already
% defined or not.
%    \begin{macrocode}
\def\@newpagestyle[#1]#2#3#4{%
  \expandafter\ifx\csname ps@#2\endcsname\relax
%    \end{macrocode}
% Then we can use the already defined |\@defpagestyle|.
%    \begin{macrocode}
    \@defpagestyle[#1]{#2}{#3}{#4}%
  \else
    \PackageError
      {scrpage2}%
      {Your command was ignored}%
      {There is already a pagestyle named ``#1''.\MessageBreak%
       Use \protect\defpagestyle\space, \protect\renewpagestyle or
       \protect\providepagestyle.}%
  \fi
}
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\renewpagestyle}
% First the simple star/starless-selection:
%    \begin{macrocode}
\def\renewpagestyle{%
%    \end{macrocode}
% We have to decide, whether it is a my-version or not:
%    \begin{macrocode}
  \@ifstar
  {\@renewpagestyle[-]}%
  {\@renewpagestyle[+]}}
%    \end{macrocode}
% \begin{macro}{\@renewpagestyle}
%   \changes{v1.2a}{1996/12/07}{Avoid to define pagestyle as \cs{relax}
%     if it wasn't defined (Thanks to Bernd).}
% There we have to distinguish, whether the pagestyle is already
% defined or not.
%    \begin{macrocode}
\def\@renewpagestyle[#1]#2#3#4{%
  \begingroup\expandafter\expandafter\expandafter\endgroup
  \expandafter\ifx\csname ps@#2\endcsname\relax
    \PackageError
      {scrpage2}%
      {Your command was ignored}%
      {There is no pagestyle named ``#1''.\MessageBreak%
       Use \protect\defpagestyle, \protect\newpagestyle or
       \protect\providepagestyle.}%
  \else
%    \end{macrocode}
% Then we can use the already defined |\@defpagestyle|.
%    \begin{macrocode}
    \@defpagestyle[#1]{#2}{#3}{#4}%
  \fi
}
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\providepagestyle}
% First the simple star/starless-selection:
%    \begin{macrocode}
\def\providepagestyle{%
%    \end{macrocode}
% We have to decide, whether it is a my-version or not:
%    \begin{macrocode}
  \@ifstar
  {\@providepagestyle[-]}%
  {\@providepagestyle[+]}}
%    \end{macrocode}
% \begin{macro}{\@providepagestyle}
% There we have to distinguish, whether the pagestyle is already
% defined or not.
%    \begin{macrocode}
\def\@providepagestyle[#1]#2#3#4{%
  \expandafter\ifx\csname ps@#2\endcsname\relax
%    \end{macrocode}
% Then we can use the already defined |\@defpagestyle|.
%    \begin{macrocode}
    \@defpagestyle[#1]{#2}{#3}{#4}%
  \else
    \PackageInfo
      {scrpage2}%
      {\protect\providepagestyle\protect{#1\protect} ignored.}%
  \fi
}
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
%
% \subsection{User-Pagestyle-Definition-Interface}
% The pagestyle-definition-interface for users is much easier than the
% expert-version. Using the expert-macros, the definition is easy, too.
%
% \begin{macro}{\deftripstyle}
%    \begin{macrocode}
%    \end{macrocode}
% At version 1 we define the selection of star- or starless-version first:
%    \begin{macrocode}
\def\deftripstyle{%
  \@ifstar
  {\@deftripstyle[-]}%
  {\@deftripstyle[+]}}
%    \end{macrocode}
% \end{macro}
% Next we check, if there is an optional argument:
% \begin{macro}{\@deftripstyle}
%   \changes{v3.20}{2016/04/12}{\cs{@ifnextchar} replaced by
%     \cs{kernel@ifnextchar}}^^A
%    \begin{macrocode}
\def\@deftripstyle[#1]#2{%
  \kernel@ifnextchar[%]
  {\@@deftripstyle[#1]{#2}}%
  {\@@deftripstyle[#1]{#2}[\z@]}}
%    \end{macrocode}
% \end{macro}
% or perhaps two optional arguments:
% \begin{macro}{\@@deftripstyle}
%    \begin{macrocode}
\def\@@deftripstyle[#1]#2[#3]{%
%    \end{macrocode}
%   \changes{v3.20}{2016/04/12}{\cs{@ifnextchar} replaced by
%     \cs{kernel@ifnextchar}}^^A
% Ok, now we have the problem, that there can be only 9 arguments. So we
% have to distinguish the star-versions by a macro:
%    \begin{macrocode}
  \def\@tempa{#1}%
  \kernel@ifnextchar[%]
  {\@@@deftripstyle#2[#3]}%
  {\@@@deftripstyle#2[\z@][#3]}}
%    \end{macrocode}
% \end{macro}
% Now the main-definition:
% \begin{macro}{\@@@deftripstyle}
%    \begin{macrocode}
\def\@@@deftripstyle#1[#2][#3]#4#5#6#7#8#9{%
  \def\@tempb{+}%
  \ifx\@tempa\@tempb
    \defpagestyle{#1}%
      {(\@headwidth,#2)%
       {\rlap{#6}\hfill{#5}\hfill\llap{#4}}%
       {\rlap{#4}\hfill{#5}\hfill\llap{#6}}%
       {\rlap{#4}\hfill{#5}\hfill\llap{#6}}%
       (\@headwidth,#3)}%
      {(\@footwidth,#3)%
       {\rlap{#9}\hfill{#8}\hfill\llap{#7}}%
       {\rlap{#7}\hfill{#8}\hfill\llap{#9}}%
       {\rlap{#7}\hfill{#8}\hfill\llap{#9}}%
       (\@footwidth,#2)}%
  \else
    \defpagestyle*{#1}%
      {(\@headwidth,#2)%
       {\rlap{#6}\hfill{#5}\hfill\llap{#4}}%
       {\rlap{#4}\hfill{#5}\hfill\llap{#6}}%
       {\rlap{#4}\hfill{#5}\hfill\llap{#6}}%
       (\@headwidth,#3)}%
      {(\@footwidth,#3)%
       {\rlap{#9}\hfill{#8}\hfill\llap{#7}}%
       {\rlap{#7}\hfill{#8}\hfill\llap{#9}}%
       {\rlap{#7}\hfill{#8}\hfill\llap{#9}}%
       (\@footwidth,#2)}%
  \fi
}
%    \end{macrocode}
% \end{macro}
%
%
% \subsection{Automark or not}
% This is new since version 2.
% \begin{macro}{\automark}
%   \changes{v2.0}{2001/04/20}{New}
%   \changes{v2.0c}{2001/06/07}{Use of \cs{MakeMarkcase}}
%   \changes{v2.0g}{2001/06/25}{Use of \cs{manualmark}}
%   \changes{v2.0i}{2001/08/17}{Warning, if arguments are mixed up}
%   \changes{v2.0i}{2001/08/17}{\cs{markboth} behavior fixed}
%   \changes{v2.0i}{2001/08/17}{Use of \cs{if@autooneside}}
%   \changes{v2.1a}{2002/10/30}{Switch on \cs{if@automark}}
% This macro activates automatic mark. Is has two arguments. The
% first, optional argument is the sectioning level name of the mark at
% left pages, the second, not  optional argument is the same at right
% pages. At oneside mode all pages are right.
% \begin{macro}{\@iflevelok}
%   \changes{v2.0i}{2001/08/17}{New}
% \begin{macro}{\markleft}
%   \changes{v2.0i}{2001/08/17}{New}
% \begin{macro}{\@markleft}
%   \changes{v2.0i}{2001/08/17}{New}
% To define \cs{automark} we also need these three makros. The first
% one decides, if level of second parameter is less than level of
% first parameter and does then third or fourth parameter.
% \cs{markleft} and \cs{@markleft} are similar to \cs{markright} and
% \cs{@markright} at \LaTeX{} kernel.
%    \begin{macrocode}
\newcommand*{\@iflevelok}[4]{%
  \begingroup
    \edef\@tempa{#1}\ifx\@tempa\@empty\def\@tempa{\endgroup #3}\else
      \def\@tempa{\csname #1level\endcsname}%
      \def\@tempb{\csname #2level\endcsname}%
      \ifnum \@tempa>\@tempb
        \def\@tempa{\endgroup#3}%
      \else
        \def\@tempa{\endgroup#4}%
    \fi\fi\@tempa}
\providecommand{\markleft}[1]{%
  \begingroup
    \let\label\relax \let\index\relax \let\glossary\relax
    \expandafter\@markleft\@themark {#1}%
    \@temptokena \expandafter{\@themark}%
    \mark{\the\@temptokena}%
  \endgroup
  \if@nobreak\ifvmode\nobreak\fi\fi}
\providecommand{\@markleft}[3]{\@temptokena {#2}%
  \unrestored@protected@xdef\@themark{{#3}{\the\@temptokena}}}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
%   \changes{v2.2a}{2004/09/05}{all changes of helper macros and switches are
%     local to fix e.g.\ twocolumn problem with \cs{part}}
%    \begin{macrocode}
\newcommand*{\automark}[2][\@empty]{%
  \manualmark
  \@automarktrue
  \begingroup
  \edef\@tempa{#2}\ifx\@tempa\@empty
    \endgroup
    \PackageWarning{scrpage2}%
      {\string\automark\space with empty obligatory argument}%
  \else
    \endgroup
    \expandafter\def\csname #2mark\endcsname##1{%
      \begingroup
        \def\@tempa{\csname #2level\endcsname}%
        \@tempswafalse
        \ifnum \c@secnumdepth <\@tempa\else\if@mainmatter
            \@tempswatrue
        \fi\fi
        \edef\@tempa{#1}%
        \if@twoside\edef\@tempb{#2}\else\let\@tempb\@tempa\fi
        \ifx\@tempa\@tempb
          \if@tempswa
            \@mkboth{\MakeMarkcase{\csname #2markformat\endcsname ##1}}%
                    {\MakeMarkcase{\csname #2markformat\endcsname ##1}}%
          \else%
            \@mkboth{\MakeMarkcase{##1}}{\MakeMarkcase{##1}}%
          \fi
        \else
          \if@tempswa
            \@iflevelok{#1}{#2}{%
              \@mkboth{\MakeMarkcase{\csname #2markformat\endcsname
                  ##1}}{}}{%
              \ifx\@mkboth\markboth\markleft{\MakeMarkcase{\csname
                  #2markformat\endcsname ##1}}%
              \fi}
          \else
            \@iflevelok{#1}{#2}{%
              \@mkboth{\MakeMarkcase{##1}}{}}{%
              \ifx\@mkboth\markboth\markleft{\MakeMarkcase{##1}}\fi}%
          \fi
        \fi
      \endgroup
    }
  \fi
  \begingroup
  \edef\@tempa{#1}\edef\@tempb{#2}%
  \if@autooneside\if@twoside\else\let\@tempa\@empty\fi\fi
  \ifx\@tempa\@empty
    \endgroup
  \else
    \ifx\@tempa\@tempb
      \endgroup
    \else
      \endgroup
      \expandafter\def\csname #1mark\endcsname##1{%
        \begingroup
          \def\@tempa{\csname #1level\endcsname}%
          \@tempswafalse
          \ifnum \c@secnumdepth <\@tempa\else\if@mainmatter
              \@tempswatrue
          \fi\fi
          \if@tempswa
            \@iflevelok{#1}{#2}{%
              \ifx\@mkboth\markboth
                \markright{\MakeMarkcase{\csname #1markformat\endcsname
                    ##1}}%
              \fi}{%
              \@mkboth{}{\MakeMarkcase{\csname #1markformat\endcsname
                  ##1}}}%
          \else
            \@iflevelok{#1}{#2}{%
              \ifx\@mkboth\markboth
                \markright{\MakeMarkcase{##1}}%
              \fi}{%
              \@mkboth{}{\MakeMarkcase{##1}}}%
          \fi
        \endgroup
      }
  \fi\fi%
  \let\@mkboth\markboth
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\manualmark}
%   \changes{v2.0}{2001/04/20}{New}
%   \changes{v2.0g}{2001/06/25}{also deactivating \cs{...mark}}
%   \changes{v2.1a}{2002/10/30}{Switch off \cs{if@automark}}
% This macro switchs to the manual set of marks (using \cs{markboth}
% and \cs{markright}. This is very simple, we only have to deaktivate
% the mark macros.
%    \begin{macrocode} 
\newcommand*{\manualmark}{%
  \if@chapter\let\chaptermark\@gobble\fi
  \let\sectionmark\@gobble
  \let\subsectionmark\@gobble
  \let\subsubsectionmark\@gobble
  \let\paragraphmark\@gobble
  \let\subparagraphmark\@gobble
  \let\@mkboth\@gobbletwo
  \@automarkfalse
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\partlevel}
%   \changes{v2.2}{2004/07/05}{New}
%   \changes{v2.4}{2009/11/11}{part level is always -1}
% \begin{macro}{\chapterlevel}
%   \changes{v2.0}{2001/04/20}{New}
% \begin{macro}{\sectionlevel}
%   \changes{v2.0}{2001/04/20}{New}
% \begin{macro}{\subsectionlevel}
%   \changes{v2.0}{2001/04/20}{New}
% \begin{macro}{\subsubsectionlevel}
%   \changes{v2.0}{2001/04/20}{New}
% \begin{macro}{\paragraphlevel}
%   \changes{v2.0}{2001/04/20}{New}
% \begin{macro}{\subparagraphlevel}
%   \changes{v2.0}{2001/04/20}{New}
% At \cs{automark} we use some macros to get the numeric level of a
% sectioning name. We simply define these:
%    \begin{macrocode}
\newcommand*{\partlevel}{-1}
\newcommand*{\chapterlevel}{0}
\newcommand*{\sectionlevel}{1}
\newcommand*{\subsectionlevel}{2}
\newcommand*{\subsubsectionlevel}{3}
\newcommand*{\paragraphlevel}{4}
\newcommand*{\subparagraphlevel}{5}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\MakeMarkcase}
%   \changes{v2.0m}{2002/02/05}{\texttt{scrlttr2} is a known class}
% At \cs{automark} we use a new macro to enable usability of
% \cs{MakeUppercase} at the head-marks. We set this macro to
% \cs{MakeUppercase} if one of the standard-classes was loaded:
%    \begin{macrocode}
\@ifundefined{MakeMarkcase}{%
  \@ifclassloaded{scrbook}{\let\MakeMarkcase\relax}{%
    \@ifclassloaded{scrreprt}{\let\MakeMarkcase\relax}{%
      \@ifclassloaded{scrartcl}{\let\MakeMarkcase\relax}{%
        \@ifclassloaded{scrlttr2}{\let\MakeMarkcase\relax}{%
          \@ifclassloaded{book}{}{%
            \@ifclassloaded{report}{}{%
              \@ifclassloaded{article}{}{%
                \PackageWarningNoLine{scrpage2}{%
                  use of scrpage2 with unknown class.\MessageBreak
                  Please mail to markus.kohm@gmx.de, if
                  headmarks\MessageBreak
                  are lower case without use of scrpage2}}}}%
          \let\MakeMarkcase\MakeUppercase}}}}}{}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\scrheadings@style}
%   \changes{v2.0g}{2001/06/25}{New}
%   \changes{v2.0m}{2002/02/05}{Take care of class \texttt{scrlttr2}}
% This macro defines, which style for scrheadings should be used. If
% it is not defined, we have to define it in a propper way.
%    \begin{macrocode}
\@ifundefined{scrheadings@style}{%
  \@ifclassloaded{scrbook}{\def\scrheadings@style{koma}}{%
    \@ifclassloaded{scrreprt}{\def\scrheadings@style{koma}}{%
      \@ifclassloaded{scrartcl}{\def\scrheadings@style{koma}}{%
        \@ifclassloaded{scrlttr2}{\def\scrheadings@style{koma}}{%
          \def\scrheadings@style{standard}}}}}}{}
%    \end{macrocode}
% \end{macro}
%
%
% \subsection{Width of head and foot}
% \begin{macro}{\setheadwidth}
%   \changes{v1.3}{2001/03/30}{New}
% \begin{macro}{\setfootwidth}
%   \changes{v1.3}{2001/03/30}{New}
% \begin{macro}{\set@hf@width}
%   \changes{v1.3}{2001/03/30}{New}
%   \changes{v1.3a}{2001/05/31}{symbolic values ``paper'', ``text'',
%     ``textwidthmarginpar''} 
%   \changes{v2.0b}{2001/05/31}{symbolic values ``paper'', ``text'',
%     ``textwidthmarginpar''} 
%   \changes{v2.0c}{2001/06/07}{error fix at warning}
% \begin{macro}{\settowidthof}
%   \changes{v2.0e}{2001/06/22}{New}
% \begin{macro}{\deftowidthof}
%   \changes{v2.0e}{2001/06/22}{New}
%   \changes{v2.0f}{2001/06/23}{new symbolic values ``autohead'' and
%     ``autofoot''}
%   \changes{v2.0i}{2001/08/17}{new symbolic value ``page''}
%   \changes{v2.0k}{2001/09/28}{\cs{pagewidth} korrigiert}
%   \changes{v2.1b}{2003/05/31}{more save existance test}
%   \changes{v2.2}{2004/07/05}{value ``foot'' fixed}
% Until version 1.3, head and foot of a page had same width like the
% text block. Since version 1.3 this was changed. Now the head and
% foot have their own width and an optional shift relative to the text
% part of the page. This shift can be positive or negative. We set
% the width and shift with one macro and save them at macros. The set
% macros have an optional argument: the shift.
%
% For definition of symbolic length values there is the macro
% \cs{settowidthof}. And to define a macro with this value, there
% is \cs{deftowidthof}.
%    \begin{macrocode}
\newcommand*{\settowidthof}[2]{%
  \edef\@tempa{#2}%
  \edef\@tempb{paper}\ifx\@tempa\@tempb
    \setlength{#1}{\paperwidth}%
  \else\edef\@tempb{text}\ifx\@tempa\@tempb
      \setlength{#1}{\textwidth}%
    \else\edef\@tempb{textwithmarginpar}\ifx\@tempa\@tempb
        \setlength{#1}{\textwidth}%
        \addtolength{#1}{\marginparwidth}%
        \addtolength{#1}{\marginparsep}%
      \else\edef\@tempb{head}\ifx\@tempa\@tempb
          \setlength{#1}{\@headwidth}%
        \else\edef\@tempb{foot}\ifx\@tempa\@tempb
            \setlength{#1}{\@footwidth}%
          \else\edef\@tempb{headtopline}\ifx\@tempa\@tempb
              \setlength{#1}{\scr@headabove@linelength}%
            \else\edef\@tempb{headsepline}\ifx\@tempa\@tempb
                \setlength{#1}{\scr@headbelow@linelength}%
              \else\edef\@tempb{footsepline}\ifx\@tempa\@tempb
                  \setlength{#1}{\scr@footabove@linelength}%
                \else\edef\@tempb{footbotline}\ifx\@tempa\@tempb
                    \setlength{#1}{\scr@footbelow@linelength}%
                  \else\edef\@tempb{page}\ifx\@tempa\@tempb
                      \setlength{#1}{\paperwidth}%
                      \begingroup\expandafter\expandafter\expandafter\endgroup
                      \expandafter\ifx\csname ta@bcor\endcsname\relax\else
                        \addtolength{#1}{-\ta@bcor}%
                      \fi
                    \else
                      \setlength{#1}{#2}%
                    \fi
                  \fi
                \fi
              \fi
            \fi
          \fi
        \fi
      \fi
    \fi
  \fi
}
\newcommand*{\deftowidthof}[2]{%
  \edef\@tempa{#2}\edef\@tempb{autohead}\ifx\@tempa\@tempb
    \expandafter\def\csname #1\endcsname{\@headwidth}%
  \else\edef\@tempb{autofoot}\ifx\@tempa\@tempb
      \expandafter\def\csname #1\endcsname{\@footwidth}%
    \else
      \settowidthof{\@tempdima}{#2}%
      \expandafter\edef\csname #1\endcsname{\the\@tempdima}%
    \fi
  \fi
}
\newcommand*{\setheadwidth}[2][\@empty]{%
  \set@hf@width{head}{#1}{#2} %
}
\newcommand*{\setfootwidth}[2][\@empty]{%
  \set@hf@width{foot}{#1}{#2}%
}
\newcommand*{\set@hf@width}[3]{%
  \settowidthof{\@tempdima}{#3}%
  \ifdim\@tempdima>\paperwidth
    \PackageWarning
      {scrpage2}%
      {You've set width of #1 to a value\MessageBreak
        greater than width of page!\MessageBreak%
        I`ll reduce width of #1 to width of page}%
    \setlength{\@tempdima}{\paperwidth}%
  \else
    \ifdim\@tempdima<\z@
       \PackageWarning
         {scrpage2}%
         {You've set width of #1 to negative value!\MessageBreak%
           I'll set it to 0pt}%
       \setlength{\@tempdima}{\z@}%
     \fi
  \fi
  \expandafter\edef\csname @#1width\endcsname{\the\@tempdima}%
  \edef\@tempa{#2}%
  \setlength{\@tempdima}{\textwidth}%
  \addtolength{\@tempdima}{-\csname @#1width\endcsname}%
  \ifx\@tempa\@empty
    \if@twoside
      \setlength{\@tempdimb}{.3333333333\@tempdima}%
    \else
      \setlength{\@tempdimb}{.5\@tempdima}%
    \fi
  \else
    \setlength{\@tempdimb}{#2}%
  \fi
  \addtolength{\@tempdima}{-\@tempdimb}%
  \ifdim\@tempdimb<\z@
    \setlength{\@tempdimb}{-\@tempdimb}%
    \expandafter\edef\csname @odd#1shift\endcsname{-\the\@tempdimb}%
  \else
    \expandafter\edef\csname @odd#1shift\endcsname{\the\@tempdimb}%
  \fi
  \ifdim\@tempdima<\z@
    \setlength{\@tempdima}{-\@tempdima}%
    \expandafter\edef\csname @even#1shift\endcsname{-\the\@tempdima}%
  \else
    \expandafter\edef\csname @even#1shift\endcsname{\the\@tempdima}%
  \fi
}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\@headwidth}
%   \changes{v1.3}{2001/03/30}{New}
%   \changes{v2.1}{2002/03/28}{use of option \texttt{mpinclude}}
% \begin{macro}{\@footwidth}
%   \changes{v1.3}{2001/03/30}{New}
%   \changes{v2.1}{2002/03/28}{use of option \texttt{mpinclude}}
% \begin{macro}{\@oddheadshift}
%   \changes{v1.3}{2001/03/30}{New}
% \begin{macro}{\@evenheadshift}
%   \changes{v1.3}{2001/03/30}{New}
% \begin{macro}{\@oddfootshift}
%   \changes{v1.3}{2001/03/30}{New}
% \begin{macro}{\@evenfootshift}
%   \changes{v1.3}{2001/03/30}{New}
% The values of width and shift of head and foot are saved at internal
% macros. 
%    \begin{macrocode}
\newcommand*{\@headwidth}{\textwidth}%
\newcommand*{\@oddheadshift}{\z@}%
\newcommand*{\@evenheadshift}{\z@}%
\newcommand*{\@footwidth}{\textwidth}%
\newcommand*{\@oddfootshift}{\z@}%
\newcommand*{\@evenfootshift}{\z@}%
%    \end{macrocode}
% If option \texttt{mpinclude} was used, we use a special trick to set
% width of head and foot but only if the user doesn't:
%    \begin{macrocode}
\if@mincl
  \renewcommand*{\@headwidth}{}%
  \renewcommand*{\@footwidth}{}%
  \AtBeginDocument{%
    \ifx\@headwidth\@empty
      \setheadwidth[0pt]{textwithmarginpar}%
    \fi
    \ifx\@footwidth\@empty
      \setfootwidth[0pt]{textwithmarginpar}%
    \fi
    }
\fi
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
%
% \subsection{Fonts}
% \begin{macro}{\pnumfont}
% We have to define a macro defining the font, used by |\pagemark|. Because
% of this macro may already be defined by a \textsf{KOMA}-script-class, we
% have to do this, using |\providecommand|
%    \begin{macrocode}
\providecommand*{\pnumfont}{\normalfont}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\headfont}
% There is also a macro used by |\@evenhead|, |\@oddhead| and |\@evenfoot|,
% |\@oddfoot|:
%    \begin{macrocode}
\providecommand*{\headfont}{\normalfont\slshape}
\def\scr@fnt@wrn@pagehead#1{%
  `pagehead' is only an alias of `pageheadfoot'.\MessageBreak
  Font of page foot may also be changed%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\footfont}
%   \changes{v2.2f}{2008/02/14}{New}
% \begin{macro}{\scr@fnt@pagefoot}
%   \changes{v2.2f}{2008/02/14}{New (internal)}
% \begin{macro}{\scr@fnt@wrn@pagefoot}
%   \changes{v2.2f}{2008/02/14}{deactivated}
% There is also a macro used by |\@evenfoot|, |\@oddfoot| after |\headfont|:
%    \begin{macrocode}
\providecommand*{\footfont}{\normalfont}
\providecommand*{\scr@fnt@pagefoot}{\footfont}
\let\scr@fnt@wrn@pagefoot\relax
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
%
%
% \subsection{Length and thickness of lines at head and foot}
% \begin{macro}{\setheadtopline}
%   \changes{v2.0}{2001/04/20}{New}
%   \changes{v2.0d}{2001/06/19}{\texttt{headtop} changed into
%     \texttt{headabove}} 
%   \changes{v2.0f}{2001/06/23}{new symbolic value ``auto''}
% \begin{macro}{\setheadsepline}
%   \changes{v2.0}{2001/04/20}{New}
%   \changes{v2.0d}{2001/06/19}{\texttt{headbot} changed into 
%     \texttt{headbelow}}
%   \changes{v2.0f}{2001/06/23}{new symbolic value ``auto''}
% \begin{macro}{\setfootsepline}
%   \changes{v2.0}{2001/04/20}{New}
%   \changes{v2.0d}{2001/06/19}{\texttt{foottop} changed into 
%     \texttt{footabove}}
%   \changes{v2.0f}{2001/06/23}{new symbolic value ``auto''}
% \begin{macro}{\setfootbotline}
%   \changes{v2.0}{2001/04/20}{New}
%   \changes{v2.0d}{2001/06/19}{\texttt{footbot} changed into 
%     \texttt{footbelow}}
%   \changes{v2.0f}{2001/06/23}{new symbolic value ``auto''}
% Since version 2 there are new macros to set the length and
% thickness of the lines at head and foot. Wie use macros not
% dimensions, because the amount of dimensions is very small at \TeX.
%    \begin{macrocode}
\newcommand*{\setheadtopline}{\scr@setline{head}{above}}
\newcommand*{\setheadsepline}{\scr@setline{head}{below}}
\newcommand*{\setfootsepline}{\scr@setline{foot}{above}}
\newcommand*{\setfootbotline}{\scr@setline{foot}{below}}
%    \end{macrocode}
% \begin{macro}{\scr@setline}
%   \changes{v3.20}{2016/04/12}{\cs{@ifnextchar} replaced by
%     \cs{kernel@ifnextchar}}^^A
% \begin{macro}{\@scr@setline}
%   \changes{v2.0d}{2001/06/19}{symbolic values implemented}
% \begin{macro}{\@@scr@setline}
%   \changes{v2.0d}{2001/06/18}{macro name fixed}
%   \changes{v3.20}{2016/04/12}{\cs{@ifnextchar} replaced by
%     \cs{kernel@ifnextchar}}^^A
% \begin{macro}{\@scr@set@pre@line}
%   \changes{v2.2}{2004/07/05}{New internal}
% The real change of the lines is done with the macros
% \cs{scr@setline}, \cs{@scr@setline} and \cs{@@scr@setline}:
%    \begin{macrocode}
\def\scr@setline#1#2{%
  \kernel@ifnextchar[%]
  {\@scr@setline{#1}{#2}}{\@@scr@setline{#1#2}}%
}
\def\@scr@setline#1#2[#3]{%
  \edef\@tempa{#3}\edef\@tempa{auto}\ifx\@tempa\@tempb
    \deftowidthof{scr@#1#2@linelength}{#3#1}%
  \else
    \deftowidthof{scr@#1#2@linelength}{#3}%
  \fi
  \@@scr@setline{#1#2}%
}
\def\@@scr@setline#1#2{%
  \edef\@tempa{#2}\edef\@tempb{current}\ifx\@tempa\@empty\else
    \ifx\@tempa\@tempb\else
      \setlength{\@tempdima}{#2}%
      \expandafter\edef\csname scr@#1@linethickness\endcsname%
      {\the\@tempdima}%
  \fi\fi
  \kernel@ifnextchar[%]
  {\@src@set@pre@line{#1}}{}%
}
\def\@src@set@pre@line#1[#2]{%
  \expandafter\def\csname scr@pre@#1@line\endcsname{#2}%
}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
%
% \subsection{Extended multilanguage formats}
% \begin{macro}{\partmarkformat}
%   \changes{v2.2}{2004/07/05}{New}
% \begin{macro}{\chaptermarkformat}
%   \changes{v1.1}{1995/06/27}{Space after chapternumber increased.}
% \begin{macro}{\sectionmarkformat}
%   \changes{v1.1}{1995/06/27}{Space after sectionnumber increased.}
% \begin{macro}{\subsectionmarkformat}
%   \changes{v1.1}{1995/06/27}{Space after subsectionnumber increased.}
% \begin{macro}{\subsubsectionmarkformat}
%   \changes{v2.0}{2001/04/20}{New}
% \begin{macro}{\paragraphmarkformat}
%   \changes{v2.0}{2001/04/20}{New}
% \begin{macro}{\subparagraphmarkformat}
%   \changes{v2.0}{2001/04/20}{New}
% \begin{macro}{\@seccntmarkformat}
%   \changes{v2.0}{2001/04/20}{New}
% \begin{macro}{\@seccntformat}
%   \changes{v2.0}{2001/04/20}{New}
% There are some macros to handle languages like Chinese, Japanese or Korean.
% These macros were defined first by Werner Lemberg at his CJK-bundle. See
% |scrclass.dtx| for further information.
%    \begin{macrocode}
\providecommand{\partmarkformat}         {\partname\ \thepart. \ }
\if@chapter
  \providecommand{\chaptermarkformat}    {\@chapapp\ \thechapter. \ }
  \providecommand{\sectionmarkformat}    {\thesection. \ }
  \providecommand{\subsectionmarkformat} {\@seccntmarkformat{subsection}}
\else
  \providecommand{\sectionmarkformat}    {\thesection\quad}
  \providecommand{\subsectionmarkformat} {\thesubsection\quad}
\fi
\providecommand{\subsubsectionmarkformat}{\@seccntmarkformat{subsubsection}}
\providecommand{\paragraphmarkformat}    {\@seccntmarkformat{paragraph}}
\providecommand{\subparagraphmarkformat} {\@seccntmarkformat{subparagraph}}
\providecommand{\@seccntmarkformat}[1]   {\@seccntformat{#1}}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
%
% \subsection{Definition of default pagestyles}
%
% \begin{macro}{\ps@save@plain}
%   \changes{v2.0}{2001/04/20}{New}
%   \changes{v2.0b}{2001/05/31}{use this instead of
%     \cs{ps@standardplain}} 
% We define two default pagestyles, which can be used instead of the
% standard pagestyles. The two pagestyles are something like a
% family. A pagestyle for \emph{normal} pages with head and foot and a
% pagestyle for \emph{plain} pages with not so much head and foot. So
% we have to redefine the standard pagestyle \texttt{plain}. But maybe
% someone want to use the old standard pagestyle. So we first define
% new names for old pagestyles.
%    \begin{macrocode}
\newcommand*{\ps@save@plain}{}
\let\ps@save@plain\ps@plain
\newcommand*{\ps@use@plain}{\let\save@@mkboth\@mkboth
  \ps@save@plain
  \let\@mkboth\save@@mkboth}
\let\ps@plain\ps@use@plain
%    \end{macrocode}
% \begin{macro}{\ps@save@headings}
%   \changes{v2.0}{2001/04/20}{New}
%   \changes{v2.0b}{2001/05/31}{use this instead of
%     \cs{ps@standardheadings}} 
% \begin{macro}{\ps@save@myheadings}
%   \changes{v2.0}{2001/04/20}{New}
%   \changes{v2.0b}{2001/05/31}{use this instead of
%     \cs{ps@standardmyheadings}} 
% \begin{macro}{\ps@headings}
%   \changes{v2.0}{2001/04/20}{New}
% \begin{macro}{\ps@myheadings}
%   \changes{v2.0}{2001/04/20}{New}
% If standard pagestyle \texttt{headings} or \texttt{myheadings} is
% used, also standard pagestyle \texttt{use@plain} should be
% used. So we also define new names for the other old pagestyles and
% new pagestyles with the old names, doing the switch back for the
% plain pagestyle. These are defined even if the pagestyles are
% unknown.
%    \begin{macrocode}
\newcommand*{\ps@save@headings}{}
\let\ps@save@headings\ps@headings
\newcommand*{\ps@save@myheadings}{}
\let\ps@save@myheadings\ps@myheadings
\def\ps@headings{%
  \PackageWarning{scrpage2}%
    {you've used pagestyle ``headings''.\MessageBreak
      You should not use this pagestyle with a\MessageBreak
      scrpage2-pagestyle!\MessageBreak 
      You should use pagestyle ``useheadings'' instead\MessageBreak}%
  \let\ps@plain\ps@save@plain%
  \ps@save@headings\@automarktrue}
\def\ps@myheadings{%
  \PackageWarning{scrpage2}%
    {you've used pagestyle ``myheadings''.\MessageBreak
      You should not use this pagestyle with a\MessageBreak
      scrpage2-pagestyle!\MessageBreak 
      You should use pagestyle ``useheadings'' instead\MessageBreak}%
  \let\ps@plain\ps@save@plain%
  \ps@save@myheadings\@automarkfalse}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
%
% \begin{macro}{\ps@useheadings}
%   \changes{v2.0b}{2001/05/31}{New}
%   \changes{v2.0m}{2002/02/05}{Fatal bug (\cs{mkboth} instead of
%     \cs{@mkboth}) fixed}
%   \changes{v2.1a}{2002/10/30}{Use of switch \cs{if@automark}}
% This is the pagestyle, you should use instead of \texttt{headings}
% or \texttt{myheadings}. If you are using manual marks, this behaves
% like pagestyle \texttt{myheadings}. If you are using automatic
% marks, this behaves like headings, but without changing
% \cs{chaptermark}, \cs{sectionmark} or \cs{subsectionmark}.
%    \begin{macrocode}
\newcommand*{\ps@useheadings}{%
  \if@automark\let\@mkboth\markboth\else\let\@mkboth\@gobbletwo\fi
  \let\ps@plain\ps@use@plain
  \let\save@@mkboth\@mkboth
  \let\save@chaptermark\chaptermark
  \let\save@sectionmark\sectionmark
  \let\save@subsectionmark\subsectionmark
  \ifx\@mkboth\markboth\ps@save@headings\else\ps@save@myheadings\fi
  \let\@mkboth\save@@mkboth
  \let\chaptermark\save@chaptermark
  \let\sectionmark\save@sectionmark
  \let\subsectionmark\save@subsectionmark
}
%    \end{macrocode}
% Note: Because of saving \cs{@mkboth}, \cs{chaptermark},
% \cs{sectionmark} and \cs{subsection} before changing the pagestyle
% and restore them after changing the pagestyle it does not matter, if
% we set pagestyle \texttt{headings} or \texttt{myheadings}. So it
% would be possible to remove the \cs{ifx}\dots\cs{fi}-line above and
% simply use \cs{ps@save@headings} or \cs{ps@save@myheadings} instead
% of.
% \end{macro}
%
%
% \begin{macro}{\ps@scrplain}
%   \changes{v2.0}{2001/04/20}{New}
%   \changes{v2.0a}{2001/04/24}{\cs{strut} inserted}
%   \changes{v2.0f}{2001/06/23}{\cs{strut} inserted}
%   \changes{v2.1c}{2004/02/07}{thickness of footbelow line fixed}
% \begin{macro}{\scrplain@even@left@head}
%   \changes{v2.0}{2001/04/20}{New}
% \begin{macro}{\scrplain@even@middle@head}
%   \changes{v2.0}{2001/04/20}{New}
% \begin{macro}{\scrplain@even@right@head}
%   \changes{v2.0}{2001/04/20}{New}
% \begin{macro}{\scrplain@odd@left@head}
%   \changes{v2.0}{2001/04/20}{New}
% \begin{macro}{\scrplain@odd@middle@head}
%   \changes{v2.0}{2001/04/20}{New}
% \begin{macro}{\scrplain@odd@right@head}
%   \changes{v2.0}{2001/04/20}{New}
% \begin{macro}{\scrplain@even@left@foot}
%   \changes{v2.0}{2001/04/20}{New}
% \begin{macro}{\scrplain@even@middle@foot}
%   \changes{v2.0}{2001/04/20}{New}
% \begin{macro}{\scrplain@even@right@foot}
%   \changes{v2.0}{2001/04/20}{New}
% \begin{macro}{\scrplain@odd@left@foot}
%   \changes{v2.0}{2001/04/20}{New}
% \begin{macro}{\scrplain@odd@middle@foot}
%   \changes{v2.0}{2001/04/20}{New}
% \begin{macro}{\scrplain@odd@right@foot}
%   \changes{v2.0}{2001/04/20}{New}
% After this, we can define the new pagestyles, first a new plain
% one. It sould be variable and so we use macros to define the parts.
%    \begin{macrocode}
\newcommand*{\ps@scrplain}{\let\ps@plain\ps@@scrplain\ps@plain}
\newpagestyle{@scrplain}
{%
  (\scrplain@headabove@linelength,\scr@headabove@linethickness)%
  {%
    \rlap{\parbox{\@headwidth}{\raggedright
        \strut\scrplain@even@left@head\strut}}%
    \hfill
    \parbox{\@headwidth}{\centering\strut
      \scrplain@even@middle@head\strut}%
    \hfill
    \llap{\parbox{\@headwidth}{\raggedleft
        \strut\scrplain@even@right@head\strut}}}%
  {%
    \rlap{\parbox{\@headwidth}{\raggedright
        \strut\scrplain@odd@left@head\strut}}%
    \hfill
    \parbox{\@headwidth}{\centering
      \strut\scrplain@odd@middle@head\strut}%
    \hfill
    \llap{\parbox{\@headwidth}{\raggedleft
        \strut\scrplain@odd@right@head\strut}}}%
  {%
    \rlap{\parbox{\@headwidth}{\raggedright
        \strut\scrplain@odd@left@head\strut}}%
    \hfill
    \parbox{\@headwidth}{\centering
      \strut\scrplain@odd@middle@head\strut}%
    \hfill
    \llap{\parbox{\@headwidth}{\raggedleft
        \strut\scrplain@odd@right@head\strut}}}%
  (\scrplain@headbelow@linelength,\scr@headbelow@linethickness)
}{%
  (\scrplain@footabove@linelength,\scr@footabove@linethickness)
  {%
    \rlap{\parbox{\@footwidth}{\raggedright
        \strut\scrplain@even@left@foot\strut}}%
    \hfill
    \parbox{\@footwidth}{\centering
      \strut\scrplain@even@middle@foot\strut}%
    \hfill
    \llap{\parbox{\@footwidth}{\raggedleft
        \strut\scrplain@even@right@foot\strut}}}%
  {%
    \rlap{\parbox{\@footwidth}{\raggedright
        \strut\scrplain@odd@left@foot\strut}}%
    \hfill
    \parbox{\@footwidth}{\centering
      \strut\scrplain@odd@middle@foot\strut}%
    \hfill
    \llap{\parbox{\@footwidth}{\raggedleft
        \strut\scrplain@odd@right@foot\strut}}}%
  {%
    \rlap{\parbox{\@footwidth}{\raggedright
        \strut\scrplain@odd@left@foot\strut}}%
    \hfill
    \parbox{\@footwidth}{\centering
      \strut\scrplain@odd@middle@foot\strut}%
    \hfill
    \llap{\parbox{\@footwidth}{\raggedleft
        \strut\scrplain@odd@right@foot\strut}}}%
  (\scrplain@footbelow@linelength,\scr@footbelow@linethickness)
}
\newcommand*{\scrplain@even@left@head}{}
\newcommand*{\scrplain@even@middle@head}{}
\newcommand*{\scrplain@even@right@head}{}
\newcommand*{\scrplain@odd@left@head}{}
\newcommand*{\scrplain@odd@middle@head}{}
\newcommand*{\scrplain@odd@right@head}{}
\newcommand*{\scrplain@even@left@foot}{}
\newcommand*{\scrplain@even@middle@foot}{}
\newcommand*{\scrplain@even@right@foot}{}
\newcommand*{\scrplain@odd@left@foot}{}
\newcommand*{\scrplain@odd@middle@foot}{}
\newcommand*{\scrplain@odd@right@foot}{}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \begin{macro}{\ps@scrheadings}
%   \changes{v2.0}{2001/04/20}{New}
%   \changes{v2.0a}{2001/04/24}{\cs{strut} inserted}
%   \changes{v2.0f}{2001/06/23}{\cs{strut} inserted}
% \begin{macro}{\scrheadings@even@left@head}
%   \changes{v2.0}{2001/04/20}{New}
% \begin{macro}{\scrheadings@even@middle@head}
%   \changes{v2.0}{2001/04/20}{New}
% \begin{macro}{\scrheadings@even@right@head}
%   \changes{v2.0}{2001/04/20}{New}
% \begin{macro}{\scrheadings@odd@left@head}
%   \changes{v2.0}{2001/04/20}{New}
% \begin{macro}{\scrheadings@odd@middle@head}
%   \changes{v2.0}{2001/04/20}{New}
% \begin{macro}{\scrheadings@odd@right@head}
%   \changes{v2.0}{2001/04/20}{New}
% \begin{macro}{\scrheadings@even@left@foot}
%   \changes{v2.0}{2001/04/20}{New}
% \begin{macro}{\scrheadings@even@middle@foot}
%   \changes{v2.0}{2001/04/20}{New}
% \begin{macro}{\scrheadings@even@right@foot}
%   \changes{v2.0}{2001/04/20}{New}
% \begin{macro}{\scrheadings@odd@left@foot}
%   \changes{v2.0}{2001/04/20}{New}
% \begin{macro}{\scrheadings@odd@middle@foot}
%   \changes{v2.0}{2001/04/20}{New}
% \begin{macro}{\scrheadings@odd@right@foot}
%   \changes{v2.0}{2001/04/20}{New}
% We also define define a new headings one. It sould be variable and
% so we use macros to define the parts. But we need an \emph{also
% action}, so we first define a inner pagestyle and then use this at a
% outer one (definition is done in reverse order):
%    \begin{macrocode}
\newcommand*{\ps@scrheadings}{\let\ps@plain\ps@scrplain\ps@@scrheadings}
\newpagestyle{@scrheadings}
{%
  {%
    \rlap{\parbox{\@headwidth}{\raggedright
        \strut\scrheadings@even@left@head\strut}}%
    \hfill
    \parbox{\@headwidth}{\centering
      \strut\scrheadings@even@middle@head\strut}%
    \hfill
    \llap{\parbox{\@headwidth}{\raggedleft%
        \strut\scrheadings@even@right@head\strut}}}%
  {%
    \rlap{\parbox{\@headwidth}{\raggedright
        \strut\scrheadings@odd@left@head\strut}}%
    \hfill
    \parbox{\@headwidth}{\centering
      \strut\scrheadings@odd@middle@head\strut}%
    \hfill
    \llap{\parbox{\@headwidth}{\raggedleft%
        \strut\scrheadings@odd@right@head\strut}}}%
  {%
    \rlap{\parbox{\@headwidth}{\raggedright
        \strut\scrheadings@odd@left@head\strut}}%
    \hfill
    \parbox{\@headwidth}{\centering
      \strut\scrheadings@odd@middle@head\strut}%
    \hfill
    \llap{\parbox{\@headwidth}{\raggedleft
        \strut\scrheadings@odd@right@head\strut}}}}%
{%
  {%
    \rlap{\parbox{\@footwidth}{\raggedright
        \strut\scrheadings@even@left@foot\strut}}%
    \hfill
    \parbox{\@footwidth}{\centering
      \strut\scrheadings@even@middle@foot\strut}%
    \hfill
    \llap{\parbox{\@footwidth}{\raggedleft
        \strut\scrheadings@even@right@foot\strut}}}%
  {%
    \rlap{\parbox{\@footwidth}{\raggedright
        \strut\scrheadings@odd@left@foot\strut}}%
    \hfill
    \parbox{\@footwidth}{\centering
      \strut\scrheadings@odd@middle@foot\strut}%
    \hfill
    \llap{\parbox{\@footwidth}{\raggedleft
        \strut\scrheadings@odd@right@foot\strut}}}%
  {%
    \rlap{\parbox{\@footwidth}{\raggedright
        \strut\scrheadings@odd@left@foot\strut}}%
    \hfill
    \parbox{\@footwidth}{\centering
      \strut\scrheadings@odd@middle@foot\strut}%
    \hfill
    \llap{\parbox{\@footwidth}{\raggedleft
        \strut\scrheadings@odd@right@foot\strut}}%
  }%
}
\newcommand*{\scrheadings@even@left@head}{}
\newcommand*{\scrheadings@even@middle@head}{}
\newcommand*{\scrheadings@even@right@head}{}
\newcommand*{\scrheadings@odd@left@head}{}
\newcommand*{\scrheadings@odd@middle@head}{}
\newcommand*{\scrheadings@odd@right@head}{}
\newcommand*{\scrheadings@even@left@foot}{}
\newcommand*{\scrheadings@even@middle@foot}{}
\newcommand*{\scrheadings@even@right@foot}{}
\newcommand*{\scrheadings@odd@left@foot}{}
\newcommand*{\scrheadings@odd@middle@foot}{}
\newcommand*{\scrheadings@odd@right@foot}{}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
%
% \begin{macro}{\ihead}
%   \changes{v2.0}{2001/04/20}{New}
%   \changes{v3.20}{2016/04/12}{\cs{@ifnextchar} replaced by
%     \cs{kernel@ifnextchar}}^^A
% \begin{macro}{\ohead}
%   \changes{v2.0}{2001/04/20}{New}
%   \changes{v3.20}{2016/04/12}{\cs{@ifnextchar} replaced by
%     \cs{kernel@ifnextchar}}^^A
% \begin{macro}{\chead}
%   \changes{v2.0}{2001/04/20}{New}
%   \changes{v3.20}{2016/04/12}{\cs{@ifnextchar} replaced by
%     \cs{kernel@ifnextchar}}^^A
% \begin{macro}{\lehead}
%   \changes{v2.0}{2001/04/20}{New}
%   \changes{v3.20}{2016/04/12}{\cs{@ifnextchar} replaced by
%     \cs{kernel@ifnextchar}}^^A
% \begin{macro}{\lohead}
%   \changes{v2.0}{2001/04/20}{New}
%   \changes{v3.20}{2016/04/12}{\cs{@ifnextchar} replaced by
%     \cs{kernel@ifnextchar}}^^A
% \begin{macro}{\rehead}
%   \changes{v2.0}{2001/04/20}{New}
%   \changes{v3.20}{2016/04/12}{\cs{@ifnextchar} replaced by
%     \cs{kernel@ifnextchar}}^^A
% \begin{macro}{\rohead}
%   \changes{v2.0}{2001/04/20}{New}
%   \changes{v3.20}{2016/04/12}{\cs{@ifnextchar} replaced by
%     \cs{kernel@ifnextchar}}^^A
% \begin{macro}{\cehead}
%   \changes{v2.0}{2001/04/20}{New}
%   \changes{v3.20}{2016/04/12}{\cs{@ifnextchar} replaced by
%     \cs{kernel@ifnextchar}}^^A
% \begin{macro}{\cohead}
%   \changes{v2.0}{2001/04/20}{New}
%   \changes{v3.20}{2016/04/12}{\cs{@ifnextchar} replaced by
%     \cs{kernel@ifnextchar}}^^A
% \begin{macro}{\ifoot}
%   \changes{v2.0}{2001/04/20}{New}
%   \changes{v3.20}{2016/04/12}{\cs{@ifnextchar} replaced by
%     \cs{kernel@ifnextchar}}^^A
% \begin{macro}{\ofoot}
%   \changes{v2.0}{2001/04/20}{New}
%   \changes{v3.20}{2016/04/12}{\cs{@ifnextchar} replaced by
%     \cs{kernel@ifnextchar}}^^A
% \begin{macro}{\cfoot}
%   \changes{v2.0}{2001/04/20}{New}
%   \changes{v3.20}{2016/04/12}{\cs{@ifnextchar} replaced by
%     \cs{kernel@ifnextchar}}^^A
% \begin{macro}{\lefoot}
%   \changes{v2.0}{2001/04/20}{New}
%   \changes{v3.20}{2016/04/12}{\cs{@ifnextchar} replaced by
%     \cs{kernel@ifnextchar}}^^A
% \begin{macro}{\lofoot}
%   \changes{v2.0}{2001/04/20}{New}
%   \changes{v3.20}{2016/04/12}{\cs{@ifnextchar} replaced by
%     \cs{kernel@ifnextchar}}^^A
% \begin{macro}{\refoot}
%   \changes{v2.0}{2001/04/20}{New}
%   \changes{v3.20}{2016/04/12}{\cs{@ifnextchar} replaced by
%     \cs{kernel@ifnextchar}}^^A
% \begin{macro}{\rofoot}
%   \changes{v2.0}{2001/04/20}{New}
%   \changes{v3.20}{2016/04/12}{\cs{@ifnextchar} replaced by
%     \cs{kernel@ifnextchar}}^^A
% \begin{macro}{\cefoot}
%   \changes{v2.0}{2001/04/20}{New}
%   \changes{v3.20}{2016/04/12}{\cs{@ifnextchar} replaced by
%     \cs{kernel@ifnextchar}}^^A
% \begin{macro}{\cofoot}
%   \changes{v2.0}{2001/04/20}{New}
%   \changes{v3.20}{2016/04/12}{\cs{@ifnextchar} replaced by
%     \cs{kernel@ifnextchar}}^^A
% We also need macros to define the contents of the three part head
% and foot. Each macro defines one of the part of head or foot of the
% scrheadings pagestyle and optional of the scrplain pagestyle.
%    \begin{macrocode}
\newcommand{\ihead}{\kernel@ifnextchar[{\@@lhead}{\@lhead}}
\newcommand{\@lhead}[1]{\@rehead{#1}\@lohead{#1}}
\newcommand{\@@lhead}[2][]{\@@rehead[{#1}]{#2}\@@lohead[{#1}]{#2}}
\newcommand{\ohead}{\kernel@ifnextchar[{\@@rhead}{\@rhead}}
\newcommand{\@rhead}[1]{\@lehead{#1}\@rohead{#1}}
\newcommand{\@@rhead}[2][]{\@@lehead[{#1}]{#2}\@@rohead[{#1}]{#2}}
\newcommand{\chead}{\kernel@ifnextchar[{\@@chead}{\@chead}}
\newcommand{\@chead}[1]{\@cehead{#1}\@cohead{#1}}
\newcommand{\@@chead}[2][]{\@@cehead[{#1}]{#2}\@@cohead[{#1}]{#2}}
\newcommand{\lehead}{\kernel@ifnextchar[{\@@lehead}{\@lehead}}
\newcommand{\@lehead}[1]{\renewcommand*{\scrheadings@even@left@head}{#1}}
\newcommand{\@@lehead}[2][]{%
  \renewcommand*{\scrplain@even@left@head}{#1}%
  \renewcommand*{\scrheadings@even@left@head}{#2}}
\newcommand{\lohead}{\kernel@ifnextchar[{\@@lohead}{\@lohead}}
\newcommand{\@lohead}[1]{\renewcommand*{\scrheadings@odd@left@head}{#1}}
\newcommand{\@@lohead}[2][]{%
  \renewcommand*{\scrplain@odd@left@head}{#1}%
  \renewcommand*{\scrheadings@odd@left@head}{#2}}
\newcommand{\rehead}{\kernel@ifnextchar[{\@@rehead}{\@rehead}}
\newcommand{\@rehead}[1]{\renewcommand*{\scrheadings@even@right@head}{#1}}
\newcommand{\@@rehead}[2][]{%
  \renewcommand*{\scrplain@even@right@head}{#1}%
  \renewcommand*{\scrheadings@even@right@head}{#2}}
\newcommand{\rohead}{\kernel@ifnextchar[{\@@rohead}{\@rohead}}
\newcommand{\@rohead}[1]{\renewcommand*{\scrheadings@odd@right@head}{#1}}
\newcommand{\@@rohead}[2][]{%
  \renewcommand*{\scrplain@odd@right@head}{#1}%
  \renewcommand*{\scrheadings@odd@right@head}{#2}}
\newcommand{\cehead}{\kernel@ifnextchar[{\@@cehead}{\@cehead}}
\newcommand{\@cehead}[1]{\renewcommand*{\scrheadings@even@middle@head}{#1}}
\newcommand{\@@cehead}[2][]{%
  \renewcommand*{\scrplain@even@middle@head}{#1}%
  \renewcommand*{\scrheadings@even@middle@head}{#2}}
\newcommand{\cohead}{\kernel@ifnextchar[{\@@cohead}{\@cohead}}
\newcommand{\@cohead}[1]{\renewcommand*{\scrheadings@odd@middle@head}{#1}}
\newcommand{\@@cohead}[2][]{%
  \renewcommand*{\scrplain@odd@middle@head}{#1}%
  \renewcommand*{\scrheadings@odd@middle@head}{#2}}
\newcommand{\ifoot}{\kernel@ifnextchar[{\@@lfoot}{\@lfoot}}
\newcommand{\@lfoot}[1]{\@refoot{#1}\@lofoot{#1}}
\newcommand{\@@lfoot}[2][]{\@@refoot[{#1}]{#2}\@@lofoot[{#1}]{#2}}
\newcommand{\ofoot}{\kernel@ifnextchar[{\@@rfoot}{\@rfoot}}
\newcommand{\@rfoot}[1]{\@lefoot{#1}\@rofoot{#1}}
\newcommand{\@@rfoot}[2][]{\@@lefoot[{#1}]{#2}\@@rofoot[{#1}]{#2}}
\newcommand{\cfoot}{\kernel@ifnextchar[{\@@cfoot}{\@cfoot}}
\newcommand{\@cfoot}[1]{\@cefoot{#1}\@cofoot{#1}}
\newcommand{\@@cfoot}[2][]{\@@cefoot[{#1}]{#2}\@@cofoot[{#1}]{#2}}
\newcommand{\lefoot}{\kernel@ifnextchar[{\@@lefoot}{\@lefoot}}
\newcommand{\@lefoot}[1]{\renewcommand*{\scrheadings@even@left@foot}{#1}}
\newcommand{\@@lefoot}[2][]{%
  \renewcommand*{\scrplain@even@left@foot}{#1}%
  \renewcommand*{\scrheadings@even@left@foot}{#2}}
\newcommand{\lofoot}{\kernel@ifnextchar[{\@@lofoot}{\@lofoot}}
\newcommand{\@lofoot}[1]{\renewcommand*{\scrheadings@odd@left@foot}{#1}}
\newcommand{\@@lofoot}[2][]{%
  \renewcommand*{\scrplain@odd@left@foot}{#1}%
  \renewcommand*{\scrheadings@odd@left@foot}{#2}}
\newcommand{\refoot}{\kernel@ifnextchar[{\@@refoot}{\@refoot}}
\newcommand{\@refoot}[1]{\renewcommand*{\scrheadings@even@right@foot}{#1}}
\newcommand{\@@refoot}[2][]{%
  \renewcommand*{\scrplain@even@right@foot}{#1}%
  \renewcommand*{\scrheadings@even@right@foot}{#2}}
\newcommand{\rofoot}{\kernel@ifnextchar[{\@@rofoot}{\@rofoot}}
\newcommand{\@rofoot}[1]{\renewcommand*{\scrheadings@odd@right@foot}{#1}}
\newcommand{\@@rofoot}[2][]{%
  \renewcommand*{\scrplain@odd@right@foot}{#1}%
  \renewcommand*{\scrheadings@odd@right@foot}{#2}}
\newcommand{\cefoot}{\kernel@ifnextchar[{\@@cefoot}{\@cefoot}}
\newcommand{\@cefoot}[1]{\renewcommand*{\scrheadings@even@middle@foot}{#1}}
\newcommand{\@@cefoot}[2][]{%
  \renewcommand*{\scrplain@even@middle@foot}{#1}%
  \renewcommand*{\scrheadings@even@middle@foot}{#2}}
\newcommand{\cofoot}{\kernel@ifnextchar[{\@@cofoot}{\@cofoot}}
\newcommand{\@cofoot}[1]{\renewcommand*{\scrheadings@odd@middle@foot}{#1}}
\newcommand{\@@cofoot}[2][]{%
  \renewcommand*{\scrplain@odd@middle@foot}{#1}%
  \renewcommand*{\scrheadings@odd@middle@foot}{#2}}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\clearscrheadings}
%   \changes{v2.0j}{2001/08/18}{New}
% \begin{macro}{\clearscrheadfoot}
%   \changes{v2.0j}{2001/08/18}{New}
% \begin{macro}{\clearscrpain}
%   \changes{v2.0j}{2001/08/18}{New}
% Maybe you want to clear the currently defined head and foot. First
% let's clear only scrheadings pagestyle but not scrplain pagestyle.
% We do this simply using the already known command:
%    \begin{macrocode}
\newcommand*{\clearscrheadings}{%
  \ihead{}\chead{}\ohead{}\ifoot{}\cfoot{}\ofoot{}}
%    \end{macrocode}
% We can do almost the same to clear scrheadings pagestyle and
% scrplain pagestyle together:
%    \begin{macrocode}
\newcommand*{\clearscrheadfoot}{%
  \ihead[]{}\chead[]{}\ohead[]{}\ifoot[]{}\cfoot[]{}\ofoot[]{}}
%    \end{macrocode}
% But, for only clearing the scrplain pagestyle, we have to do the
% redefinition directly:
%    \begin{macrocode}
\newcommand*{\clearscrplain}{%
  \renewcommand*{\scrplain@even@left@head}{}%
  \renewcommand*{\scrplain@even@middle@head}{}%
  \renewcommand*{\scrplain@even@right@head}{}%
  \renewcommand*{\scrplain@odd@left@head}{}%
  \renewcommand*{\scrplain@odd@middle@head}{}%
  \renewcommand*{\scrplain@odd@right@head}{}%
  \renewcommand*{\scrplain@even@left@foot}{}%
  \renewcommand*{\scrplain@even@middle@foot}{}%
  \renewcommand*{\scrplain@even@right@foot}{}%
  \renewcommand*{\scrplain@odd@left@foot}{}%
  \renewcommand*{\scrplain@odd@middle@foot}{}%
  \renewcommand*{\scrplain@odd@right@foot}{}%
}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
%
%
% Let's do the default setting:
% \changes{v2.0m}{2002/02/05}{Active support for new letter class
%   \texttt{scrlttr2}}
% \changes{v3.12}{2013/12/14}{fix \cs{rohead} if page number left at head}
%    \begin{macrocode}
\def\@tempa{koma}\ifx\scrheadings@style\@tempa
  \@ifclassloaded{scrlttr2}{%
    \ifcase\@pageat
      \lehead[\pagemark]{\pagemark}\lohead[\pagemark]{\pagemark}%
      \chead{\rightmark}%
      \rehead{\leftmark}\rohead{\leftmark}%
    \or
      \lehead{\leftmark}\lohead{\leftmark}%
      \chead[\pagemark]{\pagemark}%
      \rehead{\rightmark}\rohead{\rightmark}%
    \or
      \lehead{\leftmark}\lohead{\leftmark}%
      \chead{\rightmark}%
      \rehead[\pagemark]{\pagemark}\rohead[\pagemark]{\pagemark}%
    \or
      \lehead{\leftmark}\lohead{\leftmark}%
      \rehead{\rightmark}\rohead{\rightmark}%
      \lefoot[\pagemark]{\pagemark}\lofoot[\pagemark]{\pagemark}%
    \or
      \lehead{\leftmark}\lohead{\leftmark}%
      \rehead{\rightmark}\rohead{\rightmark}%
      \cfoot[\pagemark]{\pagemark}%
    \or
      \lehead{\leftmark}\lohead{\leftmark}%
      \rehead{\rightmark}\rohead{\rightmark}%
      \refoot[\pagemark]{\pagemark}\rofoot[\pagemark]{\pagemark}%
    \fi
    \let\ps@save@myheadings=\ps@save@headings
    }{%
    \ohead{\if@twoside\headmark\fi}%
    \chead{\if@twoside\else\headmark\fi}%
    \cfoot[\if@twoside\else\pagemark\fi]{\if@twoside\else\pagemark\fi}%
    \ofoot[\if@twoside\pagemark\fi]{\if@twoside\pagemark\fi}%
    }%
\else\def\@tempa{standard}\ifx\scrheadings@style\@tempa
    \ihead{\headmark}
    \ohead{\pagemark}
    \cfoot[\pagemark]{}
  \else\PackageErrorNoLine{scrpage2}{unknown scrheadings style}%
                          {Somehow \string\scrheadings@style was
                            defined\MessageBreak
                            as ``\scrheadings@style''.\MessageBreak
                            scrpage2 doesn't know what to do.
                            If you'll continue, pagestyle
                            ``scrheadings''\MessageBreak 
                            will be predefined empty}
\fi\fi
\begingroup\expandafter\expandafter\expandafter\endgroup\expandafter
\ifx\csname chaptermark\endcsname\relax
  \begingroup\expandafter\expandafter\expandafter\endgroup\expandafter
  \ifx\csname sectionmark\endcsname\relax
    \ifx\@mkboth\markboth\@automarktrue\fi
  \else
%    \end{macrocode}
% \changes{v2.5a}{2012/11/02}{\cs{@gobble} is long, but \cs{sectionmark} and
%   \cs{chaptermark} may be short}
%    \begin{macrocode}
    \ifx\sectionmark\@gobble\else
      \begingroup
        \def\@gobble#1{}\ifx\sectionmark\@gobble\else
          \aftergroup\@automarktrue
        \fi
      \endgroup
    \fi
  \fi
\else
  \ifx\chaptermark\@gobble\else
    \begingroup
      \def\@gobble#1{}\ifx\chaptermark\@gobble\else
        \aftergroup\@automarktrue
      \fi
    \endgroup
  \fi
\fi
%    \end{macrocode}
%
%
% \subsection{Configurationfile}
% Not last and not least we include the local configuration-file
% \texttt{scrpage.cfg}, if it exists.
%    \begin{macrocode}
\InputIfFileExists{scrpage.cfg}
           {\typeout{*************************************^^J%
                     * Local config file scrpage.cfg used^^J%
                     *************************************}}
           {}
%    \end{macrocode}
%
%
% \subsection{Some checks}
% \changes{v2.0}{2001/04/20}{\cs{headheight}-check}
% Last but not least we do some checks at version 2. Some means one at
% the moment. And the one is a check, if the \cs{headheight} should be
% increased.
%    \begin{macrocode}
\AtBeginDocument{%
  \ifdim\headheight=12pt
    \PackageWarningNoLine{scrpage2}%
      {seems you are using a constant headheight.\MessageBreak
       If you get overfull \string\vbox\space warnings at almost every%
       \MessageBreak
       page, you should increase headheight e.g. writing\MessageBreak
       \space\string\setlength{\string\headheight}{%
       1.1\string\baselineskip}\MessageBreak
       into the preamble of your document.\MessageBreak
       A better solution would be to use typearea package}%
  \else\ifdim\headheight<1.07\baselineskip
    \PackageWarningNoLine{scrpage2}%
      {seems you are using a very small headheight.\MessageBreak
       If you get overfull \string\vbox\space warnings at almost every%
       \MessageBreak
       page, you should increase headheight e.g. writing\MessageBreak
       \space\string\setlength{\string\headheight}{%
       1.1\string\baselineskip}\MessageBreak
       into the preamble of your document.\MessageBreak
       A better solution would be to use typearea package}%
  \fi\fi}
%    \end{macrocode}
%
% \subsection{End}
%    \begin{macrocode}
%</scrpage>
%    \end{macrocode}
%
% \Finale
%
\endinput
%
% end of file `scrpage.dtx'
%%% Local Variables:
%%% mode: doctex
%%% TeX-master: t
%%% End:
