%%
%% This is file `phfthm.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% phfthm.dtx  (with options: `package')
%% 
%% This is a generated file.
%% 
%% Copyright (C) 2016 by Philippe Faist <philippe.faist@bluewin.ch>
%% 
%% This file 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.
%% 
\NeedsTeXFormat{LaTeX2e}[2005/12/01]
\ProvidesPackage{phfthm}
    [2016/08/15 v1.0 phfthm package]
\RequirePackage{xkeyval}
\RequirePackage{etoolbox}
\RequirePackage{aliascnt}
\RequirePackage{amsmath}
\RequirePackage{amsthm}
\def\phfthm@internal@execattribs#1#2#3{%
  \@for\next:=#3\do{%
    \ifcsname #1\next\endcsname%
      \csname #1\next\endcsname%
    \else%
      \PackageWarning{phfthm}{Unknown #2: '\next'. Ignoring.}
    \fi
  }
}
\define@cmdkey{phfmkthm}{counter}{}
\define@boolkey{phfmkthm}{aliascounter}[true]{}
\define@cmdkey{phfmkthm}{thmstyle}{}
\define@boolkey{phfmkthm}{defnostar}[true]{}
\define@boolkey{phfmkthm}{defstar}[true]{}
\define@boolkey{phfmkthm}{proofref}[true]{}
\define@cmdkey{phfmkthm}{proofrefstyle}{}
\newcommand\phfMakeTheorem[3][]{% }
  \KV@phfmkthm@aliascountertrue%
  \def\cmdKV@phfmkthm@counter{}%
  \def\cmdKV@phfmkthm@thmstyle{}%
  \KV@phfmkthm@defnostartrue%
  \KV@phfmkthm@defstartrue%
  \KV@phfmkthm@proofreftrue%
  \def\cmdKV@phfmkthm@proofrefstyle{default}%
  \setkeys{phfmkthm}{#1}%
  \if\relax\detokenize\expandafter{\cmdKV@phfmkthm@thmstyle}\relax%
  \else%
    \theoremstyle{\cmdKV@phfmkthm@thmstyle}%
  \fi%
  \ifKV@phfmkthm@defnostar%
    \if\relax\detokenize\expandafter{\cmdKV@phfmkthm@counter}\relax%
      \newtheorem{phfthm@#2}{#3}%
      \csdef{phfthm@#2autorefname}{#3}%
    \else%
      \ifKV@phfmkthm@aliascounter%
        \newaliascnt{#2}{\cmdKV@phfmkthm@counter}%
        \newtheorem{phfthm@#2}[#2]{#3}%
        \aliascntresetthe{#2}%
        \csdef{#2autorefname}{#3}%
      \else%
        \newtheorem{phfthm@#2}[\cmdKV@phfmkthm@counter]{#3}%
      \fi%
    \fi%
    \newenvironment{#2}[1][]{%
      \begin{phfthm@#2}[##1]%
        \begingroup%
          \csname phfthm@hook@start@#2\endcsname{##1}%
      }{%
          \csname phfthm@hook@end@#2\endcsname%
        \endgroup%
      \end{phfthm@#2}%
    }%
    \csedef{phfthm@hook@start@#2}##1{%
      \ifKV@phfmkthm@proofref%
        \expandafter\noexpand%
          \csname phfthm@proofrefstyle@\cmdKV@phfmkthm@proofrefstyle @setup\endcsname%
        \noexpand\phfthm@def@label@thmlabel{#2}%
        \noexpand\phfthm@proofref@impl@start%
      \fi%
      \noexpand\phfthm@hook@startcommonnostar{#2}{##1}%
    }%
    \csedef{phfthm@hook@afterlabel@#2}{%
      \ifKV@phfmkthm@proofref%
        \noexpand\phfthm@proofref@expandthmlabeltoarg%
          \noexpand\phfthm@proofref@impl@afterlabel%
      \fi%
      \noexpand\phfthm@hook@afterlabelcommon{#2}%
    }%
    \csedef{phfthm@hook@end@#2}{%
      \ifKV@phfmkthm@proofref%
        \noexpand\phfthm@proofref@expandthmlabeltoarg%
          \noexpand\phfthm@proofref@impl@end%
      \fi%
      \noexpand\phfthm@hook@endcommonnostar{#2}%
    }%
  \fi%
  \ifKV@phfmkthm@defstar%
    \newtheorem*{phfthm@#2*}{#3}%
    \newenvironment{#2*}[1][]{%
      \begin{phfthm@#2*}[##1]%
        \begingroup%
          \csname phfthm@hook@start@#2*\endcsname{##1}%
      }{%
          \csname phfthm@hook@end@#2*\endcsname%
        \endgroup%
      \end{phfthm@#2*}%
    }%
  \fi%
  \csdef{phfthm@hook@start@#2*}##1{\phfthm@hook@startcommonstar{#2}{##1}}%
  \csdef{phfthm@hook@end@#2*}{\phfthm@hook@endcommonstar{#2}}%
}
\def\phfthm@hook@startcommonnostar#1#2{%
  \phfthm@hook@startcommon{#1}{#2}%
}
\def\phfthm@hook@startcommonstar#1#2{%
  \phfthm@hook@startcommon{#1}{#2}%
}
\def\phfthm@hook@startcommon#1#2{%
  \postdisplaypenalty=10000\relax%
}
\def\phfthm@hook@afterlabelcommon#1{}
\def\phfthm@hook@endcommonnostar#1{\phfthm@hook@endcommon{#1}}
\def\phfthm@hook@endcommonstar#1{\phfthm@hook@endcommon{#1}}
\def\phfthm@hook@endcommon#1{}
\def\phfthm@def@label@thmlabel#1{%
  \ifdefined\phfthm@old@label
    \PackageWarning{phfthm}{Internal inconsistency: \string\phfthm@def@label@thmlabel
      called twice for the same theorem environment!}
  \else
    \let\phfthm@old@label\label%
    \edef\label{\noexpand\phfthm@thmlabel{#1}}%
  \fi
}
\def\phfthm@thmlabel#1#2{%
  \def\phfthm@val@thmlabel{#2}%
  \phfthm@old@label{#2}%
  \let\label\phfthm@old@label%
  \csname phfthm@hook@afterlabel@#1\endcsname%
  \ignorespaces%
}
\let\phfthm@old@proof\proof
\let\endphfthm@old@proof\endproof
\providecommand\proofname{Proof}
\def\proofofname#1{\proofname\space of #1}
\newcounter{phfthmproofcnt}
\def\phfthm@NOPROOFARG{}
\def\phfthm@test@NOPROOFARG{\phfthm@NOPROOFARG}
\define@cmdkey{phfmkprf}{displayenv}{}
\define@cmdkey{phfmkprf}{defaultproofname}{}
\define@boolkey{phfmkprf}{override}[true]{}
\define@cmdkey{phfmkprf}{internalcounter}{}
\define@cmdkey{phfmkprf}{proofofname}{}
\define@boolkey{phfmkprf}{parselabel}[true]{}
\define@cmdkey{phfmkprf}{parselabelcmd}{}
\newcommand\phfMakeProofEnv[2][]{%}
  \KV@phfmkprf@overridefalse%
  \def\cmdKV@phfmkprf@displayenv{*}%
  \def\cmdKV@phfmkprf@defaultproofname{\proofname}%
  \def\cmdKV@phfmkprf@internalcounter{phfthmproofcnt}%
  \def\cmdKV@phfmkprf@proofofname{\proofofname}%
  \KV@phfmkprf@parselabeltrue
  \def\cmdKV@phfmkprf@parselabelcmd{\phfthm@proof@parselabel}%
  \setkeys{phfmkprf}{#1}%
  \def\phfmkprf@tmp@star{*}%
  \ifx\cmdKV@phfmkprf@displayenv\phfmkprf@tmp@star\relax%
    \def\cmdKV@phfmkprf@displayenv{phfthm@proof@defaultdisplayenv}%
  \fi
  \cslet{phfthm@prfenv@#2@val@displayenv}\cmdKV@phfmkprf@displayenv%
  \if\relax\detokenize\expandafter{\cmdKV@phfmkprf@defaultproofname}\relax%
    \csdef{phfthm@prfenv@#2@val@defaultproofnameargs}{}%
    \csdef{phfthm@prfenv@#2@val@setdefaultprooftitle}{%
      \def\phfthm@val@prooftitle{\proofname}}%
  \else
    \csedef{phfthm@prfenv@#2@val@defaultproofnameargs}{%
      [\expandonce{\cmdKV@phfmkprf@defaultproofname}]}%
    \csedef{phfthm@prfenv@#2@val@setdefaultprooftitle}{%
      \noexpand\def\noexpand\phfthm@val@prooftitle{%
        \expandonce{\cmdKV@phfmkprf@defaultproofname}}}%
  \fi
  \csedef{phfthm@prfenv@#2@val@parselabelandmkdisplayargs}##1{%
    \ifKV@phfmkprf@parselabel
      \expandonce\cmdKV@phfmkprf@parselabelcmd{##1}%
    \else
      \noexpand\phfthm@proof@noparselabel{##1}%
    \fi
    \noexpand\def\noexpand\phfthm@val@displayargs{[{%
        \expandafter\noexpand\csname phfthm@prfenv@#2@val@proofofname\endcsname
        {\noexpand\phfthm@val@prooftitle}%
      }]}%
  }
  \cslet{phfthm@prfenv@#2@val@proofofname}\cmdKV@phfmkprf@proofofname%
  \csdef{phfthm@prfenv@#2@val@pinproofanchor}{%
    \csname phfthm@prfenv@#2@val@refstepinternalcounter\endcsname%
    \if\relax\detokenize\expandafter{\phfthm@val@proofoflabel}\relax\else%
      \edef\phfthm@tmp@larg{{proof:\phfthm@val@proofoflabel}}%
      \expandafter\label\phfthm@tmp@larg%
    \fi
  }%
  %
  \csedef{phfthm@prfenv@#2@val@refstepinternalcounter}{%
    \noexpand\refstepcounter{\cmdKV@phfmkprf@internalcounter}}%
  \if\relax\detokenize\expandafter{\cmdKV@phfmkprf@displayenv}\relax%
    \csdef{phfthm@prfenv@#2@val@displayenvbegincmd}##1{}%
    \csdef{phfthm@prfenv@#2@val@displayenvendcmd}##1{}%
  \else
    \csedef{phfthm@prfenv@#2@val@displayenvbegincmd}##1{%
      \noexpand\begin{\csname phfthm@prfenv@#2@val@displayenv\endcsname}##1}%
    \csedef{phfthm@prfenv@#2@val@displayenvendcmd}##1{%
      \noexpand\end{\csname phfthm@prfenv@#2@val@displayenv\endcsname}##1}%
  \fi
  \def\phfthm@tmp@defcmd{\newenvironment}%
  \ifKV@phfmkprf@override\def\phfthm@tmp@defcmd{\renewenvironment}\fi%
  \phfthm@tmp@defcmd{#2}[1][\phfthm@NOPROOFARG]{%
    \def\phfthm@val@proofarg{##1}%
    \csname phfthm@hookproof@#2@start\endcsname%
    \ifx\phfthm@val@proofarg\phfthm@test@NOPROOFARG\relax%
      \def\phfthm@val@proofoflabel{}%
      \csname phfthm@prfenv@#2@val@setdefaultprooftitle\endcsname%
      \letcs\phfthm@val@displayargs{phfthm@prfenv@#2@val@defaultproofnameargs}%
    \else%
      \if\relax\detokenize{##1}\relax%
        \def\phfthm@val@proofoflabel{}%
        \csname phfthm@prfenv@#2@val@setdefaultprooftitle\endcsname%
        \def\phfthm@val@displayargs{[{%
            \csname phfthm@prfenv@#2@val@proofofname\endcsname
            {\phfthm@val@prooftitle}%
          }]}%
      \else
        \csname phfthm@prfenv@#2@val@parselabelandmkdisplayargs\endcsname{##1}%
      \fi
    \fi%
    \def\phfPinProofAnchor{%
      \csname phfthm@prfenv@#2@val@pinproofanchor\endcsname%
      \global\let\phfPinProofAnchor\relax}%
    \def\phfthmPinProofAnchor{\phfPinProofAnchor}%
    \def\x{\csname phfthm@prfenv@#2@val@displayenvbegincmd\endcsname}%
    \expandafter\x\expandafter{\phfthm@val@displayargs}%
    \csname phfthm@hookproof@#2@startafterdisplay\endcsname%
    \phfPinProofAnchor%
    \expandafter\noexpand\csname phfthm@hookproof@#2@startlast\endcsname%
  }%
  {%
    \expandafter\noexpand\csname phfthm@hookproof@#2@end\endcsname%
    \csname phfthm@prfenv@#2@val@displayenvendcmd\endcsname
    \expandafter\noexpand\csname phfthm@hookproof@#2@final\endcsname%
  }%
  \csdef{phfthm@hookproof@#2@start}{\phfthm@hookproof@startcommon{#2}}%
  \csdef{phfthm@hookproof@#2@startafterdisplay}{%
    \phfthm@hookproof@startafterdisplaycommon{#2}}%
  \csdef{phfthm@hookproof@#2@startlast}{\phfthm@hookproof@startlastcommon{#2}}%
  \csdef{phfthm@hookproof@#2@end}{\phfthm@hookproof@endcommon{#2}}%
  \csdef{phfthm@hookproof@#2@final}{\phfthm@hookproof@finalcommon{#2}}%
}
\def\phfthm@hookproof@startcommon#1{}
\def\phfthm@hookproof@startafterdisplaycommon#1{}
\def\phfthm@hookproof@startlastcommon#1{}
\def\phfthm@hookproof@endcommon#1{}
\def\phfthm@hookproof@finalcommon#1{}
\newenvironment{phfthm@proof@defaultdisplayenv}[1][\proofname]{%
  \par
  \pushQED{\qed}%
  \normalfont \topsep6\p@\@plus6\p@\relax
  \trivlist\item\relax
  \phfPinProofAnchor
  \phfthm@ProofTitleFmt{#1}%
  \phfthm@ProofTitleHspace
  \ignorespaces
}{%
  \popQED\endtrivlist\@endpefalse
}
\def\phfthm@ProofTitleFmt#1{%
  {\itshape #1.}%
}
\def\phfthm@ProofTitleHspace{%
  \hspace{1.5ex plus 0.5ex minus 0.2ex}%
}
\def\phfthm@proof@parselabel#1{%
  \phfthm@proof@parselabel@maybelabel#1\phfthm@proof@parselabel@END%
}
\def\phfthm@proof@parselabel@maybelabel{%
  \@ifnextchar*\phfthm@proof@parselabel@label\phfthm@proof@parselabel@title%
}
\def\phfthm@proof@parselabel@label*#1\phfthm@proof@parselabel@END{%
  \edef\phfthm@val@proofoflabel{\detokenize{#1}}%
  \def\phfthm@val@prooftitle{\phfthm@autoref{#1}}%
}
\def\phfthm@proof@parselabel@title#1\phfthm@proof@parselabel@END{%
  \def\phfthm@val@proofoflabel{}%
  \def\phfthm@val@prooftitle{#1}%
}
\def\phfthm@proof@noparselabel#1{%
  \def\phfthm@val@proofoflabel{}%
  \def\phfthm@val@prooftitle{#1}%
}
\def\phfthm@autoref{\ref}
\AtBeginDocument{%
  \@ifpackageloaded{hyperref}{\def\phfthm@autoref{\autoref}}{}
}
\providecommand\proofonname[2]{Proof on #2.}
\def\proofrefsize{\footnotesize}
\def\noproofref{%
  \def\phfthm@val@noproofref{1}%
  \ifdefined\phfthm@old@label \let\label\phfthm@old@label \fi%
}
\def\phfthm@proofref@warnnolabel{%
  \PackageWarning{phfthm}{No label provided for proof reference!}%
}
\def\phfthm@proofref@expandthmlabeltoarg#1{%
  \ifdefined\phfthm@val@noproofref\relax%
  \else%
    \providecommand\phfthm@val@thmlabel{}%
    \edef\phfthm@tmpa{{\phfthm@val@thmlabel}}%
    \expandafter\notblank\phfthm@tmpa{%
      \expandafter#1\phfthm@tmpa%
    }{%
      \phfthm@proofref@warnnolabel% no label provided
    }%
  \fi%
}
\def\phfthm@autorefnameof#1{%
  \expandafter\ifx\csname r@#1\endcsname\relax%
    \textbf{??}%
  \else%
    \expandafter\expandafter\expandafter\phfthm@HyPsd@autorefname%
        \csname r@#1\endcsname{}{}{}{}\@nil%
  \fi%
}
\def\phfthm@HyPsd@autorefname#1#2#3#4#5\@nil{%
  \ifx\\#4\\%
  \else%
    \phfthm@HyPsd@@autorefname#4.\@nil%
  \fi%
}
\def\phfthm@HyPsd@@autorefname#1.#2\@nil{%
  \ltx@IfUndefined{#1autorefname}{%
    \ltx@IfUndefined{#1name}{%
    }{%
      \csname#1name\endcsname%
    }%
  }{%
    \csname#1autorefname\endcsname%
  }%
}
\def\phfthm@min@pageref#1{%
  \ifcsname r@#1\endcsname%
    \expandafter\expandafter\expandafter\expandafter
    \expandafter\expandafter\expandafter\@car
    \expandafter\expandafter\expandafter\@gobble
    \csname r@#1\endcsname{}\@nil
  \else%
    0%
  \fi%
}
\def\phfthm@proofrefstyle@default@fmt#1#2{%
  {\parfillskip=0pt\relax%
    \hfil\null\hfil\null\hfil%
    \hbox{\proofrefsize{(\proofonname{#1}{#2})}}\par}%
}
\def\phfthm@proofrefstyle@default@fmtfarback#1#2{%
  \phfthm@proofref@impl@fmt{#1}{#2}}
\def\phfthm@proofrefstyle@default@fmtfarahead#1#2{%
  \phfthm@proofref@impl@fmt{#1}{#2}}
\def\phfthm@proofrefstyle@default@fmtcloseby#1#2{}
\newcommand\phfProofrefPageBackTolerance{1}
\newcommand\phfProofrefPageAheadTolerance{1}
\newcounter{phfthmInternalProofrefCounter}
\def\phfthm@proofrefstyle@default@main#1{%
  \refstepcounter{phfthmInternalProofrefCounter}%
  \label{internalproofref\thephfthmInternalProofrefCounter}%
  \edef\phfthm@proofref@tmp@proofpage{\phfthm@min@pageref{proof:#1}}%
  \edef\phfthm@proofref@tmp@thispage{%
    \phfthm@min@pageref{internalproofref\thephfthmInternalProofrefCounter}}%
  \edef\phfthm@proofref@tmp@pagediff{%
    \the\numexpr\phfthm@proofref@tmp@proofpage-\phfthm@proofref@tmp@thispage\relax}%
  \ifnum\numexpr\phfthm@proofref@tmp@pagediff\relax%
      <\numexpr-\phfProofrefPageBackTolerance\relax%
    \phfthm@proofref@impl@fmtfarback{#1}{\autopageref{proof:#1}}%
  \else%
    \ifnum\numexpr\phfthm@proofref@tmp@pagediff\relax%
        >\numexpr\phfProofrefPageAheadTolerance\relax%
      \phfthm@proofref@impl@fmtfarahead{#1}{\autopageref{proof:#1}}%
    \else%
      \phfthm@proofref@impl@fmtcloseby{#1}{\autopageref{proof:#1}}%
    \fi%
  \fi%
%%  [\number\numexpr\phfthm@proofref@tmp@proofpage\relax{} vs % DEBUG
%%  \number\numexpr\phfthm@proofref@tmp@thispage\relax or % DEBUG
%%  \number\numexpr1+\phfthm@proofref@tmp@thispage\relax] % DEBUG
}
\def\phfthm@proofrefstyle@default@setup{%
  \let\phfthm@proofref@impl@start\relax
  \let\phfthm@proofref@impl@afterlabel\@gobble
  \let\phfthm@proofref@impl@end\phfthm@proofrefstyle@default@main
  \let\phfthm@proofref@impl@fmtfarback\phfthm@proofrefstyle@default@fmtfarback
  \let\phfthm@proofref@impl@fmtfarahead\phfthm@proofrefstyle@default@fmtfarahead
  \let\phfthm@proofref@impl@fmtcloseby\phfthm@proofrefstyle@default@fmtcloseby
  \let\phfthm@proofref@impl@fmt\phfthm@proofrefstyle@default@fmt
}
\def\phfthm@proofrefstyle@margin@setup{%
  \phfthm@proofrefstyle@default@setup
  \let\phfthm@proofref@impl@afterlabel\phfthm@proofrefstyle@default@main
  \let\phfthm@proofref@impl@end\@gobble
  \def\phfthm@proofref@impl@fmt##1##2{%
    \leavevmode\marginpar{\proofrefsize{\proofonname{##1}{##2}}}%
  }%
}
\define@cmdkey{phfthmmkthmheading}{thmstyle}{}
\define@cmdkey{phfthmmkthmheading}{internalcounter}{}
\newcounter{phfthmheadingcounter}%
\newcommand\phfMakeThmheadingEnvironment[2][]{% }
  \def\cmdKV@phfthmmkthmheading@thmstyle{plain}%
  \def\cmdKV@phfthmmkthmheading@internalcounter{phfthmheadingcounter}%
  \setkeys{phfthmmkthmheading}{#1}%
  \csdef{phfthm@thmheading@#2@val@title}{$\langle$No Title Given$\rangle$}%
  \theoremstyle{\cmdKV@phfthmmkthmheading@thmstyle}%
  \newtheorem*{phfthm@internal@thmheading@#2}{%
    \csname phfthm@thmheading@#2@val@title\endcsname}%
  \newenvironment{#2}[1]{%}
    \csdef{phfthm@thmheading@#2@val@title}{##1}%
    \letcs\thephfthmheadingcounter{phfthm@thmheading@#2@val@title}%
    \csname phfthm@internal@thmheading@#2\endcsname%
    \hspace*{0pt}\refstepcounter{\cmdKV@phfthmmkthmheading@internalcounter}%
    \csname phfthm@hook@thmheading@#2@start\endcsname{##1}%
    \hskip 0em plus 0.5em minus 0em%
    \ignorespaces%
  }%
  {%
    \csname phfthm@hook@thmheading@#2@end\endcsname%
    \csname endphfthm@internal@thmheading@#2\endcsname%
  }%
  \csdef{phfthm@hook@thmheading@#2@start}##1{%
    \phfthm@hook@thmheading@start{##1}}%
  \csdef{phfthm@hook@thmheading@#2@end}{\phfthm@hook@thmheading@end}%
}
\def\phfthmMakeThmheadingEnvironment{\phfMakeThmheadingEnvironment}
\def\phfthm@hook@thmheading@start#1{}
\def\phfthm@hook@thmheading@end{}
\def\theoremname{Theorem}
\def\propositionname{Proposition}
\def\lemmaname{Lemma}
\def\corollaryname{Corollary}
\def\conjecturename{Conjecture}
\def\remarkname{Remark}
\def\definitionname{Definition}
\def\ideaname{Idea}
\def\questionname{Question}
\def\problemname{Problem}
\def\phfthm@def@thmset@optlist{}
\def\phfthm@def@thmset#1{%
  \appto\phfthm@def@thmset@optlist{#1,}\csdef{phfthm@thmset@#1}}
\def\phfthm@def@thmset@mktheorem{%
  \expandafter\phfMakeTheorem\phfthm@val@mkthmoptarg@theorem}
\def\phfthm@def@thmset@mkdefn{%
  \expandafter\phfMakeTheorem\phfthm@val@mkthmoptarg@defn}
\def\phfthm@thmset@{}
\phfthm@def@thmset{empty}{}
\phfthm@def@thmset{simple}{
  \phfthm@def@thmset@mktheorem{theorem}{\theoremname}
  \phfthm@def@thmset@mktheorem{proposition}{\propositionname}
  \phfthm@def@thmset@mktheorem{lemma}{\lemmaname}
  \phfthm@def@thmset@mktheorem{corollary}{\corollaryname}
  \phfthm@def@thmset@mkdefn{definition}{\definitionname}
}
\phfthm@def@thmset{default}{
  \phfthm@def@thmset@mktheorem{theorem}{\theoremname}
  \phfthm@def@thmset@mktheorem{proposition}{\propositionname}
  \phfthm@def@thmset@mktheorem{lemma}{\lemmaname}
  \phfthm@def@thmset@mktheorem{corollary}{\corollaryname}
  \phfthm@def@thmset@mktheorem{conjecture}{\conjecturename}
  \phfthm@def@thmset@mktheorem{remark}{\remarkname}
  \phfthm@def@thmset@mkdefn{definition}{\definitionname}
}
\phfthm@def@thmset{shortnames}{
  \phfthm@def@thmset@mktheorem{thm}{\theoremname}
  \phfthm@def@thmset@mktheorem{prop}{\propositionname}
  \phfthm@def@thmset@mktheorem{lem}{\lemmaname}
  \phfthm@def@thmset@mktheorem{cor}{\corollaryname}
  \phfthm@def@thmset@mktheorem{conj}{\conjecturename}
  \phfthm@def@thmset@mktheorem{rem}{\remarkname}
  \phfthm@def@thmset@mkdefn{defn}{\definitionname}
}
\phfthm@def@thmset{rich}{
  \phfthm@thmset@default
  \phfthm@def@thmset@mktheorem{idea}{\ideaname}
  \phfthm@def@thmset@mktheorem{question}{\questionname}
  \phfthm@def@thmset@mktheorem{problem}{\problemname}
}
\newcommand\phfLoadThmSet[3]{%
  \ifcsname phfthm@thmset@#3\endcsname%
    \edef\phfthm@val@mkthmoptarg@theorem{#1}%
    \edef\phfthm@val@mkthmoptarg@defn{#2}%
    \csname phfthm@thmset@#3\endcsname%
  \else%
    \PackageWarning{phfthm}{Unknown theorem set: `#3'!}%
  \fi%
}
\def\phfthmLoadThmSet{\phfLoadThmSet}
\define@key{phfthmpkg}{resetstyle}[]{%
  \KV@phfthmpkg@smallproofsfalse%
  \KV@phfthmpkg@qedsymbolblacksquarefalse%
  \KV@phfthmpkg@prooftitleitbffalse%
  \KV@phfthmpkg@sepcountersfalse%
  \KV@phfthmpkg@proofreffalse%
  \if\relax\detokenize{#1}\relax\else%
    \PackageError{phfthm}{'resetstyle' does not take any argument.}{You
      specified the 'resetstyle' argument and provided a value to it
      ('resetstyle=...'). However the 'resetstyle' option does not accept
      any value argument.}
  \fi%
}
\define@boolkey{phfthmpkg}{sepcounters}[true]{}
\KV@phfthmpkg@sepcountersfalse
\newif\ifKV@phfthmpkg@proofref
\KV@phfthmpkg@proofreffalse
\def\cmdKV@phfthmpkg@proofref@style{}
\define@key{phfthmpkg}{proofref}[]{%
  \ifblank{#1}{%
    \KV@phfthmpkg@proofreftrue%
    \def\cmdKV@phfthmpkg@proofref@style{default}%
  }{%
    \ifstrequal{#1}{false}{%
      \KV@phfthmpkg@proofreffalse%
    }{%
      \KV@phfthmpkg@proofreftrue%
      \def\cmdKV@phfthmpkg@proofref@style{#1}%
    }%
  }%
}
\def\@tmpa{\define@choicekey{phfthmpkg}{thmset}[\val]}
\edef\@tmpb{{\phfthm@def@thmset@optlist}}
\expandafter\@tmpa\@tmpb{%
  \xdef\cmdKV@phfthmpkg@thmset{\val}%
}
\def\cmdKV@phfthmpkg@thmset{default}
\define@cmdkey{phfthmpkg}{theoremstyle}{}
\def\cmdKV@phfthmpkg@theoremstyle{plain}
\define@cmdkey{phfthmpkg}{definitionstyle}{}
\def\cmdKV@phfthmpkg@definitionstyle{definition}
\define@boolkey{phfthmpkg}{proofenv}[true]{}
\define@boolkey{phfthmpkg}{smallproofs}[true]{}
\define@boolkey{phfthmpkg}{qedsymbolblacksquare}[true]{}
\define@boolkey{phfthmpkg}{prooftitleitbf}[true]{}
\KV@phfthmpkg@smallproofstrue
\KV@phfthmpkg@qedsymbolblacksquaretrue
\KV@phfthmpkg@proofenvtrue
\KV@phfthmpkg@prooftitleitbffalse
\define@boolkey{phfthmpkg}{thmheading}[true]{}
\define@cmdkey{phfthmpkg}{thmheadingstyle}{}
\KV@phfthmpkg@thmheadingtrue
\def\cmdKV@phfthmpkg@thmheadingstyle{plain}
\DeclareOptionX*{%
  \PackageWarning{phfthm}{Invalid option: `\CurrentOption'}%
}
\ProcessOptionsX<phfthmpkg>
\def\phfthm@val@mkthmopt@proofrefstyle{}
\ifKV@phfthmpkg@proofref
  \def\phfthm@proofref@style@default{}
  \def\phfthm@proofref@style@{}
  \def\phfthm@proofref@style@always{
    \def\phfProofrefPageBackTolerance{-1}
    \def\phfProofrefPageAheadTolerance{-1}
  }
  \def\phfthm@proofref@style@onlyifveryfar{
    \def\phfProofrefPageBackTolerance{2}
    \def\phfProofrefPageAheadTolerance{4}
  }
  \def\phfthm@proofref@style@margin{
    \def\phfthm@val@mkthmopt@proofrefstyle{proofrefstyle=margin}
  }
  \def\phfthm@proofref@style@longref{
    \def\proofonname##1##2{The proof of this \phfthm@autorefnameof{##1} can
      be found on ##2.}
    \def\phfthm@proofrefstyle@default@fmt##1##2{%
      \par{\raggedleft\proofrefsize{(\proofonname{##1}{##2})}\par}%
    }
  }
  \def\phfthm@proofref@style@off{
    \def\phfthm@val@mkthmopt@proofrefstyle{proofref=false}
  }
  \def\x{%
    \phfthm@internal@execattribs{phfthm@proofref@style@}{ProofRef Style}}
  \expandafter\x\expandafter{\cmdKV@phfthmpkg@proofref@style}
\fi
\newcounter{phfthmcounter}
\setcounter{phfthmcounter}{0}
\ifKV@phfthmpkg@sepcounters
  \def\phfthm@val@mkthmopt@counteropts{}
\else
  \def\phfthm@val@mkthmopt@counteropts{counter=phfthmcounter}
\fi
\phfLoadThmSet%
{[\phfthm@val@mkthmopt@counteropts,\phfthm@val@mkthmopt@proofrefstyle,
  thmstyle=\cmdKV@phfthmpkg@theoremstyle]}%
{[\phfthm@val@mkthmopt@counteropts,proofref=false,
  thmstyle=\cmdKV@phfthmpkg@definitionstyle]}%
{\cmdKV@phfthmpkg@thmset}
\def\phfthm@pkgopterr@require@proofenv#1{%
  \ifKV@phfthmpkg@proofenv\else%
    \PackageError{phfthm}{Option `#1' depends on `proofenv=true'}%
  \fi
}
\ifKV@phfthmpkg@smallproofs
  \phfthm@pkgopterr@require@proofenv{smallproofs}
  \apptocmd\phfthm@hookproof@startcommon{%
    \def\baselinestretch{1.2}\footnotesize}{}{%
    Failed to change command \string\phfthm@hook@start@proof}
\fi
\ifKV@phfthmpkg@qedsymbolblacksquare
  \phfthm@pkgopterr@require@proofenv{qedsymbolblacksquare}
  \RequirePackage{amssymb}
  \providecommand\filledsquare{\ensuremath{\blacksquare}}
  \renewcommand\qedsymbol{\text{\tiny\ensuremath{\filledsquare}}}
\fi
\ifKV@phfthmpkg@prooftitleitbf
  \phfthm@pkgopterr@require@proofenv{prooftitleitbf}
  \def\phfthm@ProofTitleFmt#1{{\itshape\bfseries#1.}}
\fi
\ifKV@phfthmpkg@proofenv
  \phfMakeProofEnv[override=true]{proof}
\fi
\ifKV@phfthmpkg@thmheading
  \phfMakeThmheadingEnvironment%
      [thmstyle=\cmdKV@phfthmpkg@thmheadingstyle]{thmheading}
\fi
\endinput
%%
%% End of file `phfthm.sty'.
