%%
%% This is file `fhjpaper.cls',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% fhjpaper.dtx  (with options: `class')
%% 
%% Copyright 2025-2026 Michael E. Hammer
%% 
%% This work 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 2005/12/01 or later.
%% 
%% This work has the LPPL maintenance status `maintained'.
%% 
%% The Current Maintainer of this work is Michael E. Hammer.
%% 
%% This file is part of the "fhj-script bundle" and all files in that
%% bundle must be distributed together.
%% 
\NeedsTeXFormat{LaTeX2e}[2023-11-01]
\ProvidesClass{fhjpaper}
    [2026-07-31 v4.3b A class for formatting papers in the FHJ style]
\newcommand{\FHJ@ClassName}{fhjpaper}
\DeclareOption*{\PassOptionsToClass{\CurrentOption}{scrartcl}}
\ProcessOptions\relax
\LoadClass[a4paper,twocolumn,fontsize=9pt,DIV=16]{scrartcl}
\RequirePackage{fhjcommon}
\RequirePackage{etoolbox}
\PassOptionsToPackage{pagestyleset=standard}{scrlayer-scrpage}
\RequirePackage{scrlayer-scrpage}
\PassOptionsToPackage{hidelinks}{hyperref}
\RequirePackage{hyperref}
\renewcommand*{\title}[1]{\renewcommand*{\@title}{{#1}}}
\newcommand{\shorttitle}[1]{\newcommand{\FHJ@ShortTitle}{{#1}}}
\newcommand{\FHJ@CheckTitle}{%
  \@ifundefined{@title}{%
    \ClassWarningNoLine{fhjpaper}{Title not defined \title{Title}}}
  \@ifundefined{FHJ@ShortTitle}{%
    \ClassWarningNoLine{fhjpaper}{Shorttitle not defined \shorttitle{Shorttitle}}}
}
%%-------------------------------------------------------------------------------------
%% authors handling
%% Taken von apa7 class --> See: https://ctan.org/tex-archive/macros/latex/contrib/apa7

\newcommand{\FHJ@CheckAuthor}{%
  \@ifundefined{FHJ@MultipleAuthors}{%
    \ClassWarningNoLine{fhjpaper}{Author not defined \authorsnames{Author}}}
  \@ifundefined{FHJ@MultipleAffils}{%
    \ClassWarningNoLine{fhjpaper}{Affiliation not defined \authorsaffiliations{Affiliation}}}
  \@ifundefined{FHJ@MultipleAuthors}{}{%
   \ifnum\value{NumberOfSuperscripts}=0%
    % do nothing. If no superscripts are specified, print authors and affiliations without superscripts.
   \else%
      \ifnum\value{NumberOfAuthors}=\value{NumberOfSuperscripts}%
        % do nothing
      \else
        \ClassError{fhjpaper}{Number of Authors does not match number of Superscripts}%
          {Please provide an equal number of authors and superscripts.}%
  \fi
   \fi
  }%
}

%% German and English!
\newcommand*{\FHJ@LastAuthorSeparator}{UNDEF}
\iflanguage{english}{\renewcommand*{\FHJ@LastAuthorSeparator}{and}}{}
\iflanguage{ngerman}{\renewcommand*{\FHJ@LastAuthorSeparator}{und}}{}

\newcommand*\FHJ@ListAuthors{}
\newcommand*\FHJ@ListSuperscripts{}
\newcommand*\FHJ@ListAffiliations{}
\newcounter{NumberOfAuthors}
\newcounter{NumberOfSuperscripts}

\newcommand*{\authorsnames}[2][]{%
  \def\FHJ@MultipleAuthors{} %
  \renewcommand*\FHJ@ListAuthors{}
  \renewcommand*\FHJ@ListSuperscripts{}
  \setcounter{NumberOfAuthors}{0}
  \setcounter{NumberOfSuperscripts}{0}
  \forcsvlist{\stepcounter{NumberOfAuthors}\listadd\FHJ@ListAuthors}{#2}
  \forcsvlist{\stepcounter{NumberOfSuperscripts}\listadd\FHJ@ListSuperscripts}{#1}
}

\newcounter{NumberOfAffiliations}
\newcommand*{\authorsaffiliations}[1]{%
  \def\FHJ@MultipleAffils{} %
  \renewcommand*\FHJ@ListAffiliations{}
  \setcounter{NumberOfAffiliations}{0}
  \forcsvlist{\stepcounter{NumberOfAffiliations}\listadd\FHJ@ListAffiliations}{#1}
}

\catcode`\|=3
\def\FHJ@LoopTwo#1#2{%
    \edef\FHJ@Tmp{\noexpand\FHJ@XTwo%
      \unexpanded\expandafter{#1}\relax  % no added delimiter here
      \unexpanded\expandafter{#2}\relax  % no added delimiter here
    } \FHJ@Tmp%
  }%

\def\FHJ@XTwo#1|#2\relax#3|#4\relax{%
    \FHJ@DoTwo{#1}{#3}%
    \def\FHJ@Tmp{#2}%
    \ifx\empty\FHJ@Tmp%
      \expandafter\@gobble%
    \else%
      \expandafter\@firstofone%
    \fi%
    {\FHJ@XTwo#2\relax#4\relax}%
  }%

\catcode`\|=12

\newcommand*{\FHJ@DoTwo}[2]{}

\newcommand*{\FHJ@AuthorSep}{}%
\newcommand*{\FHJ@LastAuthor}{}%
\newcommand*{\FHJ@PrelastAuthor}{}%
\newcommand*{\FHJ@PrelastAuthorSep}{}%

\newcommand{\FHJ@DisplayAuthors}{%
  \renewcommand*{\FHJ@AuthorSep}{}%
  \renewcommand*{\FHJ@LastAuthor}{}%
  \renewcommand*{\FHJ@PrelastAuthor}{}%
  \renewcommand*{\FHJ@PrelastAuthorSep}{}%
  \ifnum\value{NumberOfSuperscripts}=0% If no superscripts are specified, print authors without superscripts.
  \renewcommand*{\do}[1]{%
      \FHJ@AuthorSep%
      \FHJ@LastAuthor%
      \renewcommand{\FHJ@LastAuthor}{%
        \renewcommand{\FHJ@AuthorSep}{,
          \renewcommand*{\FHJ@PrelastAuthorSep}{,}}%
        \renewcommand{\FHJ@PrelastAuthor}{\FHJ@PrelastAuthorSep\ \FHJ@LastAuthorSeparator\ }% Terminated commands with \ to preserve following space
        ##1%
      }%
    }%
    \dolistloop{\FHJ@ListAuthors}%
  \else
    \renewcommand*{\FHJ@DoTwo}[2]{%
      \FHJ@AuthorSep%
      \FHJ@LastAuthor%
      \renewcommand{\FHJ@LastAuthor}{%
        \renewcommand{\FHJ@AuthorSep}{,
          \renewcommand*{\FHJ@PrelastAuthorSep}{,}}%
        \renewcommand{\FHJ@PrelastAuthor}{\FHJ@PrelastAuthorSep\ \FHJ@LastAuthorSeparator\ }% Terminated commands with \ to preserve following space
        ##1\textsuperscript{##2}%
      }%
    }%
    \FHJ@LoopTwo\FHJ@ListAuthors\FHJ@ListSuperscripts%
  \fi
  \FHJ@PrelastAuthor \FHJ@LastAuthor%
}

\newcommand{\FHJ@DisplayAffiliations}{%
  \ifnum\value{NumberOfSuperscripts}=0% If no superscripts are specified, print affiliations without superscripts.
    \renewcommand*{\do}[1]{%
        ##1\\%
    }%
  \else
    \newcounter{AffiliationNumber}
    \renewcommand*{\do}[1]{%
        \stepcounter{AffiliationNumber}
        \textsuperscript{\arabic{AffiliationNumber}}##1\\%
    }%
  \fi
  \dolistloop{\FHJ@ListAffiliations}%
}
\ofoot{\FHJ@ShortTitle}
\ifoot{\FHJProgramLong}
\setcounter{secnumdepth}{2}
\renewcommand*{\@maketitle}{
  \cleardoublepage
  \FHJ@CheckAuthor
  \FHJ@CheckTitle
  % title
  \begin{minipage}{\textwidth}\begin{center}
    \fontsize{14}{18}\selectfont
    \textbf{\@title}
    \vspace{1em}
  \end{center}\end{minipage}
  % authors
  \begin{minipage}{\textwidth}\begin{center}
    \FHJ@DisplayAuthors
    \vspace{1em}
  \end{center}\end{minipage}
  % affiliations
  \begin{minipage}{\textwidth}\begin{center}
    \FHJ@DisplayAffiliations
    \vspace{2em}
  \end{center}\end{minipage}
}
%%
%%  Maybe some future additional macros ...
%%
\endinput
%%
%% End of file `fhjpaper.cls'.
