%% File `ob-toclof.sty`
%%
%% Copyright (c) 2007-2013 Kangsoo Kim <karnes at ktug org>
%%
%% This work may be distributed and/or modified under the
%% conditions of the LaTeX Project Public License, either version 1.3c
%% 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.3c or later is part of all distributions of LaTeX
%% version 2006/05/20 or later.
%%
%%  oblivoir substyle. part of oblivoir, 
%% 
%% \newlistof{listoffigures}{lof}{\listfigurename}
%%  \kill@lastcounter{lofdepth}
%% \newlistentry[section]{figure}{lof}{0}
%%  \cftsetindents{figure}{0em}{2.3em}
%%
\if@toclofentry\else
\renewcommand{\put@bsintoc}{%
  \ifadd@bstotoc
    \ifnumber@bs\else
      \phantomsection
      \addcontentsline{toc}{section}{\abstractname}
    \fi
  \fi}

\def\addappheadtotoc{\addcontentsline{toc}{section}{\appendixtocname}}

\renewcommand{\newlistof}[3]{%
  \@namedef{ext@#2}{#2}
  \@ifundefined{c@#2depth}{\newcounter{#2depth}}{}
  \setcounter{#2depth}{1}
  \@namedef{#2mark}{\markboth{#3}{#3}}
  \@namedef{#1}{\@ifstar{\@nameuse{@star#2}}{\@nameuse{@plain#2}}}
  \@namedef{@star#2}{%
    \ensureonecol
    \par
    \begingroup
%%%      \parindent\z@ \parskip\cftparskip
      \@nameuse{@#2maketitle}
      \@starttoc{#2}%
    \endgroup
    \restorefromonecol}
  \@namedef{@plain#2}{%
    \ensureonecol
    \par
    \begingroup
%%%      \parindent\z@ \parskip\cftparskip
      \@nameuse{@#2maketitle}
      \phantomsection
      \addcontentsline{toc}{section}{#3}
      \@starttoc{#2}%
    \endgroup
    \restorefromonecol}
  \@namedef{@#2maketitle}{%
    \@nameuse{#2headstart}
   {\parindent\z@ \parskip\cftparskip
    \interlinepenalty\@M
    \@nameuse{print#2nonum}%
    \@nameuse{print#2title}{#3}%
    \@nameuse{#2mark}%
    \thispagestyle{chapter}%
    \@nameuse{after#2title}
   }
    \@afterheading}
%  \@namedef{#2headstart}{\chapterheadstart}
%  \@namedef{after#2title}{\afterchaptertitle}
%  \@namedef{print#2nonum}{\printchapternonum}
%  \@namedef{print#2title}##1{\printchaptertitle{##1}}
} % end \newlistof

\def\@chapter[#1]#2{%
  \ifx\ch@pt@c\m@m@empty % no optional args
    \def\f@rtoc{#1}%
    \def\f@rhdr{#1}%
  \else                  % at least one opt arg
    \def\f@rtoc{\ch@pt@c}%
    \nametest{#1}{#2}%
    \ifsamename          % one opt arg
      \def\f@rhdr{\ch@pt@c}%
    \else                % two opt args
      \def\f@rhdr{#1}%
    \fi
  \fi 
  \m@m@Andfalse
  \ifnum \c@secnumdepth >\m@ne
    \if@mainmatter
      \m@m@Andtrue
    \fi
  \fi
  \ifm@m@And
   \ifanappendix
    \refstepcounter{APPchapter}%
   \else
    \refstepcounter{chapter}%
   \fi
  \fi
  \chaptermark{\f@rhdr}
  \ifartopt
    \@makechapterhead{#2}%
    \@afterheading
  \else
    \insertchapterspace
    \if@twocolumn
      \@topnewpage[\@makechapterhead{#2}]%
    \else
      \@makechapterhead{#2}%
    \fi
    \@afterheading
  \fi
  \ifm@m@And
    \ifanappendix
      \addcontentsline{toc}{appendix}{%
       \protect\chapternumberline{\hchaptertitlehead}\f@rtoc}%
       \memappchapinfo{\thechapter}{\f@rtoc}{\f@rhdr}{#2}%
    \else
      \addcontentsline{toc}{section}{%
        \protect\chapternumberline{\hchaptertitlehead}\f@rtoc}%
       \memchapinfo{\hchaptertitlehead}{\f@rtoc}{\f@rhdr}{#2}%
    \fi
  \else
    \addcontentsline{toc}{section}{\f@rtoc}%
    \ifanappendix
      \memappchapinfo{}{\f@rtoc}{\f@rhdr}{#2}%
    \else
      \memchapinfo{\hchaptertitlehead}{\f@rtoc}{\f@rhdr}{#2}%
    \fi
  \fi
  \ifheadnameref\M@gettitle{\f@rhdr}\else\M@gettitle{\f@rtoc}\fi
%%% for chapter
  \ifanappendix
     \protected@edef\@currentlabel{\thechapter}%
  \fi
}

\newlistof{tableofcontents}{toc}{\contentsname}
\newlistof{listoffigures}{lof}{\listfigurename}
\newlistof{listoftables}{lot}{\listtablename}

\fi % of \if@toclofentry

\endinput
