% +--------------------------------------------------+
% | Typeset titlesec.tex to get the documentation.   |
% +--------------------------------------------------+
%
% Copyright (c) 1998-2016 by Javier Bezos.
% All Rights Reserved.
%
% This file is part of the titlesec distribution release 2.10.2
% -----------------------------------------------------------
%
% It 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
% and version 1.3 or later is part of all distributions of LaTeX
% version 2003/12/01 or later.
% 
% This work has the LPPL maintenance status "maintained".
% 
% The Current Maintainer of this work is Javier Bezos.
%
% Release
% ~~~~~~~

\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{titleps}[2016/03/15 v1.1.1 Page styles]

% This package is mainly a wrapper for the pagestyle macros provided
% by titlesec, so that they can be used without it.  Functionality is
% almost similar. First, some definitions from titlesec.

\newif\ifttl@ps
\newif\ifttl@toclabel
\ttl@toclabeltrue

\def\ttl@calcneg#1#2{%
  {\setlength\@tempskipa{#2}%
   #1{-\@tempskipa}}}

\newif\ifttl@premark % to be used in ttlps.def
\ttl@premarkfalse

\def\ttl@premark#1#2{%
  \protected@xdef\ttl@prevmarks{\ttl@marks}%
  \csname#1mark\endcsname{#2}%
  \gdef\ttl@prevmarks{\ttl@marks}}

\let\ttl@savemark\@empty

% Patching sectioning commands

\newcommand\TitlepsPatchSection{%
  \@ifstar{\ttl@setsec\@gobbletwo}%
          {\ttl@setsec\pretitlemark}}

\def\ttl@setsec#1#2{%
  \@ifundefined{#2}{}{%
    \expandafter\let\csname ttl@s@#2\expandafter\endcsname
      \csname#2\endcsname
    \@namedef{#2}{%
      \@ifstar{\ttl@presec@s{#2}}%
              {\@dblarg{\ttl@presec@x#1{#2}}}}}}%

% premark/gobble, sect-name, opt, title
\def\ttl@presec@x#1#2[#3]#4{%
  #1{#2}{#3}%
  \@nameuse{ttl@s@#2}[#3]{#4}}

\def\ttl@presec@s#1#2{%
  \gdef\ttl@savemark{\@nameuse{#1mark}{#2}}%
  \@nameuse{ttl@s@#1}*{#2}}

\def\ttl@atbegin{%
  \TitlepsPatchSection*{chapter}%
  \TitlepsPatchSection{section}%
  \TitlepsPatchSection{subsection}%
  \TitlepsPatchSection{subsubsection}%
  \TitlepsPatchSection{paragraph}%
  \TitlepsPatchSection{subparagraph}}

\AtBeginDocument{\ttl@atbegin}

% Package options
  
\DeclareOption{psfloats}{\let\ttl@replace\@empty} % a flag

\DeclareOption{outermarks}{%
  \def\ttl@titlemarks{\outertitlemarks}}
\DeclareOption{topmarks}{
  \def\ttl@titlemarks{\toptitlemarks}}
\DeclareOption{botmarks}{%
  \def\ttl@titlemarks{\bottitlemarks}}
\DeclareOption{innermarks}{%
  \def\ttl@titlemarks{\innertitlemarks}}
\DeclareOption{extramarks}{\let\ttl@fetchmark\@empty}
\DeclareOption{nopatches}{\let\ttl@atbegin\relax}

\ExecuteOptions{innermarks}

\ProcessOptions

% Load the package body

\let\newpagestyle\@empty
\let\renewpagestyle\@empty
\let\widenhead\@empty

\input ttlps.def

% Raise error if the following are used

\DeclareRobustCommand\ttl@naerror[1]{%
  \PackageError{titleps}%
    {#1\space only available in titlesec.\MessageBreak
     Consider using it instead of titleps}%
    {titleps provides a subset of the macros\MessageBreak
     for pagestyles defined in titlesec.}}

\def\ttl@setifthe#1{%
  \expandafter\protected@edef\csname ifthe#1\endcsname{%
    \ttl@naerror{\string\ifthe#1}}}

\ttl@setifthe{part}
\ttl@setifthe{chapter}
\ttl@setifthe{section}
\ttl@setifthe{subsection}
\ttl@setifthe{subsubsection}
\ttl@setifthe{paragraph}
\ttl@setifthe{subparagraph}

\endinput