%%% figcut package: figures (and tables) in their own HTML page
%%%With contributions by Gilles Gregoire
\newif\iffigcut@show\figcut@showtrue
\DeclareOption{show}{\figcut@showtrue}%Repeat caption in main text, with link
\DeclareOption{noshow}{\figcut@showfalse}%Do not
\ProcessOptions*
%% Some pointers to original figure env.
\let\figcut@figure\figure
\let\endfigcut@figure\endfigure
\let\figcut@table\table
\let\endfigcut@table\endtable
%%Inside figure label names are recorded with a global \def
\let\figcut@label\label
\newcommand{\@def@figlabel}[1]{\global\def\csname #1@figlabel\endcsname{}}
\newcommand{\figlabel}[1]
{\@auxdowrite{\@print{\@def@figlabel}\{#1\}}%
\global\def\current@figlabel{#1}%
\figcut@label{#1}}
%%So that we can format ref to figures differently.
\let\figcut@ref\ref
\let\figcut@locref\@locref
\newcommand{\fig@locref}[2]{\@aelement{href="\@print{#}#1" target="_new"}{#2}}
\newcommand{\figref}[1]
{\let\@locref\fig@locref\figcut@ref{#1}\let\@locref\figcut@locref}
\renewcommand{\ref}[1]
{\@ifundefined{#1@figlabel}{\figcut@ref{#1}}{\figref{#1}}}
%%My custom figure
%change \hva@caption
\let\figcut@caption\hva@caption
\newsavebox{\figcut@caption@box}
\renewcommand{\hva@caption}[2]
{\global\def\figcut@caption@text{#2}%
\gsbox{\figcut@caption@box}
{\figcut@caption{#1}{#2}}\usebox{\figcut@caption@box}}
\newcommand{\figcut@show}[1]
{\@hr{.5\linewidth}{1pt}%
\begin{center}%
\renewcommand{\label}[1]{}\renewcommand{\aname}[2]{##2}%
\fig@locref{\current@figlabel}
{\csname#1name\endcsname~\csname the#1\endcsname}: \figcut@caption@text%
\end{center}%
\@hr{.5\linewidth}{1pt}}
%change figure env
\newsavebox{\figcut@figure@box}
\newenvironment{figcut@myfig}[1][]
  {\begin{lrbox}{\figcut@figure@box}\let\label\figlabel\begin{figcut@figure}[]}
  {\end{figcut@figure}\end{lrbox}%
  \begin{cutflow}{\usebox{\figcut@caption@box}}\@out@par{\usebox{\figcut@figure@box}}\end{cutflow}%
\iffigcut@show\figcut@show{figure}\fi}
\let\figure\figcut@myfig
\let\endfigure\endfigcut@myfig
\let\figure*\figcut@myfig
\let\endfigure*\endfigcut@myfig
%change table env
\newenvironment{figcut@mytab}[1][]
  {\begin{lrbox}{\figcut@figure@box}\let\label\figlabel\begin{figcut@table}[]}
  {\end{figcut@table}\end{lrbox}%
  \begin{cutflow}{\usebox{\figcut@caption@box}}\@out@par{\usebox{\figcut@figure@box}}\end{cutflow}%
\iffigcut@show\figcut@show{table}\fi}
\let\table\figcut@mytab
\let\endtable\endfigcut@mytab
\let\table*\figcut@mytab
\let\endtable*\endfigcut@mytab

