%%
%% This is file `scrpage2.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% scrpage.dtx  (with options: `scrpage,v2')
%% scrlogo.dtx 
%% 
%% Copyright 1994-2004 Markus Kohm.
%% 
%% All rights reserved. For further copyright information see the file
%% legal.txt, and any other copyright indicated in this file.
%% 
%% This file is part of the LaTeX2e KOMA-Script-bundle.
%% ----------------------------------------------------
%% 
%% The KOMA-Script-bundle (but not this file) bases on the
%% Script-family created by Frank Neukam 1993 and the standard
%% documents classes created by the LaTeX3-Team 1994-1996.
%% -------------------------------------------------------------
%% 
%%  This system is distributed in the hope that it will be useful,
%%  but WITHOUT ANY WARRANTY; without even the implied warranty of
%%  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
%% 
%% 
%% IMPORTANT NOTICE:
%% 
%% For error reports in case of UNCHANGED versions see documentation.
%% 
%% Please do not request updates from us directly. Distribution is
%% done through Mail-Servers, Mailboxes and TeX organizations.
%% 
%% You are not allowed to change this file.
%% 
%% You are allowed to distribute this file under the condition that
%% it is distributed together with all files mentioned in readme.txt
%% and liesmich.txt. See LEGAL.TXT or LEGALDE.TXT for further
%% information.
%% 
%% If you receive only some of these files from someone, complain!
%% 
%% You are NOT ALLOWED to distribute this file alone.
%% 
\NeedsTeXFormat{LaTeX2e}[1995/06/01]
\ProvidesPackage{scrpage2}
                [2004/09/05 v2.2a LaTeX2e KOMA
                 package]
\DeclareOption{headinclude}{\PassOptionsToPackage{headinclude}{typearea}}
\DeclareOption{headexclude}{\PassOptionsToPackage{headexclude}{typearea}}
\DeclareOption{footinclude}{\PassOptionsToPackage{footinclude}{typearea}}
\DeclareOption{footexclude}{\PassOptionsToPackage{footexclude}{typearea}}
\@ifundefined{mincltrue}{\newif\if@mincl}{}
\DeclareOption{mpinclude}{\@mincltrue}
\DeclareOption{mpexclude}{\@minclfalse}
\newcommand*{\scr@headabove@linethickness}{0pt}
\newcommand*{\scr@headbelow@linethickness}{0pt}
\newcommand*{\scr@footabove@linethickness}{0pt}
\newcommand*{\scr@footbelow@linethickness}{0pt}
\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}
\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}}
\newcommand*{\hfline@adjust}{1}
\DeclareOption{ilines}{\renewcommand*{\hfline@adjust}{0}}
\DeclareOption{clines}{\renewcommand*{\hfline@adjust}{1}}
\DeclareOption{olines}{\renewcommand*{\hfline@adjust}{2}}
\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}}
\newif\if@autooneside\@autoonesidefalse
\DeclareOption{autooneside}{\@autoonesidetrue}
\DeclareOption{markuppercase}{\let\MakeMarkcase\MakeUppercase}
\DeclareOption{markusedcase}{\let\MakeMarkcase\@empty}
\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}
\DeclareOption{komastyle}{\def\scrheadings@style{koma}
  \@ifundefined{MakeMarkcase}{\let\MakeMarkcase\relax}{}}
\DeclareOption{standardstyle}{\def\scrheadings@style{standard}
  \@ifundefined{MakeMarkcase}{\let\MakeMarkcase\MakeUppercase}{}}
\ExecuteOptions{%
}
\ProcessOptions\relax
\newif\if@chapter
\begingroup\expandafter\expandafter\expandafter\endgroup
\expandafter\ifx\csname chapter\endcsname\relax
  \@chapterfalse
\else
  \@chaptertrue
\fi
\def\@tempa{\newif\if@mainmatter\@mainmattertrue}
\begingroup\expandafter\expandafter\expandafter\endgroup
\expandafter\ifx\csname mainmatter\endcsname\relax\else\let\@tempa\relax\fi
\@tempa
\let\headmark\relax
\DeclareRobustCommand\pagemark{{\pnumfont\thepage}}
\newif\if@automark\@automarkfalse
\def\defpagestyle{%
  \@ifstar
  {\@defpagestyle[-]}%
  {\@defpagestyle[+]}}
\if@twoside
  \def\@defpagestyle[#1]#2#3#4{%
    \expandafter\def\csname ps@#2\endcsname{%
      \if@automark\let\@mkboth\markboth\else\let\@mkboth\@gobbletwo\fi
      \def@twosidehead#3
      \def@twosidefoot#4
    }
  }
\else
  \def\@defpagestyle[#1]#2#3#4{%
    \expandafter\def\csname ps@#2\endcsname{%
      \if@automark\let\@mkboth\markboth\else\let\@mkboth\@gobbletwo\fi
      \def@onesidehead#3
      \def@onesidefoot#4
    }
  }
\fi
\def\def@twosidehead{%
  \@ifnextchar(
  {\def@@twosidehead}
  {\def@@twosidehead(\scr@headabove@linelength,%
                     \scr@headabove@linethickness)}}
\def\def@@twosidehead(#1,#2)#3#4#5{%
  \@ifnextchar(
  {\def@@@twosidehead({#1},{#2}){#3}{#4}{#5}}
  {\def@@@twosidehead({#1},{#2}){#3}{#4}{#5}%
                     (\scr@headbelow@linelength,%
                      \scr@headbelow@linethickness)}}
\def\def@@@twosidehead(#1,#2)#3#4#5(#6,#7){%
  \def\@evenhead{\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}
  \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 #4}}%
      \hf@rule{#6}{#7}{\@headwidth}%
      {headbelow}%
  }\hskip\@evenheadshift\hss}
}
\def\def@onesidehead{%
  \@ifnextchar(
  {\def@@onesidehead}
  {\def@@onesidehead(\scr@headabove@linelength,%
                     \scr@headabove@linethickness)}}
\def\def@@onesidehead(#1,#2)#3#4#5{%
  \@ifnextchar(
  {\def@@@onesidehead({#1},{#2}){#3}{#4}{#5}}
  {\def@@@onesidehead({#1},{#2}){#3}{#4}{#5}%
                     (\scr@headbelow@linelength,%
                      \scr@headbelow@linethickness)}}
\def\def@@@onesidehead(#1,#2)#3#4#5(#6,#7){%
  \def\@evenhead{}
  \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 #5}}
      \hf@rule{#6}{#7}{\@headwidth}%
      {headbelow}%
  }\hskip\@evenheadshift\hss}
}
\def\def@twosidefoot{%
  \@ifnextchar(
  {\def@@twosidefoot}
  {\def@@twosidefoot(\scr@footabove@linelength,%
                     \scr@footabove@linethickness)}}
\def\def@@twosidefoot(#1,#2)#3#4#5{%
  \@ifnextchar(
  {\def@@@twosidefoot({#1},{#2}){#3}{#4}{#5}}
  {\def@@@twosidefoot({#1},{#2}){#3}{#4}{#5}%
                     (\scr@footbelow@linelength,%
                      \scr@footbelow@linethickness)}}
\def\def@@@twosidefoot(#1,#2)#3#4#5(#6,#7){%
  \def\@evenfoot{\let\headmark\leftmark%
    \hss\hskip\@evenfootshift\vbox{\hsize=\@footwidth\relax%
      \topfoot@rule{#1}{#2}\hb@xt@\@footwidth{{%
          \scr@nouppercase%
          \headfont\strut #3}}%
      \botfoot@rule{#6}{#7}}\hskip\@oddfootshift\hss}
  \def\@oddfoot{\let\headmark\rightmark%
    \hss\hskip\@oddfootshift\vbox{\hsize=\@footwidth\relax%
      \topfoot@rule{#1}{#2}\hb@xt@\@footwidth{{%
          \scr@nouppercase%
          \headfont\strut #4}}%
      \botfoot@rule{#6}{#7}}\hskip\@evenfootshift\hss}
}
\def\def@onesidefoot{%
  \@ifnextchar(
  {\def@@onesidefoot}
  {\def@@onesidefoot(\scr@footabove@linelength,%
                     \scr@footabove@linethickness)}}
\def\def@@onesidefoot(#1,#2)#3#4#5{%
  \@ifnextchar(
  {\def@@@onesidefoot({#1},{#2}){#3}{#4}{#5}}
  {\def@@@onesidefoot({#1},{#2}){#3}{#4}{#5}%
                     (\scr@footbelow@linelength,%
                      \scr@footbelow@linethickness)}}
\def\def@@@onesidefoot(#1,#2)#3#4#5(#6,#7){%
  \def\@evenfoot{}
  \def\@oddfoot{\let\headmark\rightmark%
    \hss\hskip\@oddfootshift\vbox{\hsize=\@footwidth\relax%
      \topfoot@rule{#1}{#2}\hb@xt@\@footwidth{{%
          \scr@nouppercase%
          \headfont\strut #5}}
      \botfoot@rule{#6}{#7}}\hskip\@evenfootshift\hss}
}
\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}
\newcommand\botfoot@rule[2]{%
  \@tempdima-\baselineskip\advance\@tempdima by .3\normalbaselineskip
  \advance\@tempdima by #2
  \vskip\@tempdima\hf@rule{#1}{#2}{\@footwidth}%
      {footbelow}%
}
\newcommand*{\hf@rule}[4]{%
  \setlength{\@tempdimb}{#1}
  \begingroup
    \csname scr@pre@#4@line\endcsname
    \ifodd\c@page
      \edef\@tempa{\hfline@adjust}
    \else
      \@tempcnta=2\advance\@tempcnta -\hfline@adjust
      \edef\@tempa{\the\@tempcnta}
    \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
}
\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}
\def\newpagestyle{%
  \@ifstar
  {\@newpagestyle[-]}%
  {\@newpagestyle[+]}}
\def\@newpagestyle[#1]#2#3#4{
  \expandafter\ifx\csname ps@#2\endcsname\relax
    \@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
}
\def\renewpagestyle{%
  \@ifstar
  {\@renewpagestyle[-]}%
  {\@renewpagestyle[+]}}
\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
    \@defpagestyle[#1]{#2}{#3}{#4}
  \fi
}
\def\providepagestyle{%
  \@ifstar
  {\@providepagestyle[-]}%
  {\@providepagestyle[+]}}
\def\@providepagestyle[#1]#2#3#4{
  \expandafter\ifx\csname ps@#2\endcsname\relax
    \@defpagestyle[#1]{#2}{#3}{#4}
  \else
    \PackageInfo
      {scrpage2}
      {\protect\providepagestyle\protect{#1\protect} ignored.}
  \fi
}
\def\deftripstyle{%
  \@ifstar
  {\@deftripstyle[-]}%
  {\@deftripstyle[+]}}
\def\@deftripstyle[#1]#2{%
  \@ifnextchar[
  {\@@deftripstyle[#1]{#2}}%
  {\@@deftripstyle[#1]{#2}[\z@]}}
\def\@@deftripstyle[#1]#2[#3]{
  \def\@tempa{#1}
  \@ifnextchar[
  {\@@@deftripstyle#2[#3]}%
  {\@@@deftripstyle#2[\z@][#3]}}
\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
}
\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}}}
\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
}
\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
}
\if@chapter
  \newcommand*{\partlevel}{-1}
\else
  \newcommand*{\partlevel}{0}
\fi
\newcommand*{\chapterlevel}{0}
\newcommand*{\sectionlevel}{1}
\newcommand*{\subsectionlevel}{2}
\newcommand*{\subsubsectionlevel}{3}
\newcommand*{\paragraphlevel}{4}
\newcommand*{\subparagraphlevel}{5}
\@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}}}}}{}
\@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}}}}}}{}
\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
}
\newcommand*{\@headwidth}{\textwidth}
\newcommand*{\@oddheadshift}{\z@}
\newcommand*{\@evenheadshift}{\z@}
\newcommand*{\@footwidth}{\textwidth}
\newcommand*{\@oddfootshift}{\z@}
\newcommand*{\@evenfootshift}{\z@}
\if@mincl
  \renewcommand*{\@headwidth}{}
  \renewcommand*{\@footwidth}{}
  \AtBeginDocument{%
    \ifx\@headwidth\@empty
      \setheadwidth[0pt]{textwithmarginpar}
    \fi
    \ifx\@footwidth\@empty
      \setfootwidth[0pt]{textwithmarginpar}
    \fi
    }
\fi
\providecommand\pnumfont{\normalfont}
\providecommand\headfont{\normalfont%
  \slshape%
}
\newcommand*{\setheadtopline}{\scr@setline{head}{above}}
\newcommand*{\setheadsepline}{\scr@setline{head}{below}}
\newcommand*{\setfootsepline}{\scr@setline{foot}{above}}
\newcommand*{\setfootbotline}{\scr@setline{foot}{below}}
\def\scr@setline#1#2{%
  \@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
  \@ifnextchar[%]
  {\@src@set@pre@line{#1}}{}%
}
\def\@src@set@pre@line#1[#2]{%
  \expandafter\def\csname scr@pre@#1@line\endcsname{#2}%
}
\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}}
\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
\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}
\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%
}
\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}{}
\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}{}
\newcommand{\ihead}{\@ifnextchar[{\@@lhead}{\@lhead}}
\newcommand{\@lhead}[1]{\@rehead{#1}\@lohead{#1}}
\newcommand{\@@lhead}[2][]{\@@rehead[{#1}]{#2}\@@lohead[{#1}]{#2}}
\newcommand{\ohead}{\@ifnextchar[{\@@rhead}{\@rhead}}
\newcommand{\@rhead}[1]{\@lehead{#1}\@rohead{#1}}
\newcommand{\@@rhead}[2][]{\@@lehead[{#1}]{#2}\@@rohead[{#1}]{#2}}
\newcommand{\chead}{\@ifnextchar[{\@@chead}{\@chead}}
\newcommand{\@chead}[1]{\@cehead{#1}\@cohead{#1}}
\newcommand{\@@chead}[2][]{\@@cehead[{#1}]{#2}\@@cohead[{#1}]{#2}}
\newcommand{\lehead}{\@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}{\@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}{\@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}{\@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}{\@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}{\@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}{\@ifnextchar[{\@@lfoot}{\@lfoot}}
\newcommand{\@lfoot}[1]{\@refoot{#1}\@lofoot{#1}}
\newcommand{\@@lfoot}[2][]{\@@refoot[{#1}]{#2}\@@lofoot[{#1}]{#2}}
\newcommand{\ofoot}{\@ifnextchar[{\@@rfoot}{\@rfoot}}
\newcommand{\@rfoot}[1]{\@lefoot{#1}\@rofoot{#1}}
\newcommand{\@@rfoot}[2][]{\@@lefoot[{#1}]{#2}\@@rofoot[{#1}]{#2}}
\newcommand{\cfoot}{\@ifnextchar[{\@@cfoot}{\@cfoot}}
\newcommand{\@cfoot}[1]{\@cefoot{#1}\@cofoot{#1}}
\newcommand{\@@cfoot}[2][]{\@@cefoot[{#1}]{#2}\@@cofoot[{#1}]{#2}}
\newcommand{\lefoot}{\@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}{\@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}{\@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}{\@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}{\@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}{\@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}}
\newcommand*{\clearscrheadings}{%
  \ihead{}\chead{}\ohead{}\ifoot{}\cfoot{}\ofoot{}}
\newcommand*{\clearscrheadfoot}{%
  \ihead[]{}\chead[]{}\ohead[]{}\ifoot[]{}\cfoot[]{}\ofoot[]{}}
\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}{}
}
\def\@tempa{koma}\ifx\scrheadings@style\@tempa
  \@ifclassloaded{scrlttr2}{%
    \ifcase\@pageat
      \lehead[\pagemark]{\pagemark}\lohead[\pagemark]{\pagemark}%
      \chead{\rightmark}%
      \rehead{\leftmark}\lohead{\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
    \ifx\sectionmark\@gobble\else\@automarktrue\fi
  \fi
\else
  \ifx\chaptermark\@gobble\else\@automarktrue\fi
\fi
\InputIfFileExists{scrpage.cfg}
           {\typeout{*************************************^^J%
                     * Local config file scrpage.cfg used^^J%
                     *************************************}}
           {}
\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}
\@ifundefined{KOMAScript}{%
  \DeclareRobustCommand{\KOMAScript}{\textsf{K\kern.05em O\kern.05em%
      M\kern.05em A\kern.1em-\kern.1em Script}}}{}
\endinput
%%
%% End of file `scrpage2.sty'.
