% \iffalse meta-comment
%
% RWTH-CI -- Corporate Design for RWTH Aachen
% ----------------------------------------------------------------------------
%
%  Copyright (C) 2025 by Marei Peischl <rwth-ci@peitex.de> and Lukas C. Bossert
%
% ============================================================================
% This work may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, either version 1.3c
% 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.3c or later is part of all distributions of LaTeX
% version 2008/05/04 or later.
%
% This work has the LPPL maintenance status `maintained'.
%
% The Current Maintainer of this work is
%   Marei Peischl <rwth-ci@peitex.de>
%
% The development repository can be found at
% https://git.rwth-aachen.de/rwth-latex
% Please use the issue tracker for feedback!
% ============================================================================
%
% \fi
% \iffalse
%<*driver>
\ProvidesFile{rwth-sciposter.dtx}
  [2025-12-18 v1.0 Sciposter for RWTH-CI, Corporate Design of RWTH Aachen]
%</driver>
%<@@=ptxcd>
%<*identification>
\NeedsTeXFormat{LaTeX2e}[2022-10-01]
%<class>\ProvidesExplClass{rwth-sciposter}{2025-12-18}{1.0}{Sciposter for RWTH-CI}
%</identification>
%<*driver>
\providecommand*{\PtxcdDocDTXfiles}{rwth-sciposter.dtx}
\providecommand*{\PtxcdDocTitle}{Scientific Posters for RWTH-CI}
\input{rwth-ci.dtx}
%</driver>
%<*initialize>
% \fi
% \begin{documentation}
% \section{Scientific Posters – \cls{rwth-sciposter.cls}}
% The Scientific poster template is based on the \pkg{tcolorbox} poster library.
% Please have a look at the corresponding documentation for a full list of configuration options.
% The demo file corresponding to this is called \file{DEMO-RWTHSciPoster.tex}.
% \end{documentation}
% \begin{implementation}
%    \begin{macrocode}
\tl_new:N \g_ptxcd_boxstyle_tl
\tl_gset:Nn \g_ptxcd_boxstyle_tl {RWTH}
\box_new:N \g_ptxcd_title_box

\dim_const:Nn \c_ptxcd_rulesep_dim {1cm}
%    \end{macrocode}
% \iffalse
%</initialize>
%<*declareoptions>
% \fi
%    \begin{macrocode}
\keys_define:nn {ptxcd/sciposter} {
%    \end{macrocode}
% \iffalse
%</declareoptions>
%<*options>
%</options>
%<*processoptions>
% \fi
%    \begin{macrocode}
}

\prop_gput:Nnn \g_ptxcd_clsopts_prop {captions} {nooneline}

\ProcessKeyOptions[ptxcd/sciposter]

\dim_new:N \g_ptxcd_margin_dim
\dim_const:Nn \c_@@_logo_height_dim {90.5mm}
\dim_const:Nn \c_@@_logo_sep_dim {14.15mm}
%    \end{macrocode}
% \iffalse
%</processoptions>
%<*body>
% \fi
%    \begin{macrocode}
\prop_map_inline:Nn \g_ptxcd_clsopts_prop {
  \tl_if_empty:nTF {#2}
  {\PassOptionsToClass{#1}{scrartcl}}
  {\clist_map_inline:nn {#2} {\PassOptionsToClass{#1=##1}{scrartcl}}}
}
\PassOptionsToPackage{typeareawarninfolimit=-1,DIV=10}{typearea}
\LoadClass[parskip=full-]{scrartcl}
%    \begin{macrocode}
\PassOptionsToPackage{fontdefaults}{rwth-fonts}
\RequirePackage{rwth-fonts}
\PassOptionsToPackage{cmyk}{rwth-colors}
\RequirePackage{rwth-colors}
\RequirePackage[margin=0pt]{geometry}
\RequirePackage{tcolorbox}
\tcbuselibrary{poster}
\RequirePackage{qrcode}

\setkomafont{disposition}{}
\setkomafont{title}{
  \fontsize{90bp}{108bp}\selectfont
}
\setkomafont{subtitle}{\fontsize{48bp}{58bp}\selectfont}
\setkomafont{author}{\bfseries}

\setkomafont{section}{\bfseries\fontsize{38bp}{46bp}\selectfont}
\setkomafont{subsection}{\bfseries\fontsize{38bp}{46bp}\selectfont}

\setkomafont{pagefoot}{\fontsize{22.5bp}{27bp}\selectfont}
\setkomafont{captionlabel}{\bfseries}
\setkomafont{caption}{\fontsize{16bp}{20bp}\selectfont}
\tcbset{
RWTH/.style =	{
empty,
coltitle=black,
colbacktitle=white,
coltext=black,
size=minimal,
boxrule=\z@,
leftrule=\z@,
rightrule=\z@,
fonttitle=\usekomafont{disposition}\usekomafont{section},
before~title={\strut},
toptitle=.5\c_ptxcd_rulesep_dim,
bottomtitle=.5\c_ptxcd_rulesep_dim,
top=.5\c_ptxcd_rulesep_dim,
bottom=.5\c_ptxcd_rulesep_dim,
parbox=false,
frame~empty,
interior~empty,
},
RWTH-inner/.style =
  {
    RWTH,
    fonttitle=\usekomafont{disposition}\usekomafont{subsubsection}
  }
}

%    \end{macrocode}
% Select default box styles according to style option
%    \begin{macrocode}
\tcbposterset{boxes ={\g_ptxcd_boxstyle_tl}}

\tcbset{%
  poster/.cd,
  spacing=2\c_ptxcd_rulesep_dim,
  rows=6,
  showframe=false,
  prefix=TCBPOSTER@,
}

\tcbset{
every~ box~ on~ layer~ 3/.style={reset,\g_ptxcd_boxstyle_tl -inner},
every~ box~ on~ layer~ 4/.style={reset,\g_ptxcd_boxstyle_tl -inner},
}

\bool_if:NT \g_@@_raggedright_bool {
\tcbset{RWTH/.append~style={halign=flush~left}}
}

\pagestyle{empty}
%    \end{macrocode}
% \end{implementation}
% \begin{documentation}
% \subsection{Additional title elements}
% The basic title setup using |\title| and |\author| works the same way as it does for standard \LaTeX.
% RWTH-CI provides some additional commands to extend that data.
% \end{documentation}
% \begin{implementation}
% \begin{macro}{\title}
%    \begin{macrocode}
\renewcommand*{\title}[1]{\gdef \@title {#1}}
%    \end{macrocode}
% \end{macro}
%    \begin{macrocode}
\tl_new:N \g_ptxcd_poster_qrcode_tl
\msg_new:nnnn {rwth-sciposter} {biblatex-required}{
  You~tried~to~use~#1.\\
  This~feature~requires~the~biblatex~package.
} {
  Try~to~remove~the~star~or~load~biblatex.
}
%    \end{macrocode}
% \end{implementation}
% \begin{documentation}
% \DescribeMacro{\footerqrcode}
% Create a QRcode to be placed in the footer.
% The starred variant allows to use a citekey for reference.
% \end{documentation}
% \begin{implementation}
% \begin{macro}{\footerqrcode}
%    \begin{macrocode}
\NewDocumentCommand{\footerqrcode}{sm}{
  \IfBooleanTF {#1} {
    \cs_if_exist:NTF \blx@blxinit {
      \begingroup
      \blx@blxinit
      \entrydata{#2}{
        \tl_gset:Nx \g_ptxcd_poster_qrcode_tl{\thefield{url}}
      }
      \endgroup
    }{
      \msg_error:nnx {rwth-sciposter} {biblatex-required} {\use:c{footerqrcode*}}
    }
  }{
    \tl_gset:Nn \g_ptxcd_poster_qrcode_tl {#2}
  }
}
%    \end{macrocode}
% \end{macro}
% \end{implementation}
% \begin{implementation}
% \begin{macro}{\author}
%    \begin{macrocode}
\seq_new:N \g_ptxcd_author_seq
\renewcommand*\author[1]{
  \seq_gset_split:Nnn \g_ptxcd_author_seq {\and} {#1}
}
%    \end{macrocode}
% \end{macro}
%    \begin{macrocode}
\msg_new:nnn {rwth-sciposter} {unknown-language} {
  You~selected~an~unknown~language~#1.\\
  The~Variable~#2~does~not~have~a~predefined~value.\\
  Ensure~to~redefine~#2~to~match~your~language.\\
  Otherwise~the~ngerman~vaue~#3~will~be~used.
}
%    \end{macrocode}
% The language dependent setting to split multiple authors is saved within this macro.
% The bundle provides English \enquote{and} as well as German \enquote{und}.
% In case another language is used, one could overwrite this setting.
% \begin{macro}{\authorandname}
%    \begin{macrocode}
\providecommand*\authorandname{
  \msg_warning:nnxxx {rwth-sciposter} {unknown-language}
  {\languagename} {\exp_not:N \authorandname} {und}
  und
}
%    \end{macrocode}
%    \begin{macrocode}
\defcaptionname{ngerman, german}{\authorandname}{und}
\defcaptionname{english, USenglish, american, UKenglish, british}{\authorandname}{and}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\@author}
%    \begin{macrocode}
\renewcommand*{\@author}{
  \seq_use:Nnnn \g_ptxcd_author_seq {~\authorandname{}~} {,~} {~\&~}
}
%    \end{macrocode}
% \end{macro}
% \end{implementation}
% \begin{documentation}
% \DescribeMacro{\contactinfo}
% This command is used to set additional contact data for the footer, for example:
% \begin{examplecode}
% \contactinfo{
%   Telefon: +49 241 80-94123\\
%   E-Mail: kim.muster@mx.rwth-aachen.de
% }
% \end{examplecode}
% \end{documentation}
% \begin{implementation}
% \begin{macro}{\contactinfo}
%    \begin{macrocode}
\newcommand{\contactinfo}[1]{\def\@contactinfo{\ignorespaces#1}}
\contactinfo{}
%    \end{macrocode}
% \end{macro}
% \end{implementation}
% \begin{documentation}
% \DescribeMacro{\addressdata}
% \begin{examplecode}
% \addressdata{
%   Institut für maximale Ausdehnung der Logosystematik\\
%   RWTH Aachen University\\
%   Musterstraße 7, 52074 Aachen, GERMANY\\
% }
% \end{examplecode}
% \end{documentation}
% \begin{implementation}
% \begin{macro}{\addressdata}
%    \begin{macrocode}
\newcommand{\addressdata}[1]{\def\@addressdata{\ignorespaces#1}}
\addressdata{}
%    \end{macrocode}
% \end{macro}
% \end{implementation}
% \begin{implementation}
% Language dependent configuration
%    \begin{macrocode}
\AtBeginDocument{
  \@ifpackageloaded{babel}{
    \addto\extrasngerman{\def\authorandname{und}}
    \addto\extrasgerman{\def\authorandname{und}}
    \addto\extrasenglish{\def\authorandname{and}}
    \addto\extrasbritish{\def\authorandname{and}}
    \addto\captionsngerman{\renewcommand{\figurename}{Abb.}}
    \addto\captionsgerman{\renewcommand{\figurename}{Abb.}}
    \addto\captionsenglish{\renewcommand{\figurename}{Fig.}}
    \addto\captionsbritish{\renewcommand{\figurename}{Fig.}}
  }{}
}

\dim_new:N \g_ptxcd_bottom_margin_dim
\dim_new:N \g_ptxcd_footheight_dim
\dim_new:N \g_ptxcd_qrcode_dim
\dim_new:N \g_ptxcd_footsep_dim
\dim_new:N \g_@@_footerblock_dim

\newlength{\contentwidth}
\newlength{\contentheight}
\tcbposterset{
  coverage =
    {
      spread,
      parbox=false,
      bottom=\dim_eval:n {\g_ptxcd_bottom_margin_dim+ \c_ptxcd_rulesep_dim},
      left=\g_ptxcd_margin_dim,
      right=\g_ptxcd_margin_dim,
      before= {\__ptxcd_poster_setup_margins_and_title:},
      top= \dim_eval:n {
        \bool_if:NTF \g_@@_logo_bottom_bool  {.5\c_@@_logo_height_dim+\g_ptxcd_margin_dim}  {1.5\c_@@_logo_height_dim}
        + \box_dp:N \g_ptxcd_title_box
        + 2.5\c_ptxcd_rulesep_dim
      },
      underlay={%
          \node[
            inner~sep=0pt,
            anchor=north~east
          ](logo) at ([xshift=\dim_eval:n {-\g_ptxcd_margin_dim+\c_@@_logo_sep_dim}]\paperwidth, \dim_eval:n {\bool_if:NTF \g_@@_logo_bottom_bool {\g_ptxcd_bottom_margin_dim}{\paperheight}}){
            \__ptxcd_insert_logo:n {\c_@@_logo_height_dim}
          };
%    \end{macrocode}
% Titleblock
%    \begin{macrocode}
          \node[anchor=base~west,inner~sep=0pt]  (title) at (
          \g_ptxcd_margin_dim,
% base top margin
          \dim_eval:n {\paperheight\bool_if:NTF \g_@@_logo_bottom_bool  {-.5\c_@@_logo_height_dim-\g_ptxcd_margin_dim} {-1.5\c_@@_logo_height_dim}}
          ) {\box_use:N \g_ptxcd_title_box};
%    \end{macrocode}
% Rules
%    \begin{macrocode}
          \draw[line~width=1pt] (\g_ptxcd_margin_dim,\g_ptxcd_bottom_margin_dim) --++(\contentwidth,0)
          (\g_ptxcd_margin_dim,\dim_eval:n {\paperheight\bool_if:NTF \g_@@_logo_bottom_bool {-\g_ptxcd_margin_dim} {-\c_@@_logo_height_dim}}) --++(\contentwidth,0);
%    \end{macrocode}
% QRCode
%    \begin{macrocode}
          \coordinate(lastpos) at (
          \g_ptxcd_margin_dim,
          \g_ptxcd_bottom_margin_dim- \g_ptxcd_footsep_dim
          ) ;
          \tl_if_empty:NF \g_ptxcd_poster_qrcode_tl
          {
            \node[anchor=north~west, inner~sep=\z@,outer~sep=\z@] (qrcode) at (lastpos)
            {
              \exp_args:NnV \use:n {\qrcode[height=\dim_use:N \g_ptxcd_qrcode_dim]}\g_ptxcd_poster_qrcode_tl
            };
            \coordinate (lastpos) at (qrcode.north~east);
          }
%    \end{macrocode}
% Contact info
%    \begin{macrocode}
          \node[anchor=north~ west, inner~ sep=\z@] (contact) at ([xshift=2\c_ptxcd_rulesep_dim]lastpos) {
            \usekomafont{pagefoot}
            \parbox[t][\dim_eval:n {\g_ptxcd_qrcode_dim+\dp\strutbox}][t]{
              \dim_eval:n {
                \g_@@_footerblock_dim
                - \g_ptxcd_qrcode_dim
                - 2\c_ptxcd_rulesep_dim
              }}{

              \raggedright
              \@author
              \par\medskip
              \vfill
              \strut\@contactinfo\strut
            }
          };
% block does not exist in portrait + logo=bottom
%    \end{macrocode}
% Address. Will not be used if |landscape=false| and |logo=bottom|.
%    \begin{macrocode}
          \if@landscape
            \def\@temp{\use:n}
          \else
            \bool_if:NTF \g_@@_logo_bottom_bool
            {\def\@temp{\use_none:n}}
            {\def\@temp{\use:n}}
          \fi
          \@temp
          {
            \node[anchor=\if@landscape north~west\else north~ east\fi, inner~ sep=\z@] (address) at (
            \dim_eval:n {
              \if@landscape
                \g_ptxcd_margin_dim
                + \g_@@_footerblock_dim
                +2\c_ptxcd_rulesep_dim
              \else
                \paperwidth- \g_ptxcd_margin_dim
              \fi
            },
            \g_ptxcd_bottom_margin_dim- \g_ptxcd_footsep_dim)  {
              \usekomafont{pagefoot}
              \parbox[t][\dim_eval:n {\g_ptxcd_qrcode_dim+\dp\strutbox}][t]{
                \dim_eval:n {\if@landscape1.5\g_@@_footerblock_dim+\c_ptxcd_rulesep_dim\else\g_@@_footerblock_dim\fi}
              }{
                \raggedright
                \@addressdata
              }
            };
          }

        }
    }
}

\dim_new:N \g_ptxcd_titleblock_dim

\cs_new:Nn \__ptxcd_poster_setup_margins_and_title: {

  \if@landscape
    \tcbset{poster/columns=8}
    \dim_gset:Nn \g_ptxcd_margin_dim {4.39cm}
    \dim_gset:Nn \g_ptxcd_bottom_margin_dim  {9.05cm}
    \dim_set:Nn \g_ptxcd_qrcode_dim {2.5cm}
    \dim_gset:Nn \g_ptxcd_footsep_dim {1.25cm}
  \else
    \tcbset{poster/columns=6}
    \dim_gset:Nn \g_ptxcd_margin_dim {4cm}
    \bool_if:NTF \g_@@_logo_bottom_bool  {
      \dim_gset:Nn \g_ptxcd_bottom_margin_dim  {9.05cm}
    } {
      \dim_gset:Nn \g_ptxcd_bottom_margin_dim  {11.4cm}
    }
    \dim_set:Nn \g_ptxcd_qrcode_dim {5.4cm}
    \bool_if:NTF \g_@@_logo_bottom_bool
    {\dim_gset:Nn \g_ptxcd_footsep_dim {1.5cm}}
    {\dim_gset:Nn \g_ptxcd_footsep_dim {1.9cm}}
  \fi
  \setlength{\contentwidth}{\dimexpr\paperwidth-2\g_ptxcd_margin_dim\relax}
  \dim_gset:Nn  \g_@@_footerblock_dim {
    \dim_eval:n {(2\contentwidth +4\c_ptxcd_rulesep_dim)/ \tcb@poster@columns - 2\c_ptxcd_rulesep_dim}
  }
  \hbox_gset:Nn \g_ptxcd_title_box {
    \parbox[t]{\contentwidth}{
      \raggedright
      \usekomafont{disposition}
      {\usekomafont{title}\leavevmode\strut\@title\strut\par}
      {\usekomafont{subtitle}\vskip.5ex\leavevmode\strut\@subtitle\strut\par}
    }
  }
}
%    \end{macrocode}
% \iffalse
%</body>
% \fi
% \end{implementation}
% \Finale
\endinput
