%
% AUTH report class
%
% note: Requires compilation with XeLaTeX or LuaTeX
%
% author: Christos Choutouridis <cchoutou@ece.auth.gr>
%
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{AUTHReport}[2024-11-03 AUTH Report document class]


% Options
% ===============================================

% Declare option for short report version
\DeclareOption{short}{\def\auth@short{yes}}

% Declare option for CoAuthor
\DeclareOption{coauthor}{\def\auth@coauthor{yes}}


% Default option values
\def\auth@short{no}
\def\auth@coauthor{no}

% Pass all other options to article
\DeclareOption*{%
    \PassOptionsToClass{\CurrentOption}{article}
}
\ProcessOptions\relax

\LoadClass{article}


% Requirements
% ===============================================
\RequirePackage{iftex}
\ifPDFTeX
    \RequirePackage[utf8]{inputenc}
    \RequirePackage[T1]{fontenc}
\else
    \RequirePackage{fontspec}
\fi

\RequirePackage{xargs}      % Commands

\RequirePackage{geometry}   % Layout
\RequirePackage{fancyhdr}

\RequirePackage{graphicx}   % Figures

% Format packages
\RequirePackage[hang, small,labelfont=bf,up,textfont=it,up]{caption} % Custom captions under/above floats in tables or figures
\RequirePackage[nobottomtitles]{titlesec}
\RequirePackage{titling}
\RequirePackage[bottom]{footmisc} % Place footnotes always as much to the bottom as possible.

\RequirePackage{hyperref}   % Various
\RequirePackage[ddmmyyyy]{datetime}
\RequirePackage{enumitem}


% Local Tools
% ===============================================

% Tool to check equality
\newcommand{\isequal}[2]{ \pdf@strcmp{#1}{#2} }

% syntactic suggar for horizaontal rule
\newcommand{\Hrule}{ \rule{\linewidth}{0.1mm} }


% Theme
% ===============================================

% Layout
% =====================================================

% Page core layout settings (include head and foot)
% A4 will result to:
% 	Top margin:       12mm
% 	Bottom margin:    11mm
% 	Head hight:       14mm
% 	Foot skip:        15mm
% 	Left margin:      15mm
% 	Right margin:     12mm
\newcommand{\authTopMargin}{12mm}
\newcommand{\authBottomMargin}{12mm}
\newcommand{\authHeadHeight}{10mm}
\newcommand{\authFootSkip}{10mm}
\newcommand{\authLeftMargin}{15mm}
\newcommand{\authRightMargin}{15mm}


%
% Sets page layout. (include head and foot)
\newcommand*{\authSetPageLayout}{%
    \newgeometry{%
        includeheadfoot,
        top= \authTopMargin,
        bottom= \authBottomMargin,
        headheight= \authHeadHeight,
        footskip= \authFootSkip,
        lmargin= \authLeftMargin,
        rmargin= \authRightMargin
    }
}

% Fonts
% =====================================================

% [1]: Main(Serif) body font
% [5]: Sans family font
% [6]: Mono family font
%
\newcommand{\authFontEnvSetup}[3]{%
    \setmainfont{#1}[SmallCapsFeatures={Letters=SmallCaps}]
    \setsansfont{#2}
    \setmonofont{#3}

%    \newfontface\smallcapsfont{Libertinus Serif}[Letters=SmallCaps]
}


% Header and Footer
% =====================================================

\newcommand*{\authSetFooterEmpty}{%
    % Clear styles
    \fancyfoot{}
    \renewcommand{\footrulewidth}{0pt}
}

\newcommand*{\authSetFooter}{%
    % Clear styles
    \fancyfoot{}
    \fancyfoot[C]{\thepage}
    \renewcommand{\footrulewidth}{0pt}
    \pagenumbering{arabic}
}

\newcommand{\authSetHeaderEmpty}{
    % Clear styles
    \fancyhead{}
    \renewcommand{\headrulewidth}{0pt}
}

\newcommand{\authSetHeader}{
    % Clear styles
    \fancyhead{}
    \fancyhead[L]{\auth@className}
    \fancyhead[R]{\auth@docTitle}
    \renewcommand{\headrulewidth}{0.5pt}
}


%
% Page styles
%
\fancypagestyle{plain}{%
    % Style for the main document (including TOC)
    \authSetFooter
    \authSetHeader
}

\fancypagestyle{authTitlePageStyle}{%
    % Style for Title page
    \authSetHeaderEmpty
    \ifnum \isequal{\auth@short}{no}=0
        \authSetFooterEmpty
    \else
        \authSetFooter
    \fi
}


% Common Page style
\newcommand{\authPageStyle}{%

    \renewcommand{\bottomtitlespace}{0.12\textheight}

    % Change the look of the section and subsection titles
    \titleformat{\section}[block]{\large\scshape}{\thesection.}{1em}{}
    \titleformat{\subsection}[block]{\large}{\thesubsection.}{1em}{}
    \titleformat{\subsubsection}[block]{\normalsize}{\thesubsubsection.}{1em}{}

    \setlist[itemize]{noitemsep}        % Make itemize lists more compact

    % Set paragraph identation and skip
    \setlength{\parindent}{0pt}
    \setlength{\parskip}{0.65em}

}


% Setup theme
% =====================================================

\AtBeginDocument{%
    % Page layout (check above for the geometry setup)
    \authSetPageLayout

    % Fonts
    \authFontEnvSetup{CMU Serif}{CMU Sans Serif}{Courier New}

    % Header - Footer
  	\pagestyle{plain}
    \thispagestyle{authTitlePageStyle}

    % Page styles and formating
    \authPageStyle

    \normalsize
} % End \AtBeginDocument



% QA document public environments/commands
% =====================================================

% Common fields
% =====================================================
\newcommand*{\AuthorName}[1]{\def\auth@authorName{#1}}
\newcommand*{\AuthorMail}[1]{\def\auth@authorMail{#1}}
\newcommand*{\AuthorAEM}[1]{\def\auth@authorAEM{#1}}

\newcommand*{\CoAuthorName}[1]{\def\auth@coauthorName{#1}}
\newcommand*{\CoAuthorMail}[1]{\def\auth@coauthorMail{#1}}
\newcommand*{\CoAuthorAEM}[1]{\def\auth@coauthorAEM{#1}}

\newcommand*{\WorkGroup}[1]{\def\auth@workGroup{#1}}

\newcommand*{\DocTitle}[1]{\def\auth@docTitle{#1}}
\newcommand*{\Department}[1]{\def\auth@department{#1}}
\newcommand*{\ClassName}[1]{\def\auth@className{#1}}

\newcommand*{\InstructorName}[1]{\def\auth@instructorName{#1}}
\newcommand*{\InstructorMail}[1]{\def\auth@instructorMail{#1}}
\newcommand*{\CurrentDate}[1]{\def\auth@date{#1}}



% \FirstPage
\newcommand{\authTitlePage}{%
    \begin{titlepage}
        % Logo
        \begin{figure}
            \begin{flushleft}
                \includegraphics[width=5cm]{img/auth_logogr.png}
            \end{flushleft}
        \end{figure}
        % Titles
        \center                                 % Center everything on the page
        \textbf{}                        \\[3.5cm]   % vertical space
        \textsc{\Large \auth@department} \\[0.5cm]   % Department
        \textsc{\Large \auth@className}  \\[1.5cm]   % Class/Course name
        \Hrule                           \\[0.4cm]   % -------
        {\huge \bfseries \auth@docTitle} \\[0.1cm]   % Document/Assignement Title
        \Hrule                           \\[3.5cm]   % -------
        % vertical space
        % Authors
        \begin{minipage}{0.4\textwidth}
            \begin{flushleft}
                \large
                \ifdefined \auth@workGroup \emph{\textsc{\auth@workGroup}} \\[2ex]\fi
                \ifnum \isequal{\auth@coauthor}{yes}=0
                \emph{Συντάκτες:}
                \else
                \emph{Συντάκτης:}
                \fi  \\
                \textsc{\auth@authorName}     \\
                \textsc{AEM:\auth@authorAEM}  \\[1ex]
                \normalsize	\href{mailto:\auth@authorMail}{\auth@authorMail}  \\[2ex]
                \large
                \ifnum \isequal{\auth@coauthor}{yes}=0
                \textsc{\auth@coauthorName}    \\
                \textsc{AEM:\auth@coauthorAEM} \\[1ex]
                \normalsize \href{mailto:\auth@coauthorMail}{\auth@coauthorMail}
                \fi
            \end{flushleft}
        \end{minipage}
        \begin{minipage}{0.4\textwidth}
            \begin{flushright} \large
                \emph{Διδάσκων:}              \\  % Instructor
                \textsc{\auth@instructorName} \\[1ex]
                \normalsize
                \href{mailto:\auth@instructorMail}{\auth@instructorMail}
            \end{flushright}
        \end{minipage}       \\
        \vfill
        {\large \auth@date}  \\ % date

    \end{titlepage}
    \newpage
}

% \TitleHeader
\newcommand{\authTitleHeader}{%
    \begin{center}                      % Center everything on the page
        % Logo
        \begin{figure}
            \center
            \includegraphics[width=5cm]{img/auth_logogr.png}
        \end{figure}
        % Titles
        \textsc{\Large \auth@department}     \\[0.4cm]   % Department
        \textsc{\Large \auth@className}      \\[0.1cm]   % Class/Course name
        {\Large \bfseries \auth@docTitle}    \\[0.2cm]   % Document/Assignement Title
        {\large \auth@date}                  \\[0.4cm]   % date
        % Authors
        \begin{minipage}{0.4\textwidth}
            \begin{flushleft}
                \large
                \ifnum \isequal{\auth@coauthor}{yes}=0
                \emph{Συντάκτες:}
                \else
                \emph{Συντάκτης:}
                \fi  \\
                \textsc{\auth@authorName}     \\
                \textsc{AEM:\auth@authorAEM}  \\[1ex]
                \normalsize	\href{mailto:\auth@authorMail}{\auth@authorMail}  \\[2ex]
                \large
                \ifnum \isequal{\auth@coauthor}{yes}=0
                \textsc{\auth@coauthorName}    \\
                \textsc{AEM:\auth@coauthorAEM} \\[1ex]
                \normalsize \href{mailto:\auth@coauthorMail}{\auth@coauthorMail}
                \fi
            \end{flushleft}
        \end{minipage}
        \begin{minipage}{0.4\textwidth}
            \begin{flushright} \large
                \emph{Διδάσκων:}         \\  % Instructor
                \textsc{\auth@instructorName} \\[1ex]
                \normalsize
                \href{mailto:\auth@instructorMail}{\auth@instructorMail}
            \end{flushright}
        \end{minipage}
    \end{center}
}

\newcommand{\Title}{%
    \ifnum \isequal{\auth@short}{no}=0
        \authTitlePage
    \else
        \authTitleHeader
    \fi
}

% \InsertFigure{}{}{}{}
% [1]: scale
% [2]: Label
% [3]: Figure file
% [4]: Caption text
% example: \InsertFigure{0.8}{fig:lala}{lala.png}{\eng{Makes lala}}
\newcommand{\InsertFigure}[4]{
    \begin{figure*}[h!]
        \captionsetup{format=plain}
        \centering
        \includegraphics[width=#1\textwidth]{#3}
        \caption{#4}
        \label{#2}
    \end{figure*}
}

% \WrapFigure{}{}{}{}
% [1]: scale
% [2]: place left or right r,l,R,L
% [3]: Label
% [4]: Figure file
% [5]: Caption text
% example: \WrapFigure{0.8}{r}{fig:lala}{lala.png}{\eng{Makes lala}}
\newcommand{\WrapFigure}[5]{
    \begin{wrapfigure}{#2}{#1\textwidth}
        \vspace{-20pt}
        \begin{center}
            \captionsetup{format=plain}
            \includegraphics[width=#1\textwidth]{#4}
            \caption{#5}
            \label{#3}
        \end{center}
        \vspace{-20pt}
    \end{wrapfigure}
}
