%%
%% This is file `kvoptions.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% kvoptions.dtx  (with options: `package')
%% 
%% This is a generated file.
%% 
%% Copyright (C) 2004, 2006, 2007 by
%%    Heiko Oberdiek <oberdiek@uni-freiburg.de>
%% 
%% This work may be distributed and/or modified under the
%% conditions of the LaTeX Project Public License, either
%% version 1.3 of this license or (at your option) any later
%% version. The latest version of this license is in
%%    http://www.latex-project.org/lppl.txt
%% and version 1.3 or later is part of all distributions of
%% LaTeX version 2005/12/01 or later.
%% 
%% This work has the LPPL maintenance status "maintained".
%% 
%% This Current Maintainer of this work is Heiko Oberdiek.
%% 
%% This work consists of the main source file kvoptions.dtx
%% and the derived files
%%    kvoptions.sty, kvoptions.pdf, kvoptions.ins, kvoptions.drv,
%%    example-mycolorsetup.sty.
%% 
%% No we don't need the option 'color'.
%% With color support option 'emphcolor' will dynamically change
%% the color of \emph statements.
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{kvoptions}
  [2007/06/11 v2.7 Connects package keyval with LaTeX options (HO)]%
\RequirePackage{keyval}
\begingroup
  \edef\x{\endgroup
    \noexpand\AtEndOfPackage{%
      \catcode\@ne=\the\catcode\@ne\relax
      \catcode\tw@=\the\catcode\tw@\relax
    }%
  }%
\x
\catcode\@ne=14 %
\catcode\tw@=14 %
\DeclareOption{debugshow}{\catcode\@ne=9 }
\DeclareOption{patch}{\catcode\tw@=9 }
\ProcessOptions\relax
\define@key{KVO}{family}{%
  \expandafter\edef\csname KVO@family@\@currname.\@currext\endcsname{#1}%
}
\def\KVO@family{%
  \@ifundefined{KVO@family@\@currname.\@currext}{%
    \@currname
  }{%
    \csname KVO@family@\@currname.\@currext\endcsname
  }%
}
\define@key{KVO}{prefix}{%
  \expandafter\edef\csname KVO@prefix@\@currname.\@currext\endcsname{#1}%
}
\def\KVO@prefix{%
  \@ifundefined{KVO@prefix@\@currname.\@currext}{%
    \@currname @%
  }{%
    \csname KVO@prefix@\@currname.\@currext\endcsname
  }%
}
\newcommand*{\SetupKeyvalOptions}{%
  \setkeys{KVO}%
}
\newcommand*{\DeclareBoolOption}[2][false]{%
  \KVO@ifdefinable{if\KVO@prefix#2}{%
    \KVO@ifdefinable{\KVO@prefix#2true}{%
      \KVO@ifdefinable{\KVO@prefix#2false}{%
        \expandafter\newif\csname if\KVO@prefix#2\endcsname
        \@ifundefined{\KVO@prefix#2#1}{%
          \PackageWarning{kvoptions}{%
            Initialization of option `#2' failed,\MessageBreak
            cannot set boolean option to `#1',\MessageBreak
            use `true' or `false', now using `false'%
          }%
        }{%
          \csname\KVO@prefix#2#1\endcsname
        }%
        \begingroup
          \edef\x{\endgroup
            \noexpand\define@key{\KVO@family}{#2}[true]{%
              \noexpand\KVO@boolkey{\@currname}%
              \ifx\@currext\@clsextension
                \noexpand\@clsextension
              \else
                \noexpand\@pkgextension
              \fi
              {\KVO@prefix}{#2}{####1}%
            }%
          }%
        \x
      }%
    }%
  }%
}
\newcommand*{\DeclareComplementaryOption}[2]{%
  \@ifundefined{if\KVO@prefix#2}{%
    \PackageError{kvoptions}{%
      Cannot generate option code for `#1',\MessageBreak
      parent switch `#2' does not exist%
    }{%
      You are inside %
      \ifx\@currext\@clsextension class\else package\fi\space
      `\@currname.\@currext'.\MessageBreak
      `\KVO@family' is used as familiy for the keyval options.\MessageBreak
      `\KVO@prefix' serves as prefix for internal switch macros.\MessageBreak
      \MessageBreak
      \@ehc
    }%
  }{%
    \KVO@ifdefinable{\KVO@prefix#1true}{%
      \KVO@ifdefinable{\KVO@prefix#1false}{%
        \expandafter\let\csname\KVO@prefix#1false\expandafter\endcsname
          \csname\KVO@prefix#2true\endcsname
        \expandafter\let\csname\KVO@prefix#1true\expandafter\endcsname
          \csname\KVO@prefix#2false\endcsname
        \begingroup
          \edef\x{\endgroup
            \noexpand\define@key{\KVO@family}{#1}[true]{%
              \noexpand\KVO@boolkey{\@currname}%
              \ifx\@currext\@clsextension
                \noexpand\@clsextension
              \else
                \noexpand\@pkgextension
              \fi
              {\KVO@prefix}{#1}{####1}%
            }%
          }%
        \x
      }%
    }%
  }%
}
\def\KVO@ifdefinable#1{%
  \expandafter\@ifdefinable\csname #1\endcsname
}
\def\KVO@boolkey#1#2#3#4#5{%
  \edef\KVO@param{#5}%
  \@onelevel@sanitize\KVO@param
  \ifx\KVO@param\KVO@true
    \expandafter\@firstofone
  \else
    \ifx\KVO@param\KVO@false
      \expandafter\expandafter\expandafter\@firstofone
    \else
      \ifx#2\@clsextension
        \expandafter\ClassWarning
      \else
        \expandafter\PackageWarning
      \fi
      {#1}{%
        Value `\KVO@param' is not supported by\MessageBreak
        option `#4'%
      }%
      \expandafter\expandafter\expandafter\@gobble
    \fi
  \fi
  {%
    ^^A\ifx#2\@clsextension
    ^^A  \expandafter\ClassInfo
    ^^A\else
    ^^A  \expandafter\PackageInfo
    ^^A\fi
    ^^A{#1}{[option] #4=\KVO@param}%
    \csname#3#4\KVO@param\endcsname
  }%
}
\def\KVO@true{true}
\def\KVO@false{false}
\@onelevel@sanitize\KVO@true
\@onelevel@sanitize\KVO@false
\newcommand*{\DeclareStringOption}[2][]{%
  \@ifnextchar[{%
    \KVO@DeclareStringOption{#1}{#2}@%
  }{%
    \KVO@DeclareStringOption{#1}{#2}{}[]%
  }%
}
\def\KVO@DeclareStringOption#1#2#3[#4]{%
  \KVO@ifdefinable{\KVO@prefix#2}{%
    \@namedef{\KVO@prefix#2}{#1}%
    \begingroup
      \ifx\\#3\\%
        \toks@{}%
      \else
        \toks@{[{#4}]}%
      \fi
      \edef\x{\endgroup
        \noexpand\define@key{\KVO@family}{#2}\the\toks@{%
          ^^A\begingroup
          ^^A  \toks@{####1}%
          ^^A  \ifx\@currext\@clsextension
          ^^A    \noexpand\ClassInfo
          ^^A  \else
          ^^A    \noexpand\PackageInfo
          ^^A  \fi
          ^^A  {\@currname}{%
          ^^A    [option] #2={\noexpand\the\toks@}%
          ^^A  }%
          ^^A\endgroup
          \noexpand\def
          \expandafter\noexpand\csname\KVO@prefix#2\endcsname{####1}%
        }%
      }%
    \x
  }%
}
\newcommand*{\DeclareVoidOption}[1]{%
  \begingroup
    \let\next\@gobbletwo
    \KVO@ifdefinable{\KVO@prefix#1}{%
      \let\next\@firstofone
    }%
  \expandafter\endgroup
  \next{%
    \begingroup
      \edef\x{\endgroup
        \noexpand\define@key{\KVO@family}{#1}[\KVO@VOID@]{%
          \noexpand\KVO@voidkey{\@currname}%
          \ifx\@currext\@clsextension
            \noexpand\@clsextension
          \else
            \noexpand\@pkgextension
          \fi
          {#1}%
          {####1}%
          \expandafter\noexpand\csname\KVO@prefix#1\endcsname
        }%
      }%
    \x
    \@namedef{\KVO@prefix#1}%
  }%
}
\def\KVO@VOID@{@VOID@}
\def\KVO@voidkey#1#2#3#4{%
  \def\CurrentOption{#3}%
  \begingroup
    \def\x{#4}%
  \expandafter\endgroup
  \ifx\x\KVO@VOID@
  \else
    \ifx#2\@clsextension
      \expandafter\ClassWarning
    \else
      \expandafter\PackageWarning
    \fi
    {#1}{%
      Unexpected value for option `#3'\MessageBreak
      is ignored%
    }%
  \fi
  ^^A\ifx#2\@clsextension
  ^^A  \expandafter\ClassInfo
  ^^A\else
  ^^A  \expandafter\PackageInfo
  ^^A\fi
  ^^A{#1}{[option] #3}%
}
\newcommand*{\DeclareDefaultOption}{%
  \@namedef{KVO@default@\@currname.\@currext}%
}
\SetupKeyvalOptions{%
  family=KVOdyn,%
  prefix=KVOdyn@%
}
\DeclareBoolOption[true]{global}
\DeclareComplementaryOption{local}{global}
\DeclareStringOption[undef]{action}
\let\KVOdyn@name\relax
\let\KVOdyn@ext\@empty
\define@key{KVOdyn}{class}{%
  \def\KVOdyn@name{#1}%
  \let\KVOdyn@ext\@clsextension
}
\define@key{KVOdyn}{package}{%
  \def\KVOdyn@name{#1}%
  \let\KVOdyn@ext\@pkgextension
}
\newcommand*{\DisableKeyvalOption}[3][]{%
  \begingroup
    \setkeys{KVOdyn}{#1}%
    \def\x{\endgroup}%
    \@ifundefined{KVO@action@\KVOdyn@action}{%
      \PackageError{kvoptions}{%
        Unknown disable action %
        `\expandafter\strip@prefix\meaning\KVOdyn@action'\MessageBreak
        for option `#3' in keyval family '#2'%
      }\@ehc
    }{%
      \csname KVO@action@\KVOdyn@action\endcsname{#2}{#3}%
    }%
  \x
}
\def\KVO@action@undef#1#2{%
  \edef\x{\endgroup
    \ifKVOdyn@global\global\fi
    \let
    \expandafter\noexpand\csname KV@#1@#2\endcsname
    \relax
    \ifKVOdyn@global\global\fi
    \let
    \expandafter\noexpand\csname KV@#1@#2@default\endcsname
    \relax
  }%
  ^^A\PackageInfo{kvoptions}{%
  ^^A  [option] key `#2' of family `#1'\MessageBreak
  ^^A  is disabled (undef, \ifKVOdyn@global global\else local\fi)%
  ^^A}%
}
\def\KVO@action@ignore#1#2{%
  \edef\x{\endgroup
    \ifKVOdyn@global\global\fi
    \let
    \expandafter\noexpand\csname KV@#1@#2\endcsname
    \@gobble
    \ifKVOdyn@global\global\fi
    \let
    \expandafter\noexpand\csname KV@#1@#2@default\endcsname
    \@empty
  }%
  ^^A\PackageInfo{kvoptions}{%
  ^^A  [option] key `#2' of family `#1'\MessageBreak
  ^^A  is disabled (ignore, \ifKVOdyn@global global\else local\fi)%
  ^^A}%
}
\def\KVO@action@error{%
  \KVO@do@action{error}%
}
\def\KVO@action@warning{%
  \KVO@do@action{warning}%
}
\def\KVO@do@action#1#2#3{%
  \ifx\KVOdyn@name\relax
    \PackageError{kvoptions}{%
      Action type `#1' needs package/class name\MessageBreak
      for key `#3' in family `#2'%
    }\@ehc
  \else
    \edef\x{\endgroup
      \noexpand\define@key{#2}{#3}[]{%
        \expandafter\noexpand\csname KVO@disable@#1\endcsname
        {\KVOdyn@name}\noexpand\KVOdyn@ext{#3}%
      }%
      \ifKVOdyn@global
        \global\let
        \expandafter\noexpand\csname KV@#2@#3\endcsname
        \expandafter\noexpand\csname KV@#2@#3\endcsname
        \global\let
        \expandafter\noexpand\csname KV@#2@#3@default\endcsname
        \expandafter\noexpand\csname KV@#2@#3@default\endcsname
      \fi
    }%
    ^^A\ifx\KVOdyn@ext\@clsextension
    ^^A  \expandafter\ClassInfo
    ^^A\else
    ^^A   \expandafter\PackageInfo
    ^^A\fi
    ^^A{\KVOdyn@name}{%
    ^^A  [option] key `#3' of family `#2'\MessageBreak
    ^^A  is disabled (#1, \ifKVOdyn@global global\else local\fi)%
    ^^A}%
  \fi
}
\def\KVO@disable@error#1#2#3{%
  \ifx#2\@clsextension
    \expandafter\ClassError
  \else
    \expandafter\PackageError
  \fi
  {#1}{%
    Option `#3' is given too late,\MessageBreak
    now the option is ignored%
  }\@ehc
}
\def\KVO@disable@warning#1#2#3{%
  \ifx#2\@clsextension
    \expandafter\ClassWarning
  \else
    \expandafter\PackageWarning
  \fi
  {#1}{%
    Option `#3' is already consumed\MessageBreak
    and has no effect%
  }%
}
\newcommand*{\ProcessKeyvalOptions}{%
  \@ifstar{%
    \begingroup
      \edef\x{\endgroup
        \noexpand\KVO@ProcessKeyvalOptions{\KVO@family}%
      }%
    \x
  }%
  \KVO@ProcessKeyvalOptions
}
\def\KVO@ProcessKeyvalOptions#1{%
  \let\@tempc\relax
  \let\KVO@temp\@empty
  \ifx\@currext\@clsextension
  \else
    \ifx\@classoptionslist\relax
    \else
      \@for\KVO@CurrentOption:=\@classoptionslist\do{%
        \@ifundefined{KV@#1@\expandafter\KVO@getkey\KVO@CurrentOption=\@nil}{%
        }{%
          \edef\KVO@temp{%
^^B         \etex@unexpanded\expandafter{%
              \KVO@temp
^^B         }%
            ,%
^^B         \etex@unexpanded\expandafter{%
              \KVO@CurrentOption
^^B         }%
            ,%
          }%
^^B       \@onelevel@sanitize\KVO@CurrentOption
          \@expandtwoargs\@removeelement\KVO@CurrentOption
            \@unusedoptionlist\@unusedoptionlist
        }%
      }%
    \fi
  \fi
  \begingroup
    \toks\tw@{}%
    \@ifundefined{opt@\@currname.\@currext}{%
      \toks@\expandafter{\KVO@temp}%
    }{%
      \toks@\expandafter\expandafter\expandafter{%
        \csname opt@\@currname.\@currext\endcsname
      }%
      \ifx\@currext\@clsextension
        \edef\CurrentOption{\the\toks@}%
        \toks@\expandafter{\KVO@temp}%
        \@for\CurrentOption:=\CurrentOption\do{%
          \@ifundefined{%
            KV@#1@\expandafter\KVO@getkey\CurrentOption=\@nil
          }{%
^^B         \@onelevel@sanitize\CurrentOption
            \ifx\@unusedoptionlist\@empty
              \global\let\@unusedoptionlist\CurrentOption
            \else
              \expandafter\expandafter\expandafter\gdef
              \expandafter\expandafter\expandafter\@unusedoptionlist
              \expandafter\expandafter\expandafter{%
                \expandafter\@unusedoptionlist
                \expandafter,\CurrentOption
              }%
            \fi
          }{%
            \toks@\expandafter{%
              \the\expandafter\toks@\expandafter,\CurrentOption
            }%
          }%
        }%
      \else
        \@ifundefined{KVO@default@\@currname.\@currext}{%
          \toks@\expandafter\expandafter\expandafter{%
            \expandafter\KVO@temp\the\toks@
          }%
        }{%
          \edef\CurrentOption{\the\toks@}%
          \toks@\expandafter{\KVO@temp}%
          \@for\CurrentOption:=\CurrentOption\do{%
            \@ifundefined{%
              KV@#1@\expandafter\KVO@getkey\CurrentOption=\@nil
            }{%
              \toks\tw@\expandafter{%
                \the\toks\expandafter\tw@\expandafter,\CurrentOption
              }%
            }{%
              \toks@\expandafter{%
                \the\expandafter\toks@\expandafter,\CurrentOption
              }%
            }%
          }%
        }%
      \fi
    }%
    \edef\KVO@temp{\endgroup
      \noexpand\KVO@calldefault{\the\toks\tw@}%
      \noexpand\setkeys{#1}{\the\toks@}%
    }%
  \KVO@temp
  \let\CurrentOption\@empty
  \AtEndOfPackage{\let\@unprocessedoptions\relax}%
}
\def\KVO@getkey#1=#2\@nil{#1}
\def\KVO@calldefault#1{%
  \begingroup
    \def\x{#1}%
  \expandafter\endgroup
  \ifx\x\@empty
  \else
    \@for\CurrentOption:=#1\do{%
      \ifx\CurrentOption\@empty
      \else
        \expandafter\KVO@setcurrents\CurrentOption=\@nil
        \@nameuse{KVO@default@\@currname.\@currext}%
      \fi
    }%
  \fi
}
\def\KVO@setcurrents#1=#2\@nil{
  \def\CurrentOptionValue{#2}%
  \ifx\CurrentOptionValue\@empty
    \let\CurrentOptionKey\CurrentOption
    \let\CurrentOptionValue\relax
  \else
    \edef\CurrentOptionKey{\zap@space#1 \@empty}%
    \expandafter\KVO@setcurrentvalue\CurrentOption\@nil
  \fi
}
\def\KVO@setcurrentvalue#1=#2\@nil{%
  \KV@@sp@def\CurrentOptionValue{#2}%
}
^^B\@gobble
           \endinput
\PackageInfo{kvoptions}{Patching LaTeX's option system}
\begingroup\expandafter\expandafter\expandafter\endgroup
\expandafter\ifx\csname eTeXversion\endcsname\relax
  \PackageWarningNoLine{kvoptions}{%
    Option `patch' ignored, because e-TeX is missing%
  }%
  \expandafter\endinput
\fi
\RequirePackage{etexcmds}
\ifetex@unexpanded
\else
  \PackageError{kvoptions}{%
    Could not find eTeX's \string\unexpanded.\MessageBreak
    Try adding \string\RequirePackage\string{etexcmds\string} %
    before \string\documentclass%
  }\@ehd
  \expandafter\endinput
\fi
\@ifpackageloaded{xkvltxp}{%
  \PackageWarningNoLine{kvoptions}{%
    Option `patch' cannot be used together with\MessageBreak
    package `xkvltxp' that is already loaded.\MessageBreak
    Therefore option `patch' will be ignored%
  }%
  \endinput
}{}
\def\@if@ptions#1#2#3{%
  \begingroup
    \KVO@normalize\KVO@temp{#3}%
    \edef\x{\endgroup
      \noexpand\@if@pti@ns{%
        \detokenize\expandafter\expandafter\expandafter{%
          \csname opt@#2.#1\endcsname
        }%
      }{%
        \detokenize\expandafter{\KVO@temp}%
      }%
    }%
  \x
}
\def\@pass@ptions#1#2#3{%
  \KVO@normalize\KVO@temp{#2}%
  \@ifundefined{opt@#3.#1}{%
    \expandafter\gdef\csname opt@#3.#1%
          \expandafter\endcsname\expandafter{%
      \KVO@temp
    }%
  }{%
    \expandafter\gdef\csname opt@#3.#1%
          \expandafter\expandafter\expandafter\endcsname
          \expandafter\expandafter\expandafter{%
      \csname opt@#3.#1\expandafter\endcsname\expandafter,\KVO@temp
    }%
  }%
}
\def\ProcessOptions{%
  \let\ds@\@empty
  \@ifundefined{opt@\@currname.\@currext}{%
    \let\@curroptions\@empty
  }{%
    \expandafter\expandafter\expandafter\def
    \expandafter\expandafter\expandafter\@curroptions
    \expandafter\expandafter\expandafter{%
      \csname opt@\@currname.\@currext\endcsname
    }%
  }%
  \@ifstar\KVO@xprocess@ptions\KVO@process@ptions
}
\def\KVO@process@ptions{%
  \@for\CurrentOption:=\@declaredoptions\do{%
    \ifx\CurrentOption\@empty
    \else
      \begingroup
        \ifx\@currext\@clsextension
          \toks@{}%
        \else
          \toks@\expandafter{\@classoptionslist,}%
        \fi
        \toks\tw@\expandafter{\@curroptions}%
        \edef\x{\endgroup
          \noexpand\in@{,\CurrentOption,}{,\the\toks@\the\toks\tw@,}%
        }%
      \x
      \ifin@
        \KVO@use@ption
        \expandafter\let\csname ds@\CurrentOption\endcsname\@empty
      \fi
    \fi
  }%
  \KVO@process@pti@ns
}
\def\KVO@xprocess@ptions{%
  \ifx\@currext\@clsextension
  \else
    \@for\CurrentOption:=\@classoptionslist\do{%
      \ifx\CurrentOption\@empty
      \else
        \KVO@in@\CurrentOption\@declaredoptions
        \ifin@
          \KVO@use@ption
          \expandafter\let\csname ds@\CurrentOption\endcsname\@empty
        \fi
      \fi
    }%
  \fi
  \KVO@process@pti@ns
}
\def\KVO@in@#1#2{%
  \in@false
  \begingroup
    \@for\x:=#2\do{%
      \ifx\x#1\relax
        \in@true
      \fi
    }%
    \edef\x{\endgroup
      \ifin@
        \noexpand\in@true
      \fi
    }%
  \x
}
\def\KVO@process@pti@ns{%
  \@for\CurrentOption:=\@curroptions\do{%
    \@ifundefined{ds@\KVO@SanitizedCurrentOption}{%
      \KVO@use@ption
      \default@ds
    }%
    \KVO@use@ption
  }%
  \@for\CurrentOption:=\@declaredoptions\do{%
    \expandafter\let\csname ds@\CurrentOption\endcsname\relax
  }%
  \let\CurrentOption\@empty
  \let\@fileswith@pti@ns\@@fileswith@pti@ns
  \AtEndOfPackage{\let\@unprocessedoptions\relax}%
}
\def\KVO@use@ption{%
  \begingroup
    \edef\x{\endgroup
      \noexpand\@removeelement{%
        \detokenize\expandafter{\CurrentOption}%
      }{%
        \detokenize\expandafter{\@unusedoptionlist}%
      }%
    }%
  \x\@unusedoptionlist
  \csname ds@\KVO@SanitizedCurrentOption\endcsname
}
\def\OptionNotUsed{%
  \ifx\@currext\@clsextension
    \xdef\@unusedoptionlist{%
      \ifx\@unusedoptionlist\@empty
      \else
        \detokenize\expandafter{\@unusedoptionlist,}%
      \fi
      \detokenize\expandafter{\CurrentOption}%
    }%
  \fi
}
\def\CurrentOption@SaveLevel{0}
\def\ExecuteOptions{%
  \expandafter\KVO@ExecuteOptions
      \csname CurrentOption@\CurrentOption@SaveLevel\endcsname
}
\def\KVO@ExecuteOptions#1#2{%
  \let#1\CurrentOption
  \edef\CurrentOption@SaveLevel{\the\numexpr\CurrentOption@SaveLevel+1}%
  \@for\CurrentOption:=#2\do{%
    \csname ds@\CurrentOption\endcsname
  }%
  \edef\CurrentOption@SaveLevel{\the\numexpr\CurrentOption@SaveLevel-1}%
  \let\CurrentOption#1%
}
\def\KVO@fileswith@pti@ns#1[#2]#3[#4]{%
  \ifx#1\@clsextension
    \ifx\@classoptionslist\relax
      \KVO@normalize\KVO@temp{#2}%
      \expandafter\gdef\expandafter\@classoptionslist\expandafter{%
        \KVO@temp
      }%
      \def\reserved@a{%
        \KVO@onefilewithoptions{#3}[{#2}][{#4}]#1%
        \@documentclasshook
      }%
    \else
      \def\reserved@a{%
        \KVO@onefilewithoptions{#3}[{#2}][{#4}]#1%
      }%
    \fi
  \else
    \begingroup
      \let\KVO@temp\relax
      \let\KVO@onefilewithoptions\relax
      \let\@pkgextension\relax
      \def\reserved@b##1,{%
        \ifx\@nil##1\relax
        \else
          \ifx\relax##1\relax
          \else
            \KVO@onefilewithoptions{##1}[{\KVO@temp}][{#4}]\@pkgextension
          \fi
          \expandafter\reserved@b
        \fi
      }%
      \edef\reserved@a{\zap@space#3 \@empty}%
      \edef\reserved@a{\expandafter\reserved@b\reserved@a,\@nil,}%
      \toks@{#2}%
      \def\KVO@temp{\the\toks@}%
    \edef\reserved@a{\endgroup \reserved@a}%
  \fi
  \reserved@a
}
\def\KVO@onefilewithoptions#1[#2][#3]#4{%
  \@pushfilename
  \xdef\@currname{#1}%
  \global\let\@currext#4%
  \expandafter\let\csname\@currname.\@currext-h@@k\endcsname\@empty
  \let\CurrentOption\@empty
  \@reset@ptions
  \makeatletter
  \def\reserved@a{%
    \@ifl@aded\@currext{#1}{%
      \@if@ptions\@currext{#1}{#2}{%
      }{%
        \begingroup
          \@ifundefined{opt@#1.\@currext}{%
            \def\x{}%
          }{%
            \edef\x{%
              \expandafter\expandafter\expandafter\strip@prefix
              \expandafter\meaning\csname opt@#1.\@currext\endcsname
            }%
          }%
          \def\y{#2}%
          \edef\y{\expandafter\strip@prefix\meaning\y}%
          \@latex@error{Option clash for \@cls@pkg\space #1}{%
            The package #1 has already been loaded %
            with options:\MessageBreak
            \space\space[\x]\MessageBreak
            There has now been an attempt to load it %
             with options\MessageBreak
            \space\space[\y]\MessageBreak
            Adding the global options:\MessageBreak
            \space\space
                 \x,\y\MessageBreak
            to your \noexpand\documentclass declaration may fix this.%
            \MessageBreak
            Try typing \space <return> \space to proceed.%
          }%
        \endgroup
      }%
    }{%
      \@pass@ptions\@currext{#2}{#1}%
      \global\expandafter
      \let\csname ver@\@currname.\@currext\endcsname\@empty
      \InputIfFileExists
        {\@currname.\@currext}%
        {}%
        {\@missingfileerror\@currname\@currext}%
      \let\@unprocessedoptions\@@unprocessedoptions
      \csname\@currname.\@currext-h@@k\endcsname
      \expandafter\let\csname\@currname.\@currext-h@@k\endcsname
              \@undefined
      \@unprocessedoptions
    }%
    \@ifl@ter\@currext{#1}{#3}{%
    }{%
      \@latex@warning@no@line{%
        You have requested,\on@line, %
        version\MessageBreak
          #3' of \@cls@pkg\space #1,\MessageBreak
        but only version\MessageBreak
         `\csname ver@#1.\@currext\endcsname'\MessageBreak
        is available%
      }%
    }%
    \ifx\@currext\@clsextension\let\LoadClass\@twoloadclasserror\fi
    \@popfilename
    \@reset@ptions
  }%
  \reserved@a
}
\def\@unknownoptionerror{%
  \@latex@error{%
    Unknown option `\KVO@SanitizedCurrentOption' %
    for \@cls@pkg\space`\@currname'%
  }{%
    The option `\KVO@SanitizedCurrentOption' was not declared in %
    \@cls@pkg\space`\@currname', perhaps you\MessageBreak
    misspelled its name. %
    Try typing \space <return> %
    \space to proceed.%
  }%
}
\def\@@unprocessedoptions{%
  \ifx\@currext\@pkgextension
    \@ifundefined{opt@\@currname.\@currext}{%
      \let\@curroptions\@empty
    }{%
      \expandafter\let\expandafter\@curroptions
          \csname opt@\@currname.\@currext\endcsname
    }%
    \@for\CurrentOption:=\@curroptions\do{%
        \ifx\CurrentOption\@empty\else\@unknownoptionerror\fi
    }%
  \fi
}
\def\KVO@SanitizedCurrentOption{%
  \expandafter\strip@prefix\meaning\CurrentOption
}
\def\KVO@normalize#1#2{%
  \let\KVO@result\@empty
  \KVO@splitcomma#2,\@nil
  \let#1\KVO@result
}
\def\KVO@splitcomma#1,#2\@nil{%
  \KVO@ifempty{#1}{}{%
    \KVO@checkkv#1=\@nil
  }%
  \KVO@ifempty{#2}{}{\KVO@splitcomma#2\@nil}%
}
\def\KVO@ifempty#1{%
  \expandafter\ifx\expandafter\\\detokenize{#1}\\%
    \expandafter\@firstoftwo
  \else
    \expandafter\@secondoftwo
  \fi
}
\def\KVO@checkkv#1=#2\@nil{%
  \KVO@ifempty{#2}{%
    % option without value
    \edef\KVO@x{\zap@space#1 \@empty}%
    \ifx\KVO@x\@empty
      % ignore empty option
    \else
      % append to list
      \edef\KVO@result{%
        \etex@unexpanded\expandafter{\KVO@result},\KVO@x
      }%
    \fi
  }{%
    % #1: "key", #2: "value="
    % add key part
    \edef\KVO@result{%
      \etex@unexpanded\expandafter{\KVO@result},%
      \zap@space#1 \@empty
    }%
    \futurelet\@let@token\KVO@checkfirsttok#2 \@nil| = \@nil|\KVO@nil
  }%
}
\def\KVO@checkfirsttok{%
  \ifx\@let@token\bgroup
    % no space at start
    \expandafter\KVO@removelastspace\expandafter=%
    % "<value><spaceopt>= \@nil"
  \else
    \expandafter\KVO@checkfirstA
  \fi
}
\def\KVO@checkfirstA#1 #2\@nil{%
  \KVO@ifempty{#2}{%
    \KVO@removelastspace=#1 \@nil
  }{%
    \KVO@ifempty{#1}{%
      \KVO@removelastspace=#2\@nil
    }{%
      \KVO@removelastspace=#1 #2\@nil
    }%
  }%
}
\def\KVO@removelastspace#1 = \@nil|#2\KVO@nil{%
  \KVO@ifempty{#2}{%
    \edef\KVO@result{%
      \etex@unexpanded\expandafter{\KVO@result}%
      \etex@unexpanded\expandafter{\KVO@removegarbage#1\KVO@nil}%
    }%
  }{%
    \edef\KVO@result{%
      \etex@unexpanded\expandafter{\KVO@result}%
      \etex@unexpanded{#1}%
    }%
  }%
}
\def\KVO@removegarbage#1= \@nil#2\KVO@nil{#1}%
\def\KVO@removeelement#1#2{%
  \begingroup
    \toks@={}%
    \@for\x:=#2\do{%
      \ifx\x\@empty
      \else
        \ifx\x#1\relax
        \else
          \edef\t{\the\toks@}%
          \ifx\t\@empty
          \else
            \toks@\expandafter{\the\toks@,}%
          \fi
          \toks@\expandafter{\the\expandafter\toks@\x}%
        \fi
      \fi
    }%
    \edef\x{\endgroup
      \def\noexpand#2{\the\toks@}%
    }%
  \x
}
\let\@@fileswith@pti@ns\KVO@fileswith@pti@ns
\ifx\@fileswith@pti@ns\@badrequireerror
\else
  \let\@fileswith@pti@ns\KVO@fileswith@pti@ns
\fi
\endinput
%%
%% End of file `kvoptions.sty'.
