\usepackage {hyperref}
\edef\hyper@quote{\string"}
\edef\hyper@sharp{\string#}
\def \softlink #1#2{\special 
  {html:<A href=\hyper@quote\hyper@sharp#1\hyper@quote>}#2\special
  {html:</A>}}
\def \softtarget #1#2{\special
  {html:<A name=\hyper@quote#1\hyper@quote>}#2\special
  {html:</A>}}

\newtheorem{theorem}{Theorem}
\newtheorem {lemma}{Lemma}

\usepackage {exercise}
\def \pdf@hyperlink {\softlink}
\def \pdf@hypertarget {\softtarget}

\def \@thm #1#2{%
  \refstepcounter {#1}
  \xdef \ThmName {\@currenvir}%
  \xdef \ThmLabel {\@currentlabel}%
  \@ifnextchar [{\@ythm {#1}{#2}}{\@xthm{#1}{#2}}%
}

\def \capitalize #1{\uppercase {#1}}
\newanswer {proof}
  {\def \theExercise {\ThmName}\def \theQuestion {\ThmLabel}%
   \if@answer@later
       \if@answer@anchor \AnswerLink{\hbox {(See proof in the Appendix)}}\fi%
   \else \def \AnswerName {Proof}\fi
   \pdf@hypertarget {Thm-\ThmName.\ThmLabel}{}}
  {}
  {\trivlist \item [\hskip \labelsep {\underline {Proof}:}]}
  {\penalty 100\hfill\rule{2mm}{2mm}\endtrivlist\@doendpe}
  {{\ThmName}{\ThmLabel}}
  [2]
  {\subsection* 
        {\pdf@hypertarget {Ans-#1.#2}{Proof} of 
         \pdf@hyperlink {Thm-#1.#2}{\capitalize #1 #2}}%
   \nobreak
   }
  {}

\newcounter{detailsCounter}
\setcounter{detailsCounter}{1}
\newanswer{details}{%
  \def\theExercise{Details}%
  \def\theQuestion{\thedetailsCounter}%
  \if@answer@later
    \if@answer@anchor \AnswerLink{\hbox {(See details (\romannumeral\thedetailsCounter) in the Appendix)}}\fi%
  \else \def \AnswerName{Details}\fi
  \pdf@hypertarget{body/details/\thedetailsCounter}{}%
  \addtocounter{detailsCounter}{1}}
  {}
  {\trivlist \item [\hskip \labelsep {\underline {Proof}:}]}
  {\penalty 100\hfill\rule{2mm}{2mm}\endtrivlist\@doendpe}
  {{\thepage}{\thedetailsCounter}}
  [2]
  {\subsection* 
        {\pdf@hypertarget {Ans-Details.#2}{Details (\romannumeral#2)} of
         \pdf@hyperlink {body/details/#2}{page #1}}%
   \nobreak
   }
  {}
