%%
%% This is file `cleveref.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% cleveref.dtx  (with options: `package')
%% 
%% LaTeX package for automatic cross-referencing text.
%% 
%% Copyright (C) 2006  Toby Cubitt
%% See the files README and COPYING.
%% 
%% This file may be distributed and/or modified under the
%% conditions of the LaTeX Project Public License, either version 1.2
%% 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.2 or later is part of all distributions of LaTeX
%% version 1999/12/01 or later.
\NeedsTeXFormat{LaTeX2e}[1999/12/01]
\ProvidesPackage{cleveref}
 [2007/11/06 v0.6 Automatic cross-reference formatting]
%% \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         \~}
\let\old@refstepcounter\refstepcounter
\def\refstepcounter%
  {\@ifnextchar[{\refstepcounter@optarg}{\refstepcounter@noarg}}%]
\def\refstepcounter@noarg#1{%
  \old@refstepcounter{#1}%
  \reset@by{#1}{\@result}%
  \ifx\@result\relax\def\@result{}%
  \else\edef\@result{\csname the\@result\endcsname}\fi%
  \protected@edef\@currentlabel{%
    [#1][\arabic{#1}][\@result]\@currentlabel}}
\def\refstepcounter@optarg[#1]#2{%
  \old@refstepcounter{#2}%
  \reset@by{#2}{\@result}%
  \ifx\@result\relax\def\@result{}%
  \else\edef\@result{\csname the\@result\endcsname}\fi%
  \protected@edef\@currentlabel{%
    [#1][\arabic{#2}][\@result]\@currentlabel}}
\def\cref@label#1#2{\@result}
\AtBeginDocument{%
  \def\ref#1{%
    \expandafter\ifx\csname r@#1\endcsname\relax%
      \let\@result\relax%
    \else%
      \cref@getlabel{#1}{\@result}%
    \fi%
  \expandafter\@setref\csname r@#1\endcsname{\cref@label}{#1}}%
}
\def\cref@getlabel#1#2{%
  \expandafter\let\expandafter\@tempa\csname r@#1\endcsname%
  \edef\@tempa{\expandafter\@firstoftwo\@tempa}%
  \expandafter\@cref@getlabel\@tempa\@nil#2}
\def\@cref@getlabel{\@ifnextchar[%]
  \@@cref@getlabel{\@@cref@getlabel[][][]}}
\def\@@cref@getlabel[#1][#2][#3]#4\@nil#5{\def#5{#4}}
\def\cref@gettype#1#2{%
  \expandafter\let\expandafter\@tempa\csname r@#1\endcsname%
  \edef\@tempa{\expandafter\@firstoftwo\@tempa}%
  \expandafter\@cref@gettype\@tempa\@nil#2}
\def\@cref@gettype{\@ifnextchar[%]
  \@@cref@gettype{\@@cref@gettype[][][]}}
\def\@@cref@gettype[#1][#2][#3]#4\@nil#5{\def#5{#1}}
\def\cref@getcounter#1#2{%
  \expandafter\let\expandafter\@tempa\csname r@#1\endcsname%
  \edef\@tempa{\expandafter\@firstoftwo\@tempa}%
  \expandafter\@cref@getcounter\@tempa\@nil#2}
\def\@cref@getcounter{\@ifnextchar[%]
  \@@cref@getcounter{\@@cref@getcounter[][][]}}
\def\@@cref@getcounter[#1][#2][#3]#4\@nil#5{\def#5{#2}}
\def\cref@getprefix#1#2{%
  \expandafter\let\expandafter\@tempa\csname r@#1\endcsname%
  \edef\@tempa{\expandafter\@firstoftwo\@tempa}%
  \expandafter\@cref@getprefix\@tempa\@nil#2}
\def\@cref@getprefix{\@ifnextchar[%]
  \@@cref@getprefix{\@@cref@getprefix[][][]}}
\def\@@cref@getprefix[#1][#2][#3]#4\@nil#5{\def#5{#3}}
\def\stack@init#1{\def#1{\@nil}}
\def\stack@top#1{\expandafter\stack@top@aux#1}
\def\stack@top@aux#1,#2\@nil{#1}
\def\stack@pop#1{\expandafter\stack@pop@aux#1#1}
\def\stack@pop@aux#1,#2\@nil#3{\def#3{#2\@nil}}
\def\stack@push#1#2{\expandafter\stack@push@aux\expandafter{#2}{#1}{#2}}
\def\stack@push@aux#1#2#3{\def#3{#2,#1}}
\def\stack@pull#1#2{\expandafter\stack@pull@aux#2{#1}{#2}}
\def\stack@pull@aux#1\@nil#2#3{\def#3{#1#2,\@nil}}
\newif\ifstackempty
\newif\ifstackfull
\def\isstackempty#1{%
  \expandafter\ifx#1\@nil\stackemptytrue%
  \else\stackemptyfalse\fi}
\def\isstackfull#1{%
  \expandafter\ifx#1\@nil\stackfullfalse%
  \else\stackfulltrue\fi}
\newif\ifinresetlist
\def\isinresetlist#1#2{%
  \def\@counter{#1}%
  \begingroup%
    \def\@elt##1{##1,}%
    \expandafter\ifx\csname cl@#2\endcsname\relax%
      \gdef\@resetstack{,\@nil}%
    \else%
      \xdef\@resetstack{\csname cl@#2\endcsname\noexpand\@nil}%
    \fi%
  \endgroup%
  \isstackfull{\@resetstack}%
  \@whilesw\ifstackfull\fi{%
    \edef\@nextcounter{\stack@top{\@resetstack}}%
    \ifx\@nextcounter\@counter%
      \stackfullfalse%
    \else%
      \let\@nextcounter\relax%
      \stack@pop{\@resetstack}%
      \isstackfull{\@resetstack}%
    \fi}%
  \ifx\@nextcounter\relax%
    \inresetlistfalse%
  \else%
    \inresetlisttrue%
  \fi}
\def\reset@by#1#2{%
  \isinresetlist{#1}{subsubsubsection}%
  \ifinresetlist%
    \def#2{subsubsubsection}%
  \else%
    \isinresetlist{#1}{subsubsection}%
    \ifinresetlist%
      \def#2{subsubsection}%
    \else%
      \isinresetlist{#1}{subsection}%
      \ifinresetlist%
        \def#2{subsection}%
      \else%
        \isinresetlist{#1}{section}%
        \ifinresetlist%
          \def#2{section}%
        \else%
          \isinresetlist{#1}{chapter}%
          \ifinresetlist%
            \def#2{chapter}%
          \else%
            \isinresetlist{#1}{part}%
            \ifinresetlist%
              \def#2{part}%
            \else%
              \let#2\relax%
            \fi%
          \fi%
        \fi%
      \fi%
    \fi%
  \fi}
\newcommand{\cref}[1]{\@cref{cref}{#1}}
\newcommand{\Cref}[1]{\@cref{Cref}{#1}}
\newcommand{\crefrange}[2]{\@setcrefrange{#1}{#2}{cref}{}}
\newcommand{\Crefrange}[2]{\@setcrefrange{#1}{#2}{Cref}{}}
\def\@cref#1#2{%
  \begingroup%
  \countdef\count@consecutive=0%
  \newif\if@firstgroup%
  \stack@init{\@refstack}%
  \stack@push{#2}{\@refstack}%
  \@firstgrouptrue%
  \isstackfull{\@refstack}%
  \@whilesw\ifstackfull\fi{%
    \stack@init{\@refsubstack}%
    \edef\@nextref{\stack@top{\@refstack}}%
    \expandafter\ifx\csname r@\@nextref\endcsname\relax%
      \def\@currenttype{\@undefined}%
    \else%
      \expandafter\cref@gettype\expandafter{\@nextref}{\@currenttype}%
    \fi%
    \let\@nexttype\@currenttype%
    \@whilesw\ifx\@nexttype\@currenttype\fi{%
      \expandafter\stack@pull\expandafter{\@nextref}{\@refsubstack}%
      \stack@pop{\@refstack}%
      \isstackempty{\@refstack}%
      \ifstackempty%
        \def\@nexttype{\relax}%
      \else%
        \edef\@nextref{\stack@top{\@refstack}}%
        \expandafter\ifx\csname r@\@nextref\endcsname\relax%
          \def\@currenttype{\@undefined}%
        \else%
          \expandafter\cref@gettype\expandafter%
            {\@nextref}{\@currenttype}%
        \fi%
      \fi}%
    \if@firstgroup%
    \else%
      \isstackfull{\@refstack}%
      \ifstackfull%
        \@setcref@middleconjunction%
      \else%
        \@setcref@lastconjunction%
      \fi%
    \fi%
    \@firstgroupfalse%
    \edef\@nextref{\stack@top{\@refsubstack}}%
    \stack@pop{\@refsubstack}%
    \isstackempty{\@refsubstack}%
    \ifstackempty%
      \expandafter\@setcref\expandafter{\@nextref}{#1}{}%
    \else%
      \edef\@beginref{\@nextref}%
      \let\@endref\relax%
      \edef\@nextref{\stack@top{\@refsubstack}}%
      \count@consecutive=1%
      \expandafter\ifx\csname r@\@beginref\endcsname\relax%
        \refconsecutivefalse%
      \else%
        \expandafter\ifx\csname r@\@nextref\endcsname\relax%
          \refconsecutivefalse%
        \else%
          \edef\@tmpa{{\@beginref}{\@nextref}}%
          \expandafter\isrefconsecutive\@tmpa%
        \fi%
      \fi%
      \@whilesw\ifrefconsecutive\fi{%
        \advance\count@consecutive 1%
        \let\@endref\@nextref%
        \stack@pop{\@refsubstack}%
        \isstackempty{\@refsubstack}%
        \ifstackempty%
          \refconsecutivefalse%
        \else%
          \edef\@nextref{\stack@top{\@refsubstack}}%
          \expandafter\ifx\csname r@\@nextref\endcsname\relax%
            \refconsecutivefalse%
          \else%
            \edef\@tmpa{{\@endref}{\@nextref}}%
            \expandafter\isrefconsecutive\@tmpa%
          \fi%
        \fi}%
      \ifx\@endref\relax%
        \expandafter\@setcref\expandafter{\@beginref}{#1}{@first}%
      \else%
        \ifnum\count@consecutive=2%
          \expandafter\@setcref\expandafter{\@beginref}{#1}{@first}%
          \expandafter\stack@push\expandafter{\@endref}{\@refsubstack}%
        \else
          \edef\@tmpa{{\@beginref}{\@endref}}%
          \ifstackempty%
            \expandafter\@setcrefrange\@tmpa{#1}{}%
          \else%
            \expandafter\@setcrefrange\@tmpa{#1}{@first}%
          \fi%
        \fi%
      \fi%
      \isstackfull{\@refsubstack}%
      \@whilesw\ifstackfull\fi{%
        \edef\@beginref{\stack@top{\@refsubstack}}%
        \stack@pop{\@refsubstack}%
        \let\@endref\relax%
        \isstackempty{\@refsubstack}%
        \ifstackempty%
          \expandafter\@setcref\expandafter{\@beginref}{#1}{@last}%
        \else%
          \edef\@nextref{\stack@top{\@refsubstack}}%
          \count@consecutive=1%
          \expandafter\ifx\csname r@\@nextref\endcsname\relax%
            \refconsecutivefalse%
          \else%
            \edef\@tmpa{{\@beginref}{\@nextref}}%
            \expandafter\isrefconsecutive\@tmpa%
          \fi%
          \@whilesw\ifrefconsecutive\fi{%
            \advance\count@consecutive 1%
            \let\@endref\@nextref%
            \stack@pop{\@refsubstack}%
            \isstackempty{\@refsubstack}%
            \ifstackempty%
              \refconsecutivefalse%
            \else%
              \edef\@nextref{\stack@top{\@refsubstack}}%
              \expandafter\ifx\csname r@\@nextref\endcsname\relax%
              \refconsecutivefalse%
              \else%
                \edef\@tmpa{{\@endref}{\@nextref}}%
                \expandafter\isrefconsecutive\@tmpa%
              \fi%
            \fi}%
          \isstackempty{\@refsubstack}%
          \ifstackempty%
            \def\@pos{@last}%
          \else%
            \def\@pos{@middle}%
          \fi%
          \ifx\@endref\relax%
            \edef\@tmpa{{\@beginref}{#1}{\@pos}}%
            \expandafter\@setcref\@tmpa%
          \else%
            \ifnum\count@consecutive=2%
              \edef\@tmpa{{\@beginref}{#1}{\@pos}}%
              \expandafter\@setcref\@tmpa%
            \else
              \edef\@tmpa{{\@beginref}{\@endref}{#1}{\@pos}}%
              \expandafter\@setcrefrange\@tmpa%
            \fi%
          \fi%
        \fi%
        \isstackfull{\@refsubstack}%
      }% end loop over reference substack
    \fi%
    \isstackfull{\@refstack}%
  }% end loop over main reference stack
  \endgroup}
\def\@setcref#1#2#3{%
  \expandafter\ifx\csname r@#1\endcsname\relax%
    \protect\G@refundefinedtrue%
    \nfss@text{\reset@font\bfseries ??}%
    \@latex@warning{Reference `#1' on page \thepage \space undefined}%
  \else%
    \cref@gettype{#1}{\@temptype}%  puts label type in \@temptype
    \cref@getlabel{#1}{\@templabel}%  puts label in \@templabel
    \expandafter\ifx\csname #2@\@temptype @format#3\endcsname\relax%
      \protect\G@refundefinedtrue%
      \nfss@text{\reset@font\bfseries ??}~\@templabel%
      \@latex@warning{\string\Cref \space reference format for label
        type `\@temptype' undefined}%
    \else%
      \expandafter\@@setcref\expandafter%
        {\csname #2@\@temptype @format#3\endcsname}{#1}%
    \fi%
  \fi}
\def\@@setcref#1#2{\cref@getlabel{#2}{\@templabel}#1{\@templabel}{}{}}
\newif\ifrefconsecutive%
\def\isrefconsecutive#1#2{%
  \begingroup%
    \countdef\refa@counter=1%
    \countdef\refb@counter=2%
    \cref@getcounter{#1}{\@result}%
    \refa@counter=\@result%
    \advance\refa@counter 1%
    \cref@getcounter{#2}{\@result}%
    \refb@counter=\@result%
    \cref@getprefix{#1}{\refa@prefix}%
    \cref@getprefix{#2}{\refb@prefix}%
    \def\@after{\refconsecutivefalse}%
    \ifx\refa@prefix\refb@prefix%
      \ifnum\refa@counter=\refb@counter%
        \def\@after{\refconsecutivetrue}%
      \fi%
    \fi%
  \expandafter\endgroup\@after}
\def\@setcrefrange#1#2#3#4{%
  \expandafter\ifx\csname r@#1\endcsname\relax%
    \protect\G@refundefinedtrue%
    \@latex@warning{Reference `#1' on page \thepage \space undefined}%
    \expandafter\ifx\csname r@#2\endcsname\relax%
      \nfss@text{\reset@font\bfseries ??}--%
      \nfss@text{\reset@font\bfseries ??}%
      \@latex@warning{Reference `#2' on page \thepage \space undefined}%
    \else%
      \cref@getlabel{#2}{\@labelb}%
      \nfss@text{\reset@font\bfseries ??}--\@labelb%
    \fi%
  \else%
    \expandafter\ifx\csname r@#2\endcsname\relax%
      \protect\G@refundefinedtrue%
      \cref@getlabel{#1}{\@labela}%
      \@labela--\nfss@text{\reset@font\bfseries ??}%
      \@latex@warning{Reference `#2' on page \thepage \space undefined}%
    \else%
      \cref@gettype{#1}{\@typea}%
      \cref@gettype{#2}{\@typeb}%
      \cref@getlabel{#1}{\@labela}%
      \cref@getlabel{#2}{\@labelb}%
      \edef\@formata{\expandafter\noexpand%
        \csname #3range@\@typea @format#4\endcsname}%
      \edef\@formatb{\expandafter\noexpand%
        \csname #3range@\@typeb @format#4\endcsname}%
      \expandafter\ifx\@formata\relax%
        \protect\G@refundefinedtrue%
        \nfss@text{\reset@font\bfseries ??}~\@labela--\@labelb%
        \@latex@warning{#3 \space reference format for label
          type `\@typea' undefined}%
      \else%
        \ifx\formata\formatb%
          \expandafter\@@setcrefrange\expandafter{\@formata}{#1}{#2}%
        \else%
          \protect\G@refundefinedtrue%
          \nfss@text{\reset@font\bfseries ??}~\@labela--\@labelb%
          \@latex@warning{Types inconsistent in reference range for
            references `#1' and `#2' on page \thepage}%
        \fi%
      \fi%
    \fi%
  \fi}
\def\@@setcrefrange#1#2#3{%
  \cref@getlabel{#2}{\@labela}%
  \cref@getlabel{#3}{\@labelb}%
  #1{\@labela}{\@labelb}{}{}{}{}}
\def\@setcref@middleconjunction{\crefmiddleconjunction}
\def\@setcref@lastconjunction{\creflastconjunction}
\newcommand{\crefformat}[2]{\@crefformat{cref}{#1}{#2}}
\newcommand{\Crefformat}[2]{\@crefformat{Cref}{#1}{#2}}
\newcommand{\crefrangeformat}[2]{\@crefrangeformat{crefrange}{#1}{#2}}
\newcommand{\Crefrangeformat}[2]{\@crefrangeformat{Crefrange}{#1}{#2}}
\newcommand{\crefmultiformat}[4]{%
  \@crefmultiformat{cref}{#1}{#2}{#3}{#4}}
\newcommand{\Crefmultiformat}[4]{%
  \@crefmultiformat{Cref}{#1}{#2}{#3}{#4}}
\newcommand{\crefrangemultiformat}[4]{%
  \@crefrangemultiformat{crefrange}{#1}{#2}{#3}{#4}}
\newcommand{\Crefrangemultiformat}[4]{%
  \@crefrangemultiformat{Crefrange}{#1}{#2}{#3}{#4}}
\def\@crefformat#1#2#3{%
  \expandafter\def\csname #1@#2@format\endcsname##1##2##3{#3}%
  \def\@tmpa##1##2\@nil{%
    \if##1c \def\@other{C##2}%
    \else\def\@other{c##2}\fi}%
  \@tmpa#1\@nil%
  \@ifundefined{\@other @#2@format}{%
    \def\@tmpa##1##2\@nil{%
      \if##1c\def\@changecase{\MakeUppercase}%
      \else\def\@changecase{\Makelowercase}\fi}%
    \@tmpa#1\@nil%
    \newtoks\@toksa%
    \@toksa={\def\@tmpa##1##2##3}%
    \expandafter\expandafter\expandafter\the%
    \expandafter\expandafter\expandafter\@toksa%
    \expandafter\expandafter\expandafter{%
      \csname#1@#2@format\endcsname{##1}{##2}{##3}}%
    \expandafter\the\expandafter\@toksa\expandafter{%
      \expandafter\MakeUppercase\@tmpa{##1}{##2}{##3}}%
    \@toksa={%
      \expandafter\def\csname\@other @#2@format\endcsname##1##2##3}%
    \expandafter\the\expandafter\@toksa\expandafter{%
      \@tmpa{##1}{##2}{##3}}%
  }{}%
}
\def\@crefrangeformat#1#2#3{%
  \expandafter\def\csname #1@#2@format\endcsname%
    ##1##2##3##4##5##6{#3}%
  \def\@tmpa##1##2\@nil{%
    \if##1c \def\@other{C##2}%
    \else\def\@other{c##2}\fi}%
  \@tmpa#1\@nil%
  \@ifundefined{\@other @#2@format}{%
    \def\@tmpa##1##2\@nil{%
      \if##1c\def\@changecase{\MakeUppercase}%
      \else\def\@changecase{\Makelowercase}\fi}%
    \@tmpa#1\@nil%
    \newtoks\@toksa%
    \@toksa={\def\@tmpa##1##2##3##4##5##6}%
    \expandafter\expandafter\expandafter\the%
    \expandafter\expandafter\expandafter\@toksa%
    \expandafter\expandafter\expandafter{%
      \csname#1@#2@format\endcsname{##1}{##2}{##3}{##4}{##5}{##6}}%
    \expandafter\the\expandafter\@toksa\expandafter{%
      \expandafter\MakeUppercase\@tmpa{##1}{##2}{##3}{##4}{##5}{##6}}
    \@toksa={\expandafter\def%
      \csname\@other @#2@format\endcsname##1##2##3##4##5##6}%
    \expandafter\the\expandafter\@toksa\expandafter{%
      \@tmpa{##1}{##2}{##3}{##4}{##5}{##6}}%
  }{}%
}
\def\@crefmultiformat#1#2#3#4#5{%
  \expandafter\def\csname #1@#2@format@first\endcsname##1##2##3{#3}%
  \expandafter\def\csname #1@#2@format@middle\endcsname##1##2##3{#4}%
  \expandafter\def\csname #1@#2@format@last\endcsname##1##2##3{#5}%
  \newtoks\@toksa%
  \def\@tmpa##1##2\@nil{%
    \if##1c \def\@other{C##2}%
    \else\def\@other{c##2}\fi}%
  \@tmpa#1\@nil%
  \@ifundefined{\@other @#2@format@first}{%
    \def\@tmpa##1##2\@nil{%
      \if##1c\def\@changecase{\MakeUppercase}%
      \else\def\@changecase{\Makelowercase}\fi}%
    \@tmpa#1\@nil%
    \@toksa={\def\@tmpa##1##2##3}%
    \expandafter\expandafter\expandafter\the%
    \expandafter\expandafter\expandafter\@toksa%
    \expandafter\expandafter\expandafter{%
      \csname#1@#2@format@first\endcsname{##1}{##2}{##3}}%
    \expandafter\the\expandafter\@toksa\expandafter{%
      \expandafter\MakeUppercase\@tmpa{##1}{##2}{##3}}%
    \@toksa={%
      \expandafter\def\csname\@other @#2@format@first\endcsname%
        ##1##2##3}%
    \expandafter\the\expandafter\@toksa\expandafter{%
      \@tmpa{##1}{##2}{##3}}%
  }{}
  \@ifundefined{\@other @#2@format@middle}{%
    \@toksa={%
      \expandafter\let\csname\@other @#2@format@middle\endcsname}%
    \expandafter\the\expandafter\@toksa%
      \csname #1@#2@format@middle\endcsname%
  }{}%
  \@ifundefined{\@other @#2@format@last}{%
    \@toksa={%
      \expandafter\let\csname\@other @#2@format@last\endcsname}%
    \expandafter\the\expandafter\@toksa%
      \csname #1@#2@format@last\endcsname%
  }{}%
}
\def\@crefrangemultiformat#1#2#3#4#5{%
  \expandafter\def\csname #1@#2@format@first\endcsname%
    ##1##2##3##4##5##6{#3}%
  \expandafter\def\csname #1@#2@format@middle\endcsname%
    ##1##2##3##4##5##6{#4}%
  \expandafter\def\csname #1@#2@format@last\endcsname%
    ##1##2##3##4##5##6{#5}%
  \def\@tmpa##1##2\@nil{%
    \if##1c \def\@other{C##2}%
    \else\def\@other{c##2}\fi}%
  \@tmpa#1\@nil%
  \@ifundefined{\@other @#2@format@first}{%
    \def\@tmpa##1##2\@nil{%
      \if##1c\def\@changecase{\MakeUppercase}%
      \else\def\@changecase{\MakeLowercase}\fi}%
    \@tmpa#1\@nil%
    \@toksa={\def\@tmpa##1##2##3##4##5##6}%
    \expandafter\expandafter\expandafter\the%
    \expandafter\expandafter\expandafter\@toksa%
    \expandafter\expandafter\expandafter{%
      \csname#1@#2@format@first\endcsname%
        {##1}{##2}{##3}{##4}{##5}{##6}}%
    \expandafter\the\expandafter\@toksa\expandafter{%
      \expandafter\MakeUppercase\@tmpa{##1}{##2}{##3}{##4}{##5}{##6}}%
    \@toksa={%
      \expandafter\def\csname\@other @#2@format@first\endcsname%
        ##1##2##3##4##5##6}%
    \expandafter\the\expandafter\@toksa\expandafter{%
      \@tmpa{##1}{##2}{##3}{##4}{##5}{##6}}%
  }{}%
  \@ifundefined{\@other @#2@format@middle}{%
    \@toksa={%
      \expandafter\let\csname\@other @#2@format@middle\endcsname}%
    \expandafter\the\expandafter\@toksa%
      \csname #1@#2@format@middle\endcsname%
  }{}%
  \@ifundefined{\@other @#2@format@last}{%
    \@toksa={%
      \expandafter\let\csname\@other @#2@format@last\endcsname}%
    \expandafter\the\expandafter\@toksa%
      \csname #1@#2@format@last\endcsname%
  }{}%
}
\crefformat{equation}{eq.~#2(#1)#3}
\Crefformat{equation}{Eq.~#2(#1)#3}
\crefformat{chapter}{chapter~#2#1#3}
\Crefformat{chapter}{Chapter~#2#1#3}
\crefformat{section}{section~#2#1#3}
\Crefformat{section}{Section~#2#1#3}
\crefformat{subsection}{section~#2#1#3}
\Crefformat{subsection}{Section~#2#1#3}
\crefformat{subsubsection}{section~#2#1#3}
\Crefformat{subsubsection}{Section~#2#1#3}
\crefformat{subsubsubsection}{section~#2#1#3}
\Crefformat{subsubsubsection}{Section~#2#1#3}
\crefformat{figure}{fig.~#2#1#3}
\Crefformat{figure}{Fig.~#2#1#3}
\crefformat{theorem}{theorem~#2#1#3}
\Crefformat{theorem}{Theorem~#2#1#3}
\crefmultiformat{equation}%
  {eqs.~#2(#1)#3}{, #2(#1)#3}{ and~#2(#1)#3}
\Crefmultiformat{equation}%
  {Eqs.~#2(#1)#3}{, #2(#1)#3}{ and~#2(#1)#3}
\crefmultiformat{chapter}%
  {chapters~#2#1#3}{, #2#1#3}{ and~#2#1#3}
\Crefmultiformat{chapter}%
  {Chapters~#2#1#3}{, #2#1#3}{ and~#2#1#3}
\crefmultiformat{section}%
  {sections~#2#1#3}{, #2#1#3}{ and~#2#1#3}
\Crefmultiformat{section}%
  {Sections~#2#1#3}{, #2#1#3}{ and~#2#1#3}
\crefmultiformat{subsection}%
  {sections~#2#1#3}{, #2#1#3}{ and~#2#1#3}
\Crefmultiformat{subsection}%
  {Sections~#2#1#3}{, #2#1#3}{ and~#2#1#3}
\crefmultiformat{subsubsection}%
  {sections~#2#1#3}{, #2#1#3}{ and~#2#1#3}
\Crefmultiformat{subsubsection}%
  {Sections~#2#1#3}{, #2#1#3}{ and~#2#1#3}
\crefmultiformat{subsubsubsection}%
  {sections~#2#1#3}{, #2#1#3}{ and~#2#1#3}
\Crefmultiformat{subsubsubsection}%
  {Sections~#2#1#3}{, #2#1#3}{ and~#2#1#3}
\crefmultiformat{figure}%
  {figs.~#2#1#3}{, #2#1#3}{ and~#2#1#3}
\Crefmultiformat{figure}%
  {Figs.~#2#1#3}{, #2#1#3}{ and~#2#1#3}
\crefmultiformat{theorem}%
  {theorems~#2#1#3}{, #2#1#3}{ and~#2#1#3}
\Crefmultiformat{theorem}%
  {Theorems~#2#1#3}{, #2#1#3}{ and~#2#1#3}
\crefrangeformat{equation}{eqs.~#3(#1)#4--#5(#2)#6}
\Crefrangeformat{equation}{Eqs.~#3(#1)#4--#5(#2)#6}
\crefrangeformat{chapter}{chapters~#3#1#4--#5#2#6}
\Crefrangeformat{chapter}{Chapters~#3#1#4--#5#2#6}
\crefrangeformat{section}{sections~#3#1#4--#5#2#6}
\Crefrangeformat{section}{Sections~#3#1#4--#5#2#6}
\crefrangeformat{subsection}{sections~#3#1#4--#5#2#6}
\Crefrangeformat{subsection}{Sections~#3#1#4--#5#2#6}
\crefrangeformat{subsubsection}{sections~#3#1#4--#5#2#6}
\Crefrangeformat{subsubsection}{Sections~#3#1#4--#5#2#6}
\crefrangeformat{subsubsubsection}{sections~#3#1#4--#5#2#6}
\Crefrangeformat{subsubsubsection}{Sections~#3#1#4--#5#2#6}
\crefrangeformat{figure}{figs.~#3#1#4--#5#2#6}
\Crefrangeformat{figure}{Figs.~#3#1#4--#5#2#6}
\crefrangeformat{theorem}{theorems~#3#1#4--#5#2#6}
\Crefrangeformat{theorem}{Theorems~#3#1#4--#5#2#6}
\crefrangemultiformat{equation}%
  {eqs.~#3(#1)#4--#5(#2)#6}%
  {, #3(#1)#4--#5(#2)#6}%
  { and~#3(#1)#4--#5(#2)#6}
\Crefrangemultiformat{equation}%
  {Eqs.~#3(#1)#4--#5(#2)#6}%
  {, #3(#1)#4--#5(#2)#6}%
  { and~#3(#1)#4--#5(#2)#6}
\crefrangemultiformat{chapter}%
  {chapters~#3#1#4--#5#2#6}%
  {, #3#1#4--#5#2#6}%
  { and~#3#1#4--#5#2#6}
\Crefrangemultiformat{chapter}%
  {Chapters~#3#1#4--#5#2#6}%
  {, #3#1#4--#5#2#6}%
  { and~#3#1#4--#5#2#6}
\crefrangemultiformat{section}%
  {sections~#3#1#4--#5#2#6}%
  {, #3#1#4--#5#2#6}%
  { and~#3#1#4--#5#2#6}
\Crefrangemultiformat{section}%
  {Sections~#3#1#4--#5#2#6}%
  {, #3#1#4--#5#2#6}%
  { and~#3#1#4--#5#2#6}
\crefrangemultiformat{subsection}%
  {sections~#3#1#4--#5#2#6}%
  {, #3#1#4--#5#2#6}%
  { and~#3#1#4--#5#2#6}
\Crefrangemultiformat{subsection}%
  {Sections~#3#1#4--#5#2#6}%
  {, #3#1#4--#5#2#6}%
  { and~#3#1#4--#5#2#6}
\crefrangemultiformat{subsubsection}%
  {sections~#3#1#4--#5#2#6}%
  {, #3#1#4--#5#2#6}%
  { and~#3#1#4--#5#2#6}
\Crefrangemultiformat{subsubsection}%
  {Sections~#3#1#4--#5#2#6}%
  {, #3#1#4--#5#2#6}%
  { and~#3#1#4--#5#2#6}
\crefrangemultiformat{subsubsubsection}%
  {sections~#3#1#4--#5#2#6}%
  {, #3#1#4--#5#2#6}%
  { and~#3#1#4--#5#2#6}
\Crefrangemultiformat{subsubsubsection}%
  {Sections~#3#1#4--#5#2#6}%
  {, #3#1#4--#5#2#6}%
  { and~#3#1#4--#5#2#6}
\crefrangemultiformat{figure}%
  {figs~#3#1#4--#5#2#6}%
  {, #3#1#4--#5#2#6}%
  { and~#3#1#4--#5#2#6}
\Crefrangemultiformat{figure}%
  {Figs~#3#1#4--#5#2#6}%
  {, #3#1#4--#5#2#6}%
  { and~#3#1#4--#5#2#6}
\crefrangemultiformat{theorem}%
  {theorems~#3#1#4--#5#2#6}%
  {, #3#1#4--#5#2#6}%
  { and~#3#1#4--#5#2#6}
\Crefrangemultiformat{theorem}%
  {Theorems~#3#1#4--#5#2#6}%
  {, #3#1#4--#5#2#6}%
  { and~#3#1#4--#5#2#6}
\def\crefmiddleconjunction{, }
\def\creflastconjunction{, and }
\DeclareOption{hyperref}{%
\PackageInfo{cleveref}{option `hyperref' loaded}
\def\cref@label#1#2#3#4#5{\@result}
\def\cref@hyperref#1{\expandafter\expandafter\expandafter%
  \@fourthoffive\csname r@#1\endcsname}
\def\cref@getlabel#1#2{%
  \expandafter\let\expandafter\@tempa\csname r@#1\endcsname%
  \edef\@tempa{\expandafter\@firstoffive\@tempa}%
  \expandafter\@cref@getlabel\@tempa\@nil#2}
\def\cref@gettype#1#2{%
  \expandafter\let\expandafter\@tempa\csname r@#1\endcsname
  \edef\@tempa{\expandafter\@firstoffive\@tempa}%
  \expandafter\@cref@gettype\@tempa\@nil#2}
\def\cref@getcounter#1#2{%
  \expandafter\let\expandafter\@tempa\csname r@#1\endcsname
  \edef\@tempa{\expandafter\@firstoffive\@tempa}%
  \expandafter\@cref@getcounter\@tempa\@nil#2}
\def\cref@getprefix#1#2{%
  \expandafter\let\expandafter\@tempa\csname r@#1\endcsname
  \edef\@tempa{\expandafter\@firstoffive\@tempa}%
  \expandafter\@cref@getprefix\@tempa\@nil#2}
\def\H@refstepcounter#1{%
  \stepcounter{#1}%
  \reset@by{#1}{\@result}%
  \ifx\@result\relax\def\@result{}%
  \else\edef\@result{\csname the\@result\endcsname}\fi%
  \protected@edef\@currentlabel%
    {[#1][\arabic{#1}][\@result]%
      \csname p@#1\endcsname\csname the#1\endcsname}}
\def\refstepcounter@noarg#1{\old@refstepcounter{#1}}
\def\refstepcounter@optarg[#1]#2{%
  \old@refstepcounter{#2}%
  \expandafter\@cref@getlabel\@currentlabel\@nil{\@templabel}%
  \reset@by{#2}{\@tempreset}%
  \ifx\@tempreset\relax\def\@tempreset{}%
  \else\edef\@tempreset{\csname the\@tempreset\endcsname}\fi%
  \protected@edef\@currentlabel{%
    [#1][\arabic{#2}][\@tempreset]\@templabel}}
\def\@@setcref#1#2{%
  \cref@getlabel{#2}{\@templabel}%
  \edef\@templink{\cref@hyperref{#2}}%
  #1{\@templabel}{\hyper@linkstart{link}{\@templink}}{\hyper@linkend}}
\def\@@setcrefrange#1#2#3{%
  \cref@getlabel{#2}{\@labela}%
  \cref@getlabel{#3}{\@labelb}%
  \edef\@linka{\cref@hyperref{#2}}%
  \edef\@linkb{\cref@hyperref{#3}}%
  #1{\@labela}{\@labelb}%
    {\hyper@linkstart{link}{\@linka}}{\hyper@linkend}%
    {\hyper@linkstart{link}{\@linkb}}{\hyper@linkend}}
} % end of hyperref option
\DeclareOption{ntheorem}{%
\PackageInfo{cleveref}{option `ntheorem' loaded}
\gdef\@thm#1#2#3{%
   \if@thmmarks
     \stepcounter{end\InTheoType ctr}%
   \fi
   \renewcommand{\InTheoType}{#1}%
   \if@thmmarks
     \stepcounter{curr#1ctr}%
     \setcounter{end#1ctr}{0}%
   \fi
   \refstepcounter[#1]{#2}%  <<<<<
   \thm@topsepadd \theorempostskipamount
   \ifvmode \advance\thm@topsepadd\partopsep\fi
   \trivlist
   \@topsep \theorempreskipamount
   \@topsepadd \thm@topsepadd
   \advance\linewidth -\theorem@indent
   \advance\@totalleftmargin \theorem@indent
   \parshape \@ne \@totalleftmargin \linewidth
   \@ifnextchar[{\@ythm{#1}{#2}{#3}}{\@xthm{#1}{#2}{#3}}%]
 }
\crefformat{lemma}{lemma~#2#1#3}
\Crefformat{lemma}{Lemma~#2#1#3}
\crefformat{corrollary}{corrollary~#2#1#3}
\Crefformat{corrollary}{Corrollary~#2#1#3}
\crefformat{proposition}{proposition~#2#1#3}
\Crefformat{proposition}{Proposition~#2#1#3}
\crefformat{definition}{definition~#2#1#3}
\Crefformat{definition}{Definition~#2#1#3}
\crefformat{result}{result~#2#1#3}
\Crefformat{result}{Result~#2#1#3}
\crefrangeformat{lemma}{lemma~#3#1#4--#5#2#6}
\Crefrangeformat{lemma}{Lemma~#3#1#4--#5#2#6}
\crefrangeformat{corrollary}{corrollary~#3#1#4--#5#2#6}
\Crefrangeformat{corrollary}{Corrollary~#3#1#4--#5#2#6}
\crefrangeformat{proposition}{proposition~#3#1#4--#5#2#6}
\Crefrangeformat{proposition}{Proposition~#3#1#4--#5#2#6}
\crefrangeformat{definition}{definition~#3#1#4--#5#2#6}
\Crefrangeformat{definition}{Definition~#3#1#4--#5#2#6}
\crefrangeformat{result}{result~#3#1#4--#5#2#6}
\Crefrangeformat{result}{Result~#3#1#4--#5#2#6}
\crefmultiformat{lemma}%
  {lemmas~#2#1#3}{, #2#1#3}{ and~#2#1#3}
\Crefmultiformat{lemma}%
  {Lemmas~#2#1#3}{, #2#1#3}{ and~#2#1#3}
\crefmultiformat{corrollary}%
  {corrollaries~#2#1#3}{, #2#1#3}{ and~#2#1#3}
\Crefmultiformat{corrollary}%
  {Corrollaries~#2#1#3}{, #2#1#3}{ and~#2#1#3}
\crefmultiformat{proposition}%
  {propositions~#2#1#3}{, #2#1#3}{ and~#2#1#3}
\Crefmultiformat{proposition}%
  {Propositions~#2#1#3}{, #2#1#3}{ and~#2#1#3}
\crefmultiformat{definition}%
  {definitions~#2#1#3}{, #2#1#3}{ and~#2#1#3}
\Crefmultiformat{definition}%
  {Definitions~#2#1#3}{, #2#1#3}{ and~#2#1#3}
\crefmultiformat{result}%
  {results~#2#1#3}{, #2#1#3}{ and~#2#1#3}
\Crefmultiformat{result}%
  {Results~#2#1#3}{, #2#1#3}{ and~#2#1#3}
\crefrangemultiformat{lemma}%
  {lemmas~#3#1#4--#5#2#6}{, #3#1#4--#5#2#6}%
  { and~#3#1#4--#5#2#6}%
\Crefrangemultiformat{lemma}%
  {Lemmas~#3#1#4--#5#2#6}{, #3#1#4--#5#2#6}%
  { and~#3#1#4--#5#2#6}
\crefrangemultiformat{corrollary}%
  {corrollaries~#3#1#4--#5#2#6}{, #3#1#4--#5#2#6}%
  { and~#3#1#4--#5#2#6}
\Crefrangemultiformat{corrollary}%
  {Corrollaries~#3#1#4--#5#2#6}{, #3#1#4--#5#2#6}%
  { and~#3#1#4--#5#2#6}
\crefrangemultiformat{proposition}%
  {propositions~#3#1#4--#5#2#6}{, #3#1#4--#5#2#6}%
  { and~#3#1#4--#5#2#6}
\Crefrangemultiformat{proposition}%
  {Propositions~#3#1#4--#5#2#6}{, #3#1#4--#5#2#6}%
  { and~#3#1#4--#5#2#6}
\crefrangemultiformat{definition}%
  {definitions~#3#1#4--#5#2#6}{, #3#1#4--#5#2#6}%
  { and~#3#1#4--#5#2#6}
\Crefrangemultiformat{definition}%
  {Definitions~#3#1#4--#5#2#6}{, #3#1#4--#5#2#6}%
  { and~#3#1#4--#5#2#6}
\crefrangemultiformat{result}%
  {results~#3#1#4--#5#2#6}{, #3#1#4--#5#2#6}%
  { and~#3#1#4--#5#2#6}
\Crefrangemultiformat{result}%
  {Results~#3#1#4--#5#2#6}{, #3#1#4--#5#2#6}%
  { and~#3#1#4--#5#2#6}
} % end of ntheorem option
\DeclareOption{poorman}{%
\PackageInfo{cleveref}{option `poorman' loaded}
\edef\cref@text{}
\AtBeginDocument{%
  \newwrite\@crefscript%
  \immediate\openout\@crefscript=\jobname.sed%
}
\AtEndDocument{%
  \immediate\closeout\@crefscript%
  \newread\@crefscript%
  \immediate\openin\@crefscript=\jobname.sed%
  \begingroup%
    \newif\if@not@eof%
    \def\@eof{\par }%
    \catcode`.=13 \catcode`[=13 \catcode`]=13
    \catcode`^=13 \catcode`$=13 %$
    \catcode`\=0 \catcode`<=1 \catcode`>=2
    \catcode`\\=13 \catcode`\{=12 \catcode`\}=12 \catcode`_=12
    \lccode`/=92
    \lccode`~=92\lowercase{\def~{\string/\string/}}%
    \lccode`~=46\lowercase{\def~{\string/\string.}}%
    \lccode`~=91\lowercase{\def~{\string/\string[}}%
    \lccode`~=93\lowercase{\def~{\string/\string]}}%
    \lccode`~=94\lowercase{\def~{\string/\string^}}%
    \lccode`~=36\lowercase{\def~{\string/\string$}}% $
    \lccode`~=0 \lccode`/=0 \catcode`~=12
    \def\cref@text{}%
    \immediate\read\@crefscript to \@tmpa%
    \edef\@tmpa{\@tmpa}%
    \ifx\@tmpa\@eof%
      \@not@eoffalse%
    \else%
      \@not@eoftrue%
    \fi%
    \@whilesw\if@not@eof\fi{%
      \expandafter\g@addto@macro\expandafter\cref@text\expandafter{%
        \@tmpa^^J}%
      \show\cref@text%
      \immediate\read\@crefscript to \@tmpa%
      \edef\@tmpa{\@tmpa}%
      \ifx\@tmpa\@eof%
        \@not@eoffalse%
      \else%
        \@not@eoftrue%
      \fi}%
  \endgroup%
  \immediate\closein\@crefscript%
  \begingroup%
    \lccode`|=92 \lccode`<=123 \lccode`>=125 \lccode`C=67
    \lowercase{\edef\@tmpa{s/||usepackage|(|[.*|]|)|?<cleveref>//g}}%
    \expandafter\g@addto@macro\expandafter\cref@text\expandafter{%
      \@tmpa^^J}
    \lowercase{\edef\@tmpa{s/||[cC]refformat<.*><.*>//g}}%
    \expandafter\g@addto@macro\expandafter\cref@text\expandafter{%
      \@tmpa^^J}
    \lowercase{\edef\@tmpa{s/||[cC]refrangeformat<.*><.*>//g}}%
    \expandafter\g@addto@macro\expandafter\cref@text\expandafter{%
      \@tmpa^^J}
    \lowercase{\edef\@tmpa{s/||[cC]refmultiformat<.*><.*><.*><.*>//g}}%
    \expandafter\g@addto@macro\expandafter\cref@text\expandafter{%
      \@tmpa^^J}
    \lowercase{\edef\@tmpa{%
        s/||[cC]refrangemultiformat<.*><.*><.*><.*>//g}}%
    \expandafter\g@addto@macro\expandafter\cref@text\expandafter{%
      \@tmpa^^J}
    \lowercase{\edef\@tmpa{s/||renewcommand<||[cC]ref><.*>//g}}%
    \expandafter\g@addto@macro\expandafter\cref@text\expandafter{%
      \@tmpa^^J}
    \lowercase{\edef\@tmpa{s/||renewcommand<||[cC]refrange><.*>//g}}%
    \expandafter\g@addto@macro\expandafter\cref@text\%
    expandafter{\@tmpa}
  \endgroup
  \newwrite\@crefscript%
  \immediate\openout\@crefscript=\jobname.sed%
  \immediate\write\@crefscript{\cref@text}%
  \immediate\closeout\@crefscript%
}%
\renewcommand{\cref}[1]{%
  \edef\cref@text{}%
  \@cref{cref}{#1}%
  \cref@writescript{\string\cref\string{#1\string}}}
\renewcommand{\Cref}[1]{%
  \edef\cref@text{}%
  \@cref{Cref}{#1}%
  \cref@writescript{\string\Cref\string{#1\string}}}
\renewcommand{\crefrange}[2]{%
  \edef\cref@text{}%
  \@setcrefrange{#1}{#2}{cref}{}%
  \cref@writescript{%
    \string\crefrange\string{#1\string}\string{#2\string}}}
\renewcommand{\Crefrange}[2]{%
  \edef\cref@text{}%
  \@setcrefrange{#1}{#2}{Cref}{}%
  \cref@writescript{%
    \string\Crefrange\string{#1\string}\string{#2\string}}}
\def\cref@writescript#1{%
  \edef\@tmpa{\cref@getmeaning{\cref@text}}%
  \immediate\write\@crefscript{s/#1/\@tmpa/g}%
}
\let\old@@setcref\@@setcref
\let\old@@setcrefrange\@@setcrefrange
\def\cref@getmeaning#1{\expandafter\@cref@getmeaning\meaning#1\@nil}
\def\@cref@getmeaning#1->#2\@nil{#2}
\def\@@setcref#1#2{%
  \old@@setcref{#1}{#2}%
  \expandafter\g@addto@macro\expandafter{%
    \expandafter\cref@text\expandafter}\expandafter{%
    #1{\ref{#2}}{}{}}}
\def\@@setcrefrange#1#2#3{%
  \old@@setcrefrange{#1}{#2}{#3}%
  \expandafter\g@addto@macro
    \expandafter{\expandafter\cref@text\expandafter}%
    \expandafter{#1{\ref{#2}}{\ref{#3}}{}{}{}{}}}
\def\@setcref@middleconjunction{%
  \crefmiddleconjunction%
  \expandafter\g@addto@macro
    \expandafter{\expandafter\cref@text\expandafter}%
    \expandafter{\crefmiddleconjunction}}
\def\@setcref@lastconjunction{%
  \creflastconjunction%
  \expandafter\g@addto@macro
    \expandafter{\expandafter\cref@text\expandafter}%
    \expandafter{\creflastconjunction}}
} % end of poorman option
\ProcessOptions\relax
\endinput
%%
%% End of file `cleveref.sty'.
