%%
%% This is file `interfaces-titlesec.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% interfaces.dtx  (with options: `titlesec')
%% 
%% This is a generated file.
%% 
%% interfaces : 2010/11/21 v2.3 - interfaces : interfaces with keys for other packages (FC)
%% 
%% This work may be distributed and/or modified under the
%% conditions of the LaTeX Project Public License, either
%% version 1.3 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
%% 
%% This work consists of the main source file interfaces.dtx
%% and the derived files
%%     interfaces.sty, interfaces.pdf, interfaces.ins,
%%     interfaces-base.sty,
%%     interfaces-LaTeX.sty,
%%     interfaces-tikz.sty,
%%     interfaces-titlesec.sty,
%%     interfaces-hyperref.sty,
%%     interfaces-bookmark.sty,
%%     interfaces-hypbmsec.sty,interfaces-hypbmsec.code.tex,
%%     interfaces-fancyhdr.sty,
%%     interfaces-marks.sty,
%%     interfaces-tocloft.sty,
%%     interfaces-makecell.sty,
%%     interfaces-enumitem.sty,
%%     interfaces-truncate.sty,
%%     interfaces-appendix.sty,
%%     interfaces-embedfile.sty,
%%     interfaces-environ.sty,
%%     interfaces-umrand.sty,
%%     interfaces-scrlfile.sty,
%%     interfaces-pgfkeys.sty,
%%     interfaces-etoolbox.sty
%% 
%% interfaces: interfaces with keys for other packages (FC)
%% Copyright (C) 2010 by Florent Chervet <florent.chervet@free.fr>
%% 
\ProvidesPackage{interfaces-titlesec}
   [2010/11/15 v2.1 pgfkeys macros for titlesec (FC)]
\RequirePackage{interfaces-base}
\RequirePackage{auxhook}% <fix for \ttlp@append (odd/even pages)>
\itf@Check@Package{titlesec}
\itf@pgfkeys
%%   t i t l e s e c   "p a t c h e s"
\robustify\titleclass   \robustify\titleformat  \robustify\titlespacing
\AddLineBeginMainAux{%
   \string\providecommand\string\ttlp@append[2]{}%
}
\BeforeFile*{ttlkeys.def}{%
   \catcode32 9\relax                   % ignore spaces
   \count@\endlinechar\endlinechar\m@ne % and line feeds
}
\AfterFile*{ttlkeys.def}{% restore spaces and line feeds
   \catcode32 10\relax
   \endlinechar\count@
}
%%-----------------------------------------------------------------------------
%% runinifempty =>  like hang but no paragraph break (like runin) if title is empty
\def\ttlh@runinifempty{%
   \csname ttlh@\ifx\ttl@savetitle\@empty runin\else hang\fi\endcsname
}% \ttlh@runinifempty
\newrobustcmd*\sectionformat[1]{\@ifstar
   {\itf@sectionformat{#1}{/*}}
   {\itf@sectionformat{#1}{}}%
}% \sectionformat
\def\itf@sectionformat#1#2{\@testopt
   {\expandafter\expandafter\expandafter%
      \itf@sectionf@rmat\expandafter\@gobble\string#1\@nil{#2}}{}%
}% \sectionformat
\def\itf@sectionf@rmat#1\@nil#2[#3]#4{\itf@pgfkeys\ifblank{#3}
   {\pgfqkeys{/itf/titlesec/#1#2}
      {/itf/titlesec/@setup={#1}{#2},#4,/itf/titlesec/@update={#1}{#2}}}
   {\pgfqkeys{/itf/titlesec/#1#2}
      {/itf/titlesec/@setup={#1}{#2},#4,shape={#3},/itf/titlesec/@update={#1}{#2}}}%
}% \itf@ttl@sectionformat
%% private keys @setup and @update
\pgfqkeys{/itf/titlesec}{%
   @setup/.code 2 args=\itf@ttl@setup{#1}{#2},%
   @update/.code 2 args=\expandafter\itf@ttl@update
                  \csname#1\endcsname{/itf/titlesec/#1}{#2}%
}
\newrobustcmd*\itf@ttl@setup[2]{%
   \pgfkeysifdefined{/itf/titlesec/#1#2/shape}{}
      {\itf@ttl@newsection{#1}{#2}}%
   \ifcsundef{ttls@#1#2}{}% no previous spacing settings
      {\expandafter\expandafter\expandafter%
      \itf@ttl@getspacing\csname ttls@#1#2\endcsname{/itf/titlesec/#1#2}}%
   \ifcsundef{ttlf@#1#2}{}% no previous format settings
      {\expandafter\expandafter\expandafter%
      \itf@ttl@getformat\csname ttlf@#1#2\endcsname{/itf/titlesec/#1#2}}%
}% \itf@ttl@setup
\def\itf@ttl@setkey#1#2{\begingroup
   \def\x{\pgfkeysvalueof{#1}}\def\y{#2}%
   \expandafter\endgroup\ifx\x\y\else
      \pgfkeyssetvalue{#1}{#2}\fi
}% \itf@ttl@setkey
\def\itf@ttl@getspacing#1#2#3#4#5#6{%
   \itf@ttl@setkey{#6/left}{#1}%
   \itf@ttl@setkey{#6/right}{#2}%
   \itf@ttl@setkey{#6/top}{#3}%
   \itf@ttl@setkey{#6/bottom}{#4}%
   \itf@ttl@setkey{#6/indent first}{#5}%
}% \itf@ttl@getspacing
\def\itf@ttl@getformat#1#2{%
   \csname ltx@\ifx\pgfkeysvalueof#1first\else second\fi oftwo\endcsname
      {\itf@ttl@get@format{}}
      {\itf@ttl@get@format{#1}{#2}}%
}% \itf@ttl@getformat
\def\itf@ttl@get@format#1#2#3#4#5#6#7{%
   \if\relax\detokenize{#1}\relax\else
   \pgfkeysEsetvalue{#7/shape}{\expandafter\itf@strip@at\string#1}%
   \fi
   \itf@ttl@setkey{#7/font}{#2}%
   \itf@ttl@setkey{#7/label}{#3}%
   \itf@ttl@setkey{#7/sep}{#4}%
   \itf@ttl@setkey{#7/before}{#5}%
   \itf@ttl@setkey{#7/after}{#6}%
}% \itf@ttl@get@format
\newrobustcmd*\itf@ttl@update[3]{%
   \ifblank{#3}
      {\ttl@getkeys{#1}{titlesec}}
      {\ttl@getkeys{name=#1,numberless}{titlesec}}%
   \pgfkeysgetvalue{#2#3/shape}\itf@tp
   \ifcsundef{ttlh@\itf@tp}
      {\begingroup \makeatletter
      \InputIfFileExists{\itf@tp.tss}{}{%
      \PackageError{titlesec}{Unknown shape}%
         {Shapes are defined in files with extension tss\MessageBreak
         Either you have misspelled the shape\MessageBreak
         or there is no a \itf@tp.tss file}}%
      \endgroup}
      {}%
   \ifttl@explicit\@temptokena{\csdef{ttlf@\ttl@a}##1}%
   \else\@temptokena{\csdef{ttlf@\ttl@a}}%
   \fi
   \the\@temptokena{%
      \pgfkeysvalueof{#2#3/shape@cs}%
      {\pgfkeysvalueof{#2#3/font}}%
      {\pgfkeysvalueof{#2#3/label}}%
      {\pgfkeysvalueof{#2#3/sep}}%
      {\pgfkeysvalueof{#2#3/before}}%
      {\pgfkeysvalueof{#2#3/after}}}%
   \csname ttl@compat\ttl@a\endcsname
   \ttl@spacing@ii
      {\pgfkeysvalueof{#2#3/indent first}}%
      {\pgfkeysvalueof{#2#3/left}}%
      {\pgfkeysvalueof{#2#3/top}}%
      {\pgfkeysvalueof{#2#3/bottom}}%
      [\pgfkeysvalueof{#2#3/right}]%
}% \itf@ttl@update
%%----------------------------------------------------------------------------
%%   t i t l e c l a s s
\newrobustcmd*\itf@ttl@titleclass{\@ifstar
   {\itf@ttl@titleclass@i*}
   {\itf@ttl@titleclass@i{}}%
}% \itf@ttl@titleclass
\def\itf@ttl@titleclass@i#1#2#3[#4]#5\@nil{\ifblank{#4}
   {%
      \expandafter\titleclass\csname#2\endcsname{#3}%
   }
   {%
      \expandafter\titleclass\csname#2\endcsname{#3}[{#4}]% #4 = sup-level
      \if\relax#1\relax % not starred
         \expandafter\expandafter\expandafter%
            \itf@ttl@titleclass@ii\expandafter\@gobble\string#4\relax{#2}% \@addtoreset...
      \fi
   }%
   \expandafter\providecommand\csname l@#2\endcsname[2]{}% no entry in toc
}% \itf@ttl@titleclass@i
\def\itf@ttl@titleclass@ii#1\relax#2{%
   \ifcsundef{c@#2}
      {\newcounter{#2}[{#1}]}% creates counter for #1
      {\@addtoreset{#2}{#1}}%
   \csxdef{the#2}{%
      \expandafter\noexpand\csname the#1\endcsname
      .\noexpand\@arabic\expandafter\noexpand\csname c@#2\endcsname
   }% \the#2
   \ifcsundef{l@#1}{}{%
      \expandafter\providecommand\csname l@#2\endcsname[2]{%
         \csname l@#1\endcsname{##1}{##2}%
      }% \l@#2 = \l@newsection is (by default) the same as \l@sup-level
   }%
}% \itf@ttl@titleclass@ii
%%-----------------------------------------------------------------------------
%%   C r e a t i n g   n e w   s e c t i o n s
\def\itf@ttl@createsection#1{% sectionning command undefined: temporarily defined
   \expandafter\titleclass\csname#1\endcsname{straight}[*]%     in straight class
   \itf@AfterPackage{hypbmsec}{%
      \AfterPreamble{%
         \csletcs{hbs@#1}{#1}%
         \csxdef{#1}{\noexpand\hbs@do\expandafter\noexpand\csname hbs@#1\endcsname}%
      }%
   }%
   \itf@AfterPackage{interfaces-tocloft}{%
      \itf@cft@newsection{#1}{toc}%
   }%
   \itf@AfterPackage{interfaces-hypbmsec}{%
      \expandafter\let\csname last#1title\endcsname\relax
      \expandafter\let\csname last#1bookmark\endcsname\relax
      \expandafter\let\csname last#1toc\endcsname\relax
   }%
}% \itf@ttl@createsection
%%-----------------------------------------------------------------------------
%%   D e f i n i n g   k e y s   f o r   e a c h   s e c t i o n
\def\itf@ttl@newsection#1#2{% #1=section, #2=/* or empty
   \ifcsundef{#1}% sectionning command undefined: temporarily defined in straight class
      {\itf@ttl@createsection{#1}}
      {}%
   \ifblank{#2}{%
      \pgfqkeys{/itf/titlesec/#1}{% these keys do not exist for starred sections
         class/.code=\itf@ttl@titleclass{#1}##1[]\@nil,% with \@addtoreset
            class/.value required,%                      if sup-level is given
            class*/.code=\itf@ttl@titleclass*{#1}##1[]\@nil,% without \@addtoreset
            class*/.value required,%                          even if sup-level is given
         shape/.initial=,% initial shapes set by titlesec.sty for not numbered sections.
         the#1/.store in cs=the#1,%
            the#1/.default=\pgfkeysvalueof{/itf/titlesec/#1/label},%
      }}
      {% starred section: unless titlesec, we do not put the default shape to hang,
      \pgfkeysifdefined{/itf/titlesec/#1/shape}%but to the shape of the not starred
         {\pgfkeysgetvalue{/itf/titlesec/#1/shape}\itf@tp}%     sectionning command
         {\def\itf@tp{hang}}%
      \pgfkeyslet{/itf/titlesec/#1#2/shape}\itf@tp%
      }%
   \pgfqkeys{/itf/titlesec/#1#2}{%
      shape/.value required,%
      shape@cs/.initial=
         \ifdefined\itf@last@from@next\itf@last@from@next{#1}\fi % interfaces-hypbmsec
         \csname ttlh@\pgfkeysvalueof{/itf/titlesec/#1#2/shape}\endcsname,% constant
         shape@cs/.is private=interface-titlesec,% constant
      font/.store as code,%
         format/.alias*=font,%
      label/.store as code,%
      sep/.estore as glue,%
         labelsep/.alias*=sep,%
      before/.store as code,%
      after/.store as code,%
      indent first/.true=\pgfkeyssetvalue{/itf/titlesec/#1#2/indent first}{\@ne},%
      indent first/.false=\pgfkeyssetvalue{/itf/titlesec/#1#2/indent first}{\z@},%
         identfirst/.alias=indent first,%
         indent first=true,%
      left/.estore as glue,%
      top/.estore as glue,%
      bottom/.estore as glue,%
      right/.estore as glue,%
      break/.code=\ifblank{##1}
                     {\cslet{#1break}\@empty}
                     {\protected\csdef{#1break}{##1}},%
         break*/.code=\protected\apptocs{#1break}{##1},%
         break+/.alias=break*,%
      mark/.code=\ifblank{##1}
                  {\cslet{#1mark}\@gobble}
                  {\protected\long\csdef{#1mark}####1{##1}},%
         mark/.default=,%
   }% \pgfkeys
   \ifblank{#2}{% no default marks for stared (numberless) \section*
   \itf@AfterPackage{interfaces-marks}{% requires interfaces-marks
      \pgfkeys{/itf/titlesec/#1/mark/.default=\marksthe{#1}{##1}}%
   }% AfterPackage interfaces-mark
   \itf@AfterPackage{interfaces-bookmark}{% requires interfaces-bookmark
   \pgfqkeys{/itf/titlesec/#1}{% does not exist for starred sections
      bookmark/.is multiple choice,%
      bookmark/level/.estore in cs=toclevel@#1,% depth of the bookmark
         bookmark/level/.default=\ifcsvoid{ttll@#1}{99}{\csuse{ttll@#1}},%
         bookmark/level/.blank=\ifcsvoid{toclevel@#1}
            {\ifcsvoid{ttll@#1}{99}{\csuse{ttll@#1}}}{\csuse{toclevel@#1}},%
         bookmark/toclevel/.alias=bookmark/level,%
      bookmark/bold/.code=\ifblank{##1}
         {\pgfkeyslet{/itf/titlesec/#1/bookmark/bold}\@empty}
         {\pgfkeyssetvalue{/itf/titlesec/#1/bookmark/bold}{bold=##1,}},%
         bookmark/bold/.default=true,%
      bookmark/bold*/.code=\ifblank{##1}
         {\pgfkeyslet{/itf/titlesec/#1/bookmark/bold*}\@empty}
         {\pgfkeyssetvalue{/itf/titlesec/#1/bookmark/bold*}{bold*=##1,}},%
         bookmark/bold*/.default=true,%
      bookmark/italic/.code=\ifblank{##1}
         {\pgfkeyslet{/itf/titlesec/#1/bookmark/italic}\@empty}
         {\pgfkeyssetvalue{/itf/titlesec/#1/bookmark/italic}{italic=##1,}},%
         bookmark/italic/.default=true,%
      bookmark/italic*/.code=\ifblank{##1}
         {\pgfkeyslet{/itf/titlesec/#1/bookmark/italic*}\@empty}
         {\pgfkeyssetvalue{/itf/titlesec/#1/bookmark/italic}{italic*=##1,}},%
         bookmark/italic*/.default=true,%
      bookmark/color/.code=\ifblank{##1}
         {\pgfkeyslet{/itf/titlesec/#1/bookmark/color}\@empty}
         {\pgfkeyssetvalue{/itf/titlesec/#1/bookmark/color}{color=##1,}},%
         bookmark/color/.default=,%
      bookmark/color*/.code=\ifblank{##1}
         {\pgfkeyslet{/itf/titlesec/#1/bookmark/color*}\@empty}
         {\pgfkeyssetvalue{/itf/titlesec/#1/bookmark/color*}{color*=##1,}},%
         bookmark/color*/.default=,%
      bookmark/on/.code=\pgfkeyssetvalue{/itf/titlesec/#1/bookmark/on}{disable=false,},%
         bookmark/on/.value forbidden,%
      bookmark/off/.code=\pgfkeyssetvalue{/itf/titlesec/#1/bookmark/on}{disable=true,},%
         bookmark/off/.value forbidden,%
         bookmark/none/.alias=bookmark/off,%
      bookmark/style/.code=\ifblank{##1}
            {\pgfkeyslet{/itf/titlesec/#1/bookmark/style}\@empty}
            {\pgfkeyssetvalue{/itf/titlesec/#1/bookmark/style}{style=##1,}},%
         bookmark/style/.default=,%
      bookmark/.unknown/.code=\pgfkeysEsetvalue{/itf/titlesec/#1/bookmark/other}
                                                {\pgfkeyscurrentname={##1}},%
      bookmark/bold/.initial=,%
      bookmark/bold*/.initial=,%
      bookmark/italic/.initial=,%
      bookmark/italic*/.initial=,%
      bookmark/color/.initial=,%
      bookmark/color*/.initial=,%
      bookmark/on/.initial=,%
      bookmark/style/.initial=,%
   }}% \AfterPackage*{interfaces-bookmark}
   }% not starred (numberless) \section
   {}% starred/numberless \section*: do not create the keys
}% \itf@ttl@newsection
%% bookmarks styles for sectionning commands:
\@makeother\#
\itf@AfterPackage{interfaces-bookmark}{%
   \itf@patch\itf@preapptocmd\addcontentsline             % #2=section name in
      {\begingroup\itf@ttl@BKM{/itf/titlesec/#2/bookmark}}%   \addcontentsline
      {\endgroup}
      {\PackageInfo{interfaces-titlesec}
         {Command \string\addcontentsline\space successfully patched!}}
      {\PackageWarning{interfaces-titlesec}
         {Patch of \string\addcontentsline\space failed
         \MessageBreak bookmark-style specs for sections
         \MessageBreak will be unavailable}}%
}% AfterPackage interfaces-bookmark
\catcode`\#=6
\def\itf@ttl@BKM#1{%
   \pgfkeysifdefined{#1/.@cmd}
      {%
      \edef\itf@tp{% do nothing if the keys are not set (shortcut)
         \pgfkeysvalueof{#1/bold}%
         \pgfkeysvalueof{#1/bold*}%
         \pgfkeysvalueof{#1/italic}%
         \pgfkeysvalueof{#1/italic*}%
         \pgfkeysvalueof{#1/color}%
         \pgfkeysvalueof{#1/color*}%
         \pgfkeysvalueof{#1/on}%
         \pgfkeysvalueof{#1/style}}%
      \ifx\itf@tp\@empty
      \else
         \global\pgfkeyslet{#1/bold*}\@empty
         \global\pgfkeyslet{#1/italic*}\@empty
         \global\pgfkeyslet{#1/color*}\@empty
         \expandafter\bookmarksetup\expandafter{\itf@tp}%
         \pgfkeysifdefined{/itf/bookmark/*}%
            {% \bookmarksetup{color*=} overwrites \sectionformat...{bookmark/color*=}
            \pgfkeysgetvalue{/itf/bookmark/*}\itf@tp
            \expandafter\bookmarksetup\expandafter{\itf@tp}%
            }
            {}%
      \fi}
      {}%
}% \itf@ttl@BKM
%%-----------------------------------------------------------------------------
%%   b o t t o m t i t l e s
\newrobustcmd*\bottomtitles{\@ifnextchar\bgroup
   \itf@setbottomtitlespace
   {\afterassignment\itf@set@bottomtitle@space\itf@sk}%
}% \bottomtitles
\def\itf@setbottomtitlespace#1{%
   \@defaultunits\itf@sk#1\textheight\relax\@nnil
   \itf@set@bottomtitle@space
}% \itf@setbottomtitlespace
\def\itf@set@bottomtitle@space{\edef\bottomtitlespace{\the\itf@sk}}
\endinput
%%
%% End of file `interfaces-titlesec.sty'.
