%
%  dfigs.sty
%
% following environments are defined
%
%  \begin{Dfigure}[loc]   \end{Dfigure}
%  \begin{Dtable}[loc]    \end{Dtable}
%  \begin{Dfigure*}[loc]  \end{Dfigure*}
%  \begin{Dtable*}[loc]   \end{Dtable*}
%
% following commands are defined
%
%  \Dtailfloats
%  \Dfigurecaptions
%  \Dtablecaptions
%  \Dmaketailfigures
%  \Dmaketailtables
%
\newif\ifDfloathere
\newif\ifDfloatcaps
\newif\ifDfiglabeling
\newif\ifDtablabeling
\newif\ifD@tmpif
\newif\ifD@dblfloat
\def\Dfigapp{Figure.}
\@ifundefined{Dwrite}{\input Dwrite.sty}{}
%
\begingroup \catcode `|=0 \catcode `(= 1
\catcode`)=2 \catcode `\{=12 \catcode `\}=12 \catcode`\\=12
|gdef|D@xfwrite(\end{Dfigure})   |gdef|D@xfbegin(\begin{Dfigure}[p])
|gdef|D@xtwrite(\end{Dtable})    |gdef|D@xtbegin(\begin{Dtable}[p])
|gdef|D@xdfwrite(\end{Dfigure*}) |gdef|D@xdfbegin(\begin{Dfigure*}[p])
|gdef|D@xdtwrite(\end{Dtable*})  |gdef|D@xdtbegin(\begin{Dtable*}[p])
|long|gdef|D@xfcomment#1\end{Dfigure}(|endD@floatcomment)
|long|gdef|D@xtcomment#1\end{Dtable}(|endD@floatcomment)
|long|gdef|D@xdfcomment#1\end{Dfigure*}(|endD@floatcomment)
|long|gdef|D@xdtcomment#1\end{Dtable*}(|endD@floatcomment)
|long|gdef|D@xfbcomment#1\end{Dfigurebody}(|endD@floatcommenta)
|long|gdef|D@xtbcomment#1\end{Dtablebody}(|endD@floatcommenta)
|endgroup
%
\@ifundefined{DselJ}{\gdef\DselJ#1#2{#1}}{}
\def\D@fcapapp{\DselJ{�ޤ�����}{Figure Captions}}
\def\D@tcapapp{\DselJ{ɽ������}{Table Captions}}
%
\def\D@floatcomment{\begingroup \let\do\@makeother \dospecials}
\def\endD@floatcomment{\endgroup\fi\endgroup}
\def\endD@floatcommenta{\endgroup\endgroup}
%
\def\Dfigurecaptions{%
  \@ifundefined{chapter}%
    {\section*{\D@fcapapp\@mkboth{\D@fcapapp}{\D@fcapapp}}}
    {\chapter*{\D@fcapapp\@mkboth{\D@fcapapp}{\D@fcapapp}}}
  \Dfloatherefalse \Dfloatcapstrue \def\D@floatsel{figure}
  \let\Depsfile\@gobble \c@figure=0
  \def\Dfigurebody{\D@floatcomment \D@xfbcomment}
  \ifDfiglabeling \let\Dlabel\label \else \let\Dlabel\@gobble \fi 
  \Dinsertfile
  \Dfiglabelingfalse}
%
\def\Dtablecaptions{%
  \@ifundefined{chapter}%
    {\section*{\D@tcapapp\@mkboth{\D@tcapapp}{\D@tcapapp}}}
    {\chapter*{\D@tcapapp\@mkboth{\D@tcapapp}{\D@tcapapp}}}
  \Dfloatherefalse \Dfloatcapstrue \def\D@floatsel{table}
  \let\Depsfile\@gobble \c@table=0
  \def\Dtablebody{\D@floatcomment \D@xtbcomment}
  \ifDtablabeling \let\Dlabel\label \else \let\Dlabel\@gobble \fi 
  \Dinsertfile
  \Dtablabelingfalse}
%
\def\Dtailfloats{%
  \Dfloatherefalse \Dfloatcapsfalse \def\D@floatsel{both}
  \Dopenfile{\jobname .fig}}
%
\def\Dmaketailfigures{%
  \Dfloatheretrue \Dfloatcapsfalse \def\D@floatsel{figure}
  \let\Depsfile\epsfile \c@figure=0
  \def\Dfigurebody{\center} \def\endDfigurebody{\endcenter}
  \ifDfiglabeling \let\Dlabel\label \else \let\Dlabel\@gobble \fi 
  \Dinsertfile
  \Dfiglabelingfalse}
%
\def\Dmaketailtables{%
  \Dfloatheretrue \Dfloatcapsfalse \def\D@floatsel{table}
  \let\Depsfile\epsfile \c@table=0 
  \def\Dtablebody{\center} \def\endDtablebody{\endcenter}
  \ifDtablabeling \let\Dlabel\label \else \let\Dlabel\@gobble \fi 
  \Dinsertfile
  \Dtablabelingfalse}
%
\Dfloatheretrue \Dfloatcapsfalse \def\D@floatsel{both}
\let\Depsfile\epsfile
\let\Dlabel\label
\Dfiglabelingtrue \Dtablabelingtrue
%
\long\def\Dcaption{\@dblarg{\D@caption}}
\long\def\D@caption[#1]#2#3{%
 \refstepcounter\@captype \D@mcaption{\@captype}[#1]{#2#3}}
%
\long\def\D@mcaption#1[#2]#3{
  \ifx\Dlabel\label
  \par\addcontentsline{\csname ext@#1\endcsname}{#1}
   {\protect\numberline{\csname the#1\endcsname}{\ignorespaces #2}} \fi
  \ifDfloatcaps
   \description \item[\csname fnum@#1\endcsname] #3 \enddescription
  \else
   \begingroup
    \@parboxrestore
    \normalsize
    \@makecaption{\csname fnum@#1\endcsname}{\ignorespaces #3}\par
  \endgroup
  \fi}
%
\def\D@float#1{
      \@ifnextchar[{\D@xfloat{#1}} %]
      {\edef\@tempa{\noexpand\D@xfloat{#1}[\csname fps@#1\endcsname]}
      \@tempa}}
%
\def\D@xfloat#1[#2]{
   \def\D@tmp{#1} \def\D@both{both}
   \ifx\D@floatsel\D@both \D@tmpiffalse
   \else \ifx\D@floatsel\D@tmp \D@tmpiffalse\else \D@tmpiftrue\fi\fi 
   \ifD@tmpif\D@floatcomment \D@xfloatcomment
   \else
   \ifDfloathere
     \ifD@dblfloat \@xfloat#1[#2]\hsize\textwidth\linewidth\textwidth
     \else \@xfloat#1[#2] \fi
   \else \ifDfloatcaps
     \def\@captype{#1}
   \else
     \if@filesw \immediate\write\D@auxfile{\D@xbegin}\fi
     \begingroup\D@setupwrite\D@writeX
   \fi\fi\fi}
%
\def\D@dblfloat{
     \if@twocolumn\D@dblfloattrue\else\D@dblfloatfalse\fi
     \D@float}
%
\def\endD@float{\ifDfloathere\end@float\fi}

\def\endD@dblfloat{\ifDfloathere\end@dblfloat\fi}
%
\def\Dfigure{%
  \let\D@xwrite\D@xfwrite\let\D@xbegin\D@xfbegin
  \let\D@xfloatcomment\D@xfcomment
  \D@dblfloatfalse
  \D@float{figure}}
\let\endDfigure\endD@float
\@namedef{Dfigure*}{%
  \let\D@xwrite\D@xdfwrite\let\D@xbegin\D@xdfbegin
  \let\D@xfloatcomment\D@xdfcomment
  \D@dblfloat{figure}}
\@namedef{endDfigure*}{\endD@dblfloat}
%
\def\Dtable{%
  \let\D@xwrite\D@xtwrite\let\D@xbegin\D@xtbegin
  \let\D@xfloatcomment\D@xtcomment
  \D@dblfloatfalse
  \D@float{table}}
\let\endDtable\endD@float
\@namedef{Dtable*}{%
  \let\D@xwrite\D@xdtwrite\let\D@xbegin\D@xdtbegin
  \let\D@xfloatcomment\D@xdtcomment
  \D@dblfloat{table}}
\@namedef{endDtable*}{\endD@dblfloat}
