\RequirePackage{ifthen}

\newcounter{ddenture}
\newcounter{maxindent}
\newcounter{ddenparn}
\newcounter{dtemp}
\newcounter{dlinenum}
\newcounter{uselinenum}

\newcommand\T{\Ta{0.25in}}
\newcommand\Ta[1]{%
  \addtocounter{ddenture}{1}%
  \ifnum \value{ddenture} > \value{maxindent}%
     \hspace{#1}\=%
     \addtocounter{maxindent}{1}%
  \else%
     \>%
  \fi}
\newcommand\R{%
  \addtocounter{ddenture}{1}%
  \=%
  \ifnum \value{ddenture} > \value{maxindent}%
    \addtocounter{maxindent}{1}%
  \fi}

\newdimen\dlnmspace
\setbox0=\hbox{999}
\dlnmspace=\wd0
\newdimen\dlafspace
\dlafspace=0.1in
\renewcommand\thedlinenum{
{\tiny \arabic{dlinenum}}%
}
\newcommand\li{%
  \addtocounter{dlinenum}{1}%
  \parbox[b]{\dlnmspace}{\hfill\thedlinenum}%
  \hspace{\dlafspace}%
}

\newcommand\Bop{%
  \addtocounter{ddenparn}{1}%
  \B %
}
\newcommand\Bcl{%
  \addtocounter{ddenparn}{-1}%
  \B %
}

\newcommand\B{ \\ %
  \setcounter{ddenture}{0}%
  \setcounter{dtemp}{0}%
  \ifnum \value{uselinenum}>0%
    \li%
  \fi%
  \whiledo{\value{dtemp} < \value{ddenparn}}{\T \addtocounter{dtemp}{1}}%
}

\newenvironment{dindent}[1][0.25in]{%
\setcounter{ddenture}{0}%
\setcounter{ddenparn}{0}%
\setcounter{maxindent}{0}%
\setcounter{dlinenum}{0}%
\renewcommand\T{\Ta{#1}}%
\setcounter{uselinenum}{1}%
  \begin{tabbing}%
    \li%
    }{%
  \end{tabbing}%
  }
\newenvironment{dindent*}[1][0.25in]{%
\setcounter{ddenture}{0}%
\setcounter{ddenparn}{0}%
\setcounter{maxindent}{0}%
\setcounter{dlinenum}{0}%
\renewcommand\T{\Ta{#1}}%
\setcounter{uselinenum}{0}%
  \begin{tabbing}%
    }{%
  \end{tabbing}%
  }
