\NeedsTeXFormat{LaTeX2e}

\ProvidesPackage{TeXOPE}[2019/06/08 Operation que du Plaisir, V1.0]
\RequirePackage{ragged2e}
\RequirePackage{eurosym}
\RequirePackage[utf8x]{inputenc}
\RequirePackage[T1]{fontenc}
\RequirePackage[french,english]{babel}
%\RequirePackage[showframe,tmargin=2cm,bmargin=1.5cm]{geometry}
\RequirePackage[tmargin=2cm,bmargin=1.5cm]{geometry}
\RequirePackage[svgnames]{xcolor}
\RequirePackage{graphicx}
\RequirePackage{verse}
\RequirePackage{fancyhdr}
\RequirePackage{lastpage}
\RequirePackage{realboxes}
\RequirePackage{verbatim}
\RequirePackage{tabularx}
%\RequirePackage{multicolumn}
\RequirePackage{multicol}
\RequirePackage{multirow}
\RequirePackage[explicit]{titlesec}
\RequirePackage{hologo}
\RequirePackage[colorlinks,linkcolor=myLinkColor]{hyperref}
\RequirePackage{transparent}
\RequirePackage[absolute,overlay,verbose]{textpos}
\RequirePackage{ifthen}
\RequirePackage{layout}
\RequirePackage{tikz}
\RequirePackage{printlen}
\usetikzlibrary{calc}
\RequirePackage{calc}
\RequirePackage{eso-pic}
\RequirePackage{afterpage}
\RequirePackage{cancel}

%\definecolor{myLinkColor}{rgb}{1,.0784313725,.5764705882}%RGB 255 20 147 #ff1493ff
%\definecolor{RoseOPE}{rgb}{1,.0784313725,.5764705882}%RGB 255 20 147 #ff1493ff

\newcommand{\@mydate}{}
\newcommand{\@myauthor}{}
\newcommand{\myoperation}{}
\newcommand{\mysecretlevel}{}
\newcommand{\mydoctitle}{}
\newcommand{\mysubtitle}{}

\newcommand{\doctitle}[1]{\renewcommand{\mydoctitle}{#1}\markboth{#1}{#1}}
\newcommand{\operation}[1]{\renewcommand{\myoperation}{#1}}
\newcommand{\secretlevel}[1]{\renewcommand{\mysecretlevel}{#1}}
\newcommand{\mydate}[1]{\renewcommand{\@mydate}{#1}}
\newcommand{\myauthor}[1]{\renewcommand{\@myauthor}{#1}}

\newcommand*{\cleartoleftpage}{%
  \clearpage
    \if@twoside
    \ifodd\c@page
      \hbox{}\newpage
      \if@twocolumn
        \hbox{}\newpage
      \fi
    \fi
  \fi
}

\newcommand{\liasse}{1}
\renewcommand\maketitle{%\begin{titlepage}%
%  \thispagestyle{empty}
  \let\footnotesize\small
  \let\footnoterule\relax
  \let \footnote \thanks
  \null\vfil
  \vskip 60\p@
  \begin{center}%
    {\LARGE \@title \par}%
    \vskip 3em%
    {\large
     \lineskip .75em%
      \begin{tabular}[t]{c}%
        \@author
      \end{tabular}\par}%
      \vskip 1.5em%
    {\large \@date \par}%       % Set date in \large size.
  \end{center}\par
  \@thanks
%  \vfil\null
%  \end{titlepage}%
  \setcounter{footnote}{0}%
  \global\let\thanks\relax
  \global\let\maketitle\relax
  \global\let\@thanks\@empty
  \global\let\@author\@empty
  \global\let\@date\@empty
  \global\let\@title\@empty
  \global\let\title\relax
  \global\let\author\relax
  \global\let\date\relax
  \global\let\and\relax
\setcounter{page}{1}
  }
\renewcommand\@maketitle{%
  %\newpage
%\thispagestyle{empty}
  \null
  \vskip 2em%
  \begin{center}%
  \let \footnote \thanks
    {\LARGE \@title \par}%
    \vskip 1.5em%
    {\large
      \lineskip .5em%
      \begin{tabular}[t]{c}%
        \@author
      \end{tabular}\par}%
    \vskip 1em%
    {\large \@date}%
  \end{center}%
  \par
  \vskip 1.5em}
%
\newcommand{\subtitle}[2]{%
	\renewcommand{\mysubtitle}{#1.\hologo{TeX}}%
	\pagestyle{plain}\markright{\mysubtitle}%
	\pagestyle{fancy}\markright{\mysubtitle}%
	\pagestyle{liasse}\markright{\mysubtitle}%
	\pagestyle{plain}%
	}

\newcommand{\entete}[1]{%
	\textbf {\texttt{\myoperation\\#1%
	\color{RoseOPE}\setlength\fboxrule{2pt}\\
	\vspace{1cm}\fbox{%
		{\textcolor{RoseOPE}%
		{\fontsize{2cm}{2.5cm}\selectfont%
		\textsf{\mysecretlevel}}}}}}}%fin en-tete


\newlength{\twomawstrlen}%
\newlength{\threemawstrlen}%

\newcommand{\MAWtitle}[4]{%
	\markboth{#2\hologo{.TeX}}{#2}
%%%%%\usepackage{eso-pic}
\AddToShipoutPictureBG*{%
  %\AtPageUpperLeft{\raisebox{-\height}{\color{red}Page upper left}}%
  \AtPageUpperLeft{%
\raisebox{-\height -5mm}{%
\hspace{5mm}\color{RoseOPE}\rotatebox{30}{agrafe}
}%
}%
  %\AtPageLowerLeft{\color{blue}Page lower left}%
}%
%\AddToShipoutPictureFG*{%
%  \AtPageCenter{\makebox[0pt]{\color{green}\Huge DRAFT}}%
%  \AtTextUpperLeft{\raisebox{-\height}{\color{brown}Text upper left}}%
%  \AtTextLowerLeft{\color{purple}Text lower left}%
%  \AtTextLowerLeft{\hspace*{-.5in}\raisebox{3\baselineskip}{$\bullet$}}
%}%
	\settowidth{\twomawstrlen}{#2}%
	\settowidth{\threemawstrlen}{#3}
%	\cleartoleftpage%\cleardoublepage
	\par~\vspace{-.5in}\par\noindent%
	\begin{tikzpicture}[scale=1]
		\clip (0,0) rectangle (\textwidth,1+#1);
		\foreach \x in {0,1,...,18}{
			\fill[yellow] (\x,0) -- (\x + 0.5,0) -- (\x + 1,1+#1) -- (\x+0.5,1+#1);
		}
		\foreach \x in {0,1,...,18}{
			\fill[black] (\x-0.5,0) -- (\x,0) -- (\x+0.5,1+#1) -- (\x,1+#1);
		}
		\fill[red] (0.5\textwidth - 3cm,0.5) rectangle (0.5\textwidth + 3cm,.95);
		\draw[white] (.5\textwidth, .75) node {TRÈS SECRET};
		\fill[blue] (0.5\textwidth - 3cm,0.05) rectangle (0.5\textwidth + 3cm,.45);
		\draw[white] (.5\textwidth, .25) node {CONFIDENTIEL PERSONNEL};
		\draw[red] (\textwidth - .5\threemawstrlen - 6pt, .5 + #1 ) node {#3};
		\fill[yellow,rounded corners=10pt] (0.2,.2) -- (2,.2) -- (1.1,1.9) -- (.2,.2); 
		\draw[black,line width=5pt,rounded corners=10pt] (.5,.2) -- (2,.2) -- (1.1,1.9) -- (.2,.2) -- (2,.2); 
		\draw[white,font=\bfseries] (3cm, 1.5) node {(Poor Man At Work)};
		\draw[white,font=\bfseries] (3cm, 1.2) node {(aNd No PlAy)};
		\draw[black,font=\sffamily\fontsize{6pt}{6.5pt}\selectfont\bfseries] (1.1, 1) node {P.M.};
		\draw[black,font=\sffamily\fontsize{6pt}{6.5pt}\selectfont\bfseries] (1.1, .5) node {AT WORK!};
		\fill[yellow] (0.5\textwidth - .52 \twomawstrlen ,1.1) rectangle (.5 \textwidth + .52 \twomawstrlen,.95+#1);
		\draw[black] (0.5\textwidth - .52 \twomawstrlen ,1.1) rectangle (.5 \textwidth + .52 \twomawstrlen,.95+#1);
		\draw[red] (.5\textwidth, .5 + #1 ) node {#2};
	\end{tikzpicture}
	\markboth{#3}{#3}
	\refstepcounter{section}
	\addcontentsline{toc}{section}{Document \thesection:\\
	\normalfont #3.tex : #2,\\#4}
	%\pagestyle{fancy}
	\par\noindent{\sf\bfseries#3.txt\\#4\\}
	}

\title{\entete{\mydoctitle}}
\newcounter{twototheight}
\setcounter{twototheight}{0}
\newcounter{sevenbitpage}
\setcounter{sevenbitpage}{0}
\newcounter{EOT}
\setcounter{EOT}{-1}
\newcommand\modulo[2]{\@tempcnta=#1
        \divide\@tempcnta by #2
        \multiply\@tempcnta by #2
        \multiply\@tempcnta by -1
        \advance\@tempcnta by #1\relax
        \the\@tempcnta}
\fancypagestyle{plain}{%
	\fancyhf{} % clear all header and footer fields
		%\fancyfoot[C]{\textbf{\thepage}} % except the center
		\fancyfoot[L]{\tiny \textbf{\rightmark}}%\jobname{}.TeX}} % except the center
		%\fancyfoot[R]{\textbf{\myoperation{} | \thepage{ }/{ }\pageref{LastPage}}} % except the center
		\fancyfoot[R]{\textbf{%
	\ifthenelse{\thesevenbitpage=127}{match! \setcounter{sevenbitpage}{0}\stepcounter{twototheight}}{\stepcounter{sevenbitpage}}
	\myoperation{} | \thesevenbitpage{}
	\ifthenelse{\thetwototheight>0}{+ \thetwototheight{} x 2\up{7}}{}} /{ }\pageref{EOT}}% \thepage% except the center
		\renewcommand{\headrulewidth}{0pt}
		\renewcommand{\footrulewidth}{0.4pt}%
		}
\fancypagestyle{liasse}{%
	%\fancyhf{} % clear all header and footer fields
	% CHEAD A REMPLIR
	\lhead{\setlength{\unitlength}{1mm}
\hspace{-1in - \oddsidemargin +.5cm}\rotatebox{30}{\color{RoseOPE}{agrafe}}
%\begin{picture}(0,0)
	%\put(-10,0){\rotatebox{30}{agrafe}}%{\includegraphics{pic\thepage.ps}}
%\end{picture}
}
}
\fancypagestyle{titlepage}{%
\fancyhf{}%
%\fancyhf{} % clear all header and footer fields
% CHEAD A REMPLIR
}
\pagestyle{plain}
\newcommand{\sommaireformat}[3]{%
	\addcontentsline{toc}{section}{#1 : \normalfont #2.tex : #3}}
\newcommand{\nocontentsline}[3]{}
\newcommand{\tocless}[2]{\bgroup\let\addcontentsline=\nocontentsline#1{#2}\egroup}
\newsavebox{\toctocbox}
\newcommand{\assault}[4][]{
  \clearpage
  \markboth{#3}{#3}
  \markright{#3}
  \thispagestyle{liasse}
\IfBlankTF{#1}{
  \cleartoleftpage%\cleardoublepage
}{}
  \subtitle{#3}{#4}
  \refstepcounter{section}
  %document \thesection:\hspace*{1.5ex}
  \thispagestyle{fancy}
  \section*{#2}%
  \addcontentsline{toc}{section}{Document \thesection:\\
  \normalfont ~ #3.tex : #2, \\#4}
 % \pagestyle{fancy}
}
\titleformat{\section}[block]%
{\sffamily\filright}%
{}%\thesection}
{0pt}%
{\centering\LARGE\setlength\fboxrule{2pt}\tt{}\myoperation%OP\'ERATION QUE DU PLAISIR
\\
#1}%
[%
\centering\begin{minipage}{\textwidth}
\centering
\color{RoseOPE}\textcolor{RoseOPE}%
%\fontsize{2cm}{2.5cm}\selectfont
~\vspace{1em}\\
	\sf{}\fbox{\mysecretlevel}\\\vspace{1em}
\color{black}%
\normalsize
\@mydate~\\
\@myauthor~\\
	\vspace{2em}
\end{minipage}
%\pagestyle{plain}\markboth{#1 titi}
\markright{\tiny \mysubtitle}
%\thispagestyle{plain}
]
\newcommand{\agrafe}{%%%%%\usepackage{eso-pic}
\AddToShipoutPictureBG*{%
  %\AtPageUpperLeft{\raisebox{-\height}{\color{red}Page upper left}}%
  \AtPageUpperLeft{%
\raisebox{-\height -5mm}{%
\hspace{5mm}\color{RoseOPE}\rotatebox{30}{agrafe}
}%
}%
  %\AtPageLowerLeft{\color{blue}Page lower left}%
}%
%\AddToShipoutPictureFG*{%
%  \AtPageCenter{\makebox[0pt]{\color{green}\Huge DRAFT}}%
%  \AtTextUpperLeft{\raisebox{-\height}{\color{brown}Text upper left}}%
%  \AtTextLowerLeft{\color{purple}Text lower left}%
%  \AtTextLowerLeft{\hspace*{-.5in}\raisebox{3\baselineskip}{$\bullet$}}
%}%
}

\newcommand{\agrafeverso}{%\begin{textblock}{2cm}(1cm,1cm)
	\thispagestyle{liasse}
	\chead{\hspace{-10cm}AGRAFE VERSO}%
	}
\newcommand{\agraferecto}{%
	\thispagestyle{liasse}
	\chead{\hspace{-10cm}AGRAFE RECTO}%
	}

\rhead{\footnotesize{\myoperation}}%OP\'ERATION QUE DU PLAISIR}}
\lhead{\footnotesize{\myoperation}}%OP\'ERATION QUE DU PLAISIR}}
\lfoot{\footnotesize{\myoperation}}%OP\'ERATION QUE DU PLAISIR}}
\rfoot{\footnotesize{\myoperation}}%OP\'ERATION QUE DU PLAISIR}}

%\thispagestyle{empty}
\endinput
