%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% jmk.sty
%
% LaTeX package for Sphinx override template
%
% © Jeff MacKinnon
% code by E. A. Farina latex.guru
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{jmk}[2024/04/05 v1.0 LaTeX package for Sphinx override template]
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Useful packages
    \RequirePackage{tikz}
    \RequirePackage{xcolor}
    \RequirePackage{anyfontsize}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Colors
    \definecolor{JMKblue}{HTML}{004360}%{17365d}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Layout
    \newlength{\MARmar}\setlength{\MARmar}{1in}
    \newlength{\MARlef}\setlength{\MARlef}{\MARmar}
    \newlength{\MARrig}\setlength{\MARrig}{\MARmar}
    \newlength{\MARtop}\setlength{\MARtop}{\MARmar}
    \newlength{\MARbot}\setlength{\MARbot}{\MARmar}
    \RequirePackage[letterpaper,portrait,includehead,includefoot,margin=\MARmar,headheight=10mm]{geometry}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Language
    %\RequirePackage[english]{babel}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Tokens
    \newcommand{\dbclient}{}\newcommand{\client}[1]{\renewcommand{\dbclient}{#1}}
    \newcommand{\dbrevision}{}\newcommand{\revision}[1]{\renewcommand{\dbrevision}{#1}}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Page style
    \RequirePackage{fancyhdr}
    \renewcommand{\headrulewidth}{0pt}
    \renewcommand{\footrulewidth}{0pt}
    \newcommand{\headfoot}{\fancyhf{}\fancyhead[C]{\begin{tikzpicture}[remember picture,overlay,inner sep=0pt,outer sep=0pt]
            %\node at (current page.center) {\includegraphics[width=\paperwidth,page=2]{TEST.pdf}};
            % HEAD
                \coordinate (TOPl) at ([shift={(\MARlef+100pt,0pt)}]current page.north west);
                \coordinate (TOPr) at ([shift={(-\MARrig-100pt,0pt)}]current page.north east);
                % Logo
                    \node[anchor=north west] (LOGO) at ([shift={(\MARlef,-35pt)}]current page.north west) {\includegraphics[height=55pt]{JMKEngineering-Logo.jpg}};
                % Title
                    \node[anchor=north west,font=\fontsize{12pt}{14pt}\sffamily\selectfont] at (TOPl|-LOGO.north) {\@title};
                % Client
                    \node[anchor=south west,font=\fontsize{10pt}{12pt}\sffamily\selectfont] at (TOPl|-LOGO.south) {CLIENT: \strut\dbclient};
                % Revision
                    \node[anchor=north west,font=\fontsize{10pt}{12pt}\sffamily\selectfont] (REV) at (TOPr|-LOGO.center) {\strut Revision: \strut\dbrevision};
                % Project
                    \node[anchor=south west,font=\fontsize{10pt}{12pt}\sffamily\selectfont] at ([shift={(0pt,+3pt)}]REV.north west) {\strut Project \#: \version};
                % Page
                    \node[anchor=north west,font=\fontsize{10pt}{12pt}\sffamily\selectfont] at ([shift={(0pt,-3pt)}]REV.south west) {\strut Page \thepage};
            % FOOT
                % Date
                    \node[anchor=south west,font=\fontsize{10pt}{12pt}\sffamily\selectfont] at ([shift={(\MARlef,64pt)}]current page.south west) {\strut Publish Date: \@date};
                % Filename
                    \node[anchor=south west,font=\fontsize{10pt}{12pt}\sffamily\selectfont] at ([shift={(\MARlef,50pt)}]current page.south west) {\strut Filename: \jobname.pdf};
                % Page
                    \node[anchor=south east,font=\fontsize{10pt}{12pt}\sffamily\selectfont] at ([shift={(-\MARrig,50pt)}]current page.south east) {\strut\thepage};
        \end{tikzpicture}}}
    \fancypagestyle{plain}{\headfoot}
    \fancypagestyle{normal}{\headfoot}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Headings
    %\RequirePackage[Bjornstrup]{fncychap}% Loaded by conf.py but remove by Elio
    %\RequirePackage[explicit]{titlesec}
    \def\FONTchapter{\Large\bfseries}
    \titleformat{\chapter}[hang]{\FONTchapter}{\thechapter.}{1em}{}[]
    \titleformat{name=\chapter,numberless}[hang]{\FONTchapter}{}{0pt}{}[]
    \titlespacing*{\chapter}{0pt}{0pt}{\baselineskip}
    %
    \def\FONTsection{\large\bfseries}
    \titleformat{\section}[hang]{\FONTsection}{\thesection.}{1em}{}[]
    \titleformat{name=\section,numberless}[hang]{\FONTsection}{}{0pt}{}[]
    \titlespacing*{\section}{0pt}{\baselineskip}{0pt}
    %
    \def\FONTsubsection{\bfseries}
    \titleformat{\subsection}[hang]{\FONTsubsection}{\thesubsection.}{1em}{}[]
    \titleformat{name=\subsection,numberless}[hang]{\FONTsubsection}{}{0pt}{}[]
    \titlespacing*{\subsection}{0pt}{\baselineskip}{0pt}
    %
    \def\FONTsubsubsection{\itshape}
    \titleformat{\subsubsection}[hang]{\FONTsubsubsection}{\thesubsubsection.}{1em}{}[]
    \titleformat{name=\subsubsection,numberless}[hang]{\FONTsubsubsection}{}{0pt}{}[]
    \titlespacing*{\subsubsection}{0pt}{\baselineskip}{0pt}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Intentionally Blank Page
    \newcommand{\IBP}{\clearpage\pagestyle{plain}
        \strut\par
        \vfill
        \centerline{\textbf{\sffamily Intentionally Blank Page}}\par
        \vfill
        \strut
        \clearpage
    }
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Title page
    \renewcommand{\sphinxmaketitle}{\pagestyle{empty}\pagenumbering{roman}\strut
        \begin{tikzpicture}[remember picture,overlay,inner sep=0pt,outer sep=0pt]
            % Logo
                \node[anchor=north west] (LOGO) at ([shift={(125pt,-100pt)}]current page.north west) {\includegraphics[height=72pt]{JMKEngineering-Logo_text.jpg}};
            % Title
                \node[anchor=north west,text width=\linewidth-125pt,align=flush left,font=\fontsize{34pt}{40pt}\color{JMKblue}\bfseries\selectfont] (TITLE) at ([shift={(0pt,-18pt)}]LOGO.south west) {\@title};
            % Project num
                \node[anchor=north west,text width=\linewidth-125pt,align=flush left,font=\fontsize{12pt}{14pt}\color{JMKblue}\sffamily\selectfont] (VER) at ([shift={(0pt,-15pt)}]TITLE.south west) {Project Number: \strut\version};
            % Left band
                \draw[JMKblue,line width=1.2pt] ([shift={(-5pt,10pt)}]LOGO.north west) coordinate (LS) --([yshift=-10pt]LS|-VER.south);
            % Date
                \node[anchor=south west,text width=\linewidth-125pt,align=flush left,font=\fontsize{14pt}{16pt}\color{JMKblue}\sffamily\selectfont] (DATE) at ([shift={(0pt,100pt)}]TITLE.west|-current page.south) {Issue Date: \strut\@date};
            % Revision
                \node[anchor=south west,text width=\linewidth-125pt,align=flush left,font=\fontsize{14pt}{16pt}\color{JMKblue}\sffamily\selectfont] (DATE) at ([shift={(0pt,80pt)}]TITLE.west|-current page.south) {Revision: \strut\dbrevision};
        \end{tikzpicture}
        \IBP
    }
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% List of figures and tables
    \RequirePackage{float}
    \floatstyle{boxed}
    \restylefloat{figure}
    \restylefloat{table}
    \newif\iffigures
    \newif\iftables
    \makeatletter
        \AtEndDocument{%
            \if@filesw
               \ifnum\value{figure}=\z@ % no figures
                  \immediate\write\@mainaux {\global\string\figuresfalse}%
               \else
                  \immediate\write\@mainaux {\global\string\figurestrue}%
               \fi
               \ifnum\value{table}=\z@ % no tables
                  \immediate\write\@mainaux {\global\string\tablesfalse}%
               \else
                  \immediate\write\@mainaux {\global\string\tablestrue}%
               \fi
            \fi
        }
    \makeatother
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Table of contents
    \setcounter{tocdepth}{1}
    \renewcommand{\sphinxtableofcontents}{%
        %\pagenumbering{roman}%
        \begingroup
            %\parskip \z@skip
            \sphinxtableofcontentshook
            \tableofcontents
        \endgroup
        % List of figures
            \iffigures
               \addcontentsline{toc}{section}{List of figures}
               \listoffigures
            \fi
        % List of tables
            \iftables
               \addcontentsline{toc}{section}{List of tables}
               \listoftables
            \fi
        \ifnumodd{\value{page}}{\clearpage\IBP\clearpage}{\clearpage}
        % before resetting page counter, let's do the right thing.
        %\if@openright\cleardoublepage\else\clearpage\fi
        % Start the mainmatter
        \pagenumbering{arabic}%
    }
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Hyperref
    \hypersetup{hidelinks}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\endinput