% ijditde.cls - European Scientific Network Publishing journal template class
% Note: This is NOT Elsevier's elsarticle class and does not include Elsevier branding.
\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{ijditde}[2026/07/26 v0.7 ESN Publishing journal template]

% -------- Options --------
\newif\ifij@review
\newif\ifij@anonymous

\DeclareOption{review}{\ij@reviewtrue}
\DeclareOption{final}{\ij@reviewfalse}
\DeclareOption{anonymous}{\ij@anonymoustrue}
\DeclareOption*{\PassOptionsToClass{\CurrentOption}{article}}

\ExecuteOptions{final}
\ProcessOptions\relax

% -------- Base class --------
\LoadClass[11pt,a4paper]{article}

% -------- Packages --------
\RequirePackage[T1]{fontenc}
\RequirePackage[utf8]{inputenc}
\RequirePackage{lmodern}
\RequirePackage[
  top=15mm,
  left=15mm,
  right=15mm,
  bottom=18mm
]{geometry}
\RequirePackage{microtype}
\RequirePackage{graphicx}
\RequirePackage{booktabs}
\RequirePackage{amsmath,amssymb}
\RequirePackage{siunitx}
\RequirePackage{enumitem}
\RequirePackage{caption}
\RequirePackage{subcaption}
\RequirePackage{ragged2e}
\RequirePackage{authblk}
\RequirePackage{fancyhdr}
\RequirePackage{lastpage}
\RequirePackage{xcolor}
\RequirePackage{hyperref}
\RequirePackage{natbib}
\RequirePackage{expl3}

% Hyperref setup (simple, readable)
\hypersetup{
  unicode=true,
  colorlinks=true,
  linkcolor=blue,
  citecolor=blue,
  urlcolor=blue
}

% Natbib: numeric citations: [1], [2–4]
\setcitestyle{numbers,square,comma,sort&compress}

% Review mode: double spacing + line numbers
\ifij@review
  \RequirePackage{setspace}
  \doublespacing
  \RequirePackage[switch]{lineno}
  \linenumbers
\fi

% -------- Journal metadata (customize these) --------
\newcommand{\journalname}{International Journal of Digital Technology Driven Engineering}
\newcommand{\journalshortname}{IJDTDE}

% -------- Header/footer (pages after the first) --------
\pagestyle{fancy}
\fancyhf{}

% smaller + italic, and reduce extra height
\fancyhead[L]{\scriptsize\itshape \shortauthors}
\fancyhead[R]{\scriptsize\itshape \journaltitle\ \journalvolume\ (\journalyear)\ \articleid}

% If you want NO footer at all, comment next line
\fancyfoot[C]{\scriptsize\thepage}

% remove the underline below header
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0pt}

% make header vertically tighter
\setlength{\headheight}{28pt} % height of the header box
\setlength{\headsep}{18pt}     % space between header and text (reduce for more compact)
\setlength{\footskip}{11pt}  % space from text to footer


\newcommand{\shortauthors}{A. Author et al.}
\newcommand{\journaltitle}{International Journal of Digital Technology Driven Engineering}
\newcommand{\journalvolume}{1}
\newcommand{\journalyear}{2026}
\newcommand{\articleid}{Article 001}

% -------- Title block styling --------
\setlength{\affilsep}{0.4em}
\date{} % no date

% -------- Frontmatter helpers --------
\makeatletter

% ---- Title/author/affil font controls ----
\def\ij@titlefont{\Large\bfseries}       % default title style
\def\ij@authorfont{\normalsize}         % default author style
\def\ij@affilfont{\footnotesize\itshape}% default affiliation style

\newcommand{\setijtitlefont}[1]{\def\ij@titlefont{#1}}
\newcommand{\setij@authorfont}[1]{\def\ij@authorfont{#1}}
\newcommand{\setij@affilfont}[1]{\def\ij@affilfont{#1}}

% authblk defaults (affiliation small italic)
\renewcommand\Authfont{\normalsize\normalfont}
\renewcommand\Affilfont{\footnotesize\itshape}

% --- Control the gap between banner and the article title ---
% Make this less negative for more space, more negative for tighter.
\def\ij@afterbanner@vspace{-0.4em}
\newcommand{\setijafterbannervspace}[1]{\def\ij@afterbanner@vspace{#1}}

% Metadata setters
\newcommand{\correspondingauthor}[1]{\def\ij@corrauthor{#1}}
\newcommand{\correspondingemail}[1]{\def\ij@cormail{#1}}
\newcommand{\articletype}[1]{\def\ij@articletype{#1}}
\newcommand{\keywords}[1]{\def\ij@keywords{#1}}
\newcommand{\pdfauthorline}[1]{\def\ij@pdfauthorline{#1}}
\newcommand{\pdfsubjectline}[1]{\def\ij@pdfsubjectline{#1}}

% ---- Extra first-page info (optional) ----
\newcommand{\doi}[1]{\def\ij@doi{#1}}
\newcommand{\received}[1]{\def\ij@received{#1}}
\newcommand{\revised}[1]{\def\ij@revised{#1}}
\newcommand{\accepted}[1]{\def\ij@accepted{#1}}
\newcommand{\availableonline}[1]{\def\ij@availableonline{#1}}
\newcommand{\copyrightline}[1]{\def\ij@copyright{#1}}

% IJDTDE top banner
\newcommand{\articlehead}[1]{\def\ij@articlehead{#1}}
\newcommand{\platformname}[1]{\def\ij@platformname{#1}}
\newcommand{\platformurl}[1]{\def\ij@platformurl{#1}}
\newcommand{\journalhomepage}[1]{\def\ij@journalhomepage{#1}}
\newcommand{\journallogo}[1]{\def\ij@journallogo{#1}}
\newcommand{\journalcover}[1]{\def\ij@journalcover{#1}}
\newcommand{\bannercolor}[1]{\def\ij@bannercolor{#1}}

% Defaults
\correspondingauthor{}
\correspondingemail{}
\articletype{}
\keywords{}
\pdfauthorline{}
\pdfsubjectline{Research article published in the International Journal of Digital Technology Driven Engineering}
\doi{}
\received{}
\revised{}
\accepted{}
\availableonline{}
\copyrightline{}
\articlehead{}
\platformname{}
\platformurl{}
\journalhomepage{}
\journallogo{}
\journalcover{}
\bannercolor{gray!15}

% ------------------------------------------------------------
% Keywords printer: one keyword per line (accepts ; or ,)
% Robust LaTeX2e version (no expl3, no duplication)
% ------------------------------------------------------------
\makeatletter

% Convert semicolons to commas (recursive, with sentinel \relax)
\def\ij@semicolon_to_comma#1;#2\@nil{%
  #1%
  \ifx\relax#2\relax
  \else
    ,\ij@semicolon_to_comma#2\@nil
  \fi
}

% Print one keyword per line (trims leading/trailing spaces visually)
\newcommand{\ijPrintKeywords}[1]{%
  \begingroup
    % Expand argument into text
    \edef\ij@kwtmp{#1}%
    % Convert ';' -> ',' so \@for can split
    \edef\ij@kwtmp{\expandafter\ij@semicolon_to_comma\ij@kwtmp;\relax\@nil}%
    % Loop over comma-separated list
    \@for\ij@kw:=\ij@kwtmp\do{%
      \edef\ij@kwtest{\ij@kw}%
      \ifx\ij@kwtest\@empty\relax\else
        \ignorespaces\ij@kw\unskip\par
      \fi
    }%
  \endgroup
}


% ------------------------------------------------------------------
% Banner drawing  (KEEP AS IS — unchanged from your current version)
% ------------------------------------------------------------------
\newcommand{\ij@drawbanner}{%
  % Top reference line
  \ifx\ij@articlehead\@empty\else
    {\par\centering\footnotesize\color{blue}\ij@articlehead\par}%
  \fi
  \vspace{0.55em}
  \noindent\hrule height 0.4pt\par
  \vspace{0.55em}

  % Main grey banner
  \begingroup
  \setlength{\fboxsep}{3pt}%
  \noindent\colorbox{\ij@bannercolor}{%
    % subtract padding so total width stays == \textwidth
    \parbox{\dimexpr\textwidth-2\fboxsep\relax}{%

      % --- existing content ---
      \begin{minipage}[c]{0.18\textwidth}\centering
        \ifx\ij@journallogo\@empty\relax\else
          \includegraphics[width=0.70\linewidth, trim=0 20mm 0 0,clip]{\ij@journallogo}\par
          \vspace{-15pt}
          {\color{orange}\bfseries\small ESN Publishing}
        \fi
      \end{minipage}\hfill
      \begin{minipage}[c]{0.60\textwidth}\centering

        % "Contents lists available at ..." (MOVE INTO CENTER BLOCK FOR COMPACTNESS)
        {\footnotesize\textbf{Contents lists available at }%
        \ifx\ij@platformname\@empty
          {ESN Publishing Journals}\par
        \else
          \ifx\ij@platformurl\@empty
            \ij@platformname\par
          \else
            \href{\ij@platformurl}{\ij@platformname}\par
          \fi
        \fi
        }%
        \vspace{1.25em} % (kept as-is)

        {\Large\bfseries \journalname}\par
        \vspace{1.25em} % (kept as-is)
        \ifx\ij@journalhomepage\@empty\relax\else
          {\footnotesize journal homepage: \href{\ij@journalhomepage}{\ij@journalhomepage}}\par
        \fi
      \end{minipage}\hfill
      \begin{minipage}[c]{0.18\textwidth}\centering
        \ifx\ij@journalcover\@empty\relax\else
          \includegraphics[width=0.85\linewidth]{\ij@journalcover}
        \fi
      \end{minipage}%
    }%
  }\par
  \endgroup

  \vspace{0.35em}
  \noindent\rule{\textwidth}{1.2pt}\par
  \vspace{1.2em}
}

% ------------------------------------------------------------
% First-page footnote block (Corresponding, DOI, dates, etc.)
% ------------------------------------------------------------
\newcommand{\ij@firstpagefoottext}{%
  \scriptsize
  \ifx\ij@corrauthor\@empty\else
    $\ast$~Corresponding author. 
  \fi
  \ifx\ij@cormail\@empty\else
    E-mail address: \href{mailto:\ij@cormail}{\ij@cormail}. \par
  \fi
  \ifx\ij@received\@empty\else
    Received~\ij@received%
    \ifx\ij@revised\@empty\else; Revised~\ij@revised\fi%
    \ifx\ij@accepted\@empty\else; Accepted~\ij@accepted\fi%
    \par
  \fi
  \ifx\ij@availableonline\@empty\else
    Available online~\ij@availableonline\par
  \fi
  \ifx\ij@doi\@empty\else
    \href{https://doi.org/\ij@doi}{https://doi.org/\ij@doi}\par
  \fi
  \ifx\ij@copyright\@empty\else
    \ij@copyright\par
  \fi
}

\newcommand{\ij@addfirstpagefootnote}{%
  \begingroup
    \renewcommand{\thefootnote}{}%
    \footnotetext{\ij@firstpagefoottext}%
    \addtocounter{footnote}{-1}%
  \endgroup
}

% ------------------------------------------------------------------
% IJDTDE abstract block (still one-column overall)
% ARTICLE INFO = keywords only, one keyword per line
% ABSTRACT wider
% ------------------------------------------------------------------
\renewenvironment{abstract}{%
  \par
  \vspace{0.25em}%
  \noindent\hrule height 0.4pt\par
  \vspace{0.6em}%
  \noindent
  \begin{minipage}[t]{0.24\textwidth}%
    \raggedright
    \setlength{\parindent}{0pt}%
    \setlength{\parskip}{0pt}%
    {\bfseries\footnotesize ARTICLE INFO}\par
    \vspace{0.5em}%
    \ifx\ij@articletype\@empty\else
      {\footnotesize\textit{Article type:}}\par
      {\footnotesize\normalfont\ij@articletype}\par
      \vspace{0.6em}%
    \fi
    \ifx\ij@keywords\@empty\else
      {\footnotesize\textit{Keywords:}}\par
      \footnotesize\normalfont
      \ijPrintKeywords{\ij@keywords}%
    \fi
  \end{minipage}\hfill%
  \begin{minipage}[t]{0.72\textwidth}%
    \justifying
    \setlength{\parindent}{0pt}%
    \setlength{\parskip}{0pt}%
    {\bfseries\footnotesize ABSTRACT}\par
    \vspace{0.5em}%
    \footnotesize\normalfont
}{%
    \par
  \end{minipage}%
  \par
  \vspace{0.6em}%
  \noindent\hrule height 0.4pt\par
  \vspace{1.0em}%
  \normalsize\normalfont
}

% Optional environments
\newenvironment{highlights}{%
  \section*{Highlights}
  \begin{itemize}[leftmargin=1.2em]
}{%
  \end{itemize}
}

\newenvironment{graphicalabstract}{%
  \section*{Graphical abstract}
  \begin{center}
}{%
  \end{center}
}

% ------------------------------------------------------------
% Tight IJDTDE title block using authblk internals
% (prevents the big gap; keeps one-column)
% ------------------------------------------------------------
\renewcommand{\AB@maketitle}{%
  \par\noindent
  \ifx\ij@articletype\@empty\else
    {\footnotesize\bfseries\color{orange}\centering
      \MakeUppercase{\ij@articletype}\par}
    \vspace{0.45em}
  \fi
  {\ij@titlefont \centering \@title\par}
  \vspace{0.95em}
  {\ij@authorfont \centering \AB@authlist\par}
  \vspace{0.65em}
  {\ij@affilfont \centering \AB@affillist\par}
  \vspace{0.65em}
}

% Patch \maketitle: draw banner, then title/authors, then first-page info
\renewcommand{\maketitle}{%
  \thispagestyle{empty}%
  \hypersetup{
    pdftitle={\@title},
    pdfauthor={\ij@pdfauthorline},
    pdfsubject={\ij@pdfsubjectline},
    pdfkeywords={\ij@keywords},
    pdfcreator={LaTeX with IJDTDE class},
    pdfproducer={European Scientific Network Publishing}
  }%
  \ij@drawbanner
  \vspace{\ij@afterbanner@vspace}% tighten the gap under banner

  % Anonymous mode support
  \begingroup
    \ifij@anonymous
      \def\AB@authlist{Anonymous Author(s)\par}%
      \def\AB@affillist{}%
    \fi
    \AB@maketitle
  \endgroup

  % First-page-only footnote block (bottom of page 1)
  \ij@addfirstpagefootnote
}

% Paragraph spacing closer to journal look (compact)
\setlength{\parskip}{0pt}
\setlength{\parindent}{1.2em}

\makeatother
