% This is file `letgut.cls',
% generated with the Emacs Org-babel utility.
%
% The original source file is letgut-banner.org
%
% -------------:| ---------------------------------------------------
% letgut-banner:| Package for the banner of the newsletter
%               | “La Lettre GUTenberg”
%        Author:| Association GUTenberg
%        E-mail:| secretariat@gutenberg.eu.org
%       License:| Released under the LaTeX Project Public License
%               |  v1.3c or later
%           See:| http://www.latex-project.org/lppl.txt
%
% Copyright (C) 1994-2022 by Association GUTenberg
% <secretariat@gutenberg.eu.org>
%
% This work may be distributed and/or modified under the
% conditions of the LaTeX Project Public License (LPPL), either
% version 1.3c of this license or (at your option) any later
% version.  The latest version of this license is in the file:
%
% http://www.latex-project.org/lppl.txt
%
% This work is “maintained” (as per LPPL maintenance status)
% by Association GUTenberg.
\NeedsTeXFormat{LaTeX2e}[2020-10-01]
\ProvidesExplPackage{letgut-banner}
{2022-03-22}
{0.9.1}
{
  Package for the banner of the newsletter “La Lettre de GUTenberg”
}
\RequirePackage{l3keys2e}
\RequirePackage{xcolor}
\RequirePackage{accsupp}
\keys_define:nn { letgut-banner }
{
  , pagecolor .clist_gset:N = \g__letgutbanner_pagecolor_clist
  , pagecolor .initial:n = { 1,1,1 }
}
\ProcessKeysOptions { letgut-banner }
\AddToHook{begindocument}{
\cs_generate_variant:Nn \color_fill:nn { nV }
\dim_new:N \g__letgutbanner_area_height_dim
\dim_new:N \g__letgutbanner_La_height_dim
\dim_new:N \g__letgutbanner_La_depth_dim
\dim_new:N \g__letgutbanner_La_yoffset_dim
\dim_new:N \g__letgutbanner_banner_vertical_contents_width_dim
\dim_new:N \g__letgutbanner_largest_LETR_box_height_dim
\dim_new:N \g__letgutbanner_between_letters_yoffset_dim
\dim_new:N \g__letgutbanner_between_letters_vertical_space_dim
\dim_new:N \g__letgutbanner_banner_padding_dim
\dim_if_exist:NF \g__letgutbanner_first_page_shrink_dim {
  \dim_new:N \g__letgutbanner_first_page_shrink_dim
}
\cs_generate_variant:Nn \dim_const:Nn { NV }
\dim_if_exist:NTF \c__letgut_textheight_dim {
  \dim_const:NV \c__letgutbanner_textheight_dim
  \c__letgut_textheight_dim
}{
  \dim_const:Nn \c__letgutbanner_textheight_dim
  { 25cm }
}
\dim_if_exist:NTF \c__letgut_textwidth_dim {
  \dim_const:NV \c__letgutbanner_textwidth_dim
  \c__letgut_textwidth_dim
}{
  \dim_const:Nn \c__letgutbanner_textwidth_dim
  { 14cm }
}
\dim_if_exist:NTF \c__letgut_lmargin_dim {
  \dim_const:NV \c__letgutbanner_lmargin_dim
    \c__letgut_lmargin_dim
}{
  \dim_const:Nn \c__letgutbanner_lmargin_dim
  { 5cm }
}
\dim_if_exist:NTF \c__letgut_tmargin_dim {
  \dim_const:NV \c__letgutbanner_tmargin_dim
    \c__letgut_tmargin_dim
}{
  \dim_const:Nn \c__letgutbanner_tmargin_dim
  { 2.92cm }
  % \dim_const:Nn \c__letgutbanner_tmargin_dim
  % { 3cm }
}
\dim_if_exist:NTF \c__letgut_head_dim {
  \dim_const:NV \c__letgutbanner_head_dim
    \c__letgut_head_dim
}{
  \dim_const:Nn \c__letgutbanner_head_dim
  { 0.6cm }
}
\dim_if_exist:NTF \c__letgut_headsep_dim {
  \dim_const:NV \c__letgutbanner_headsep_dim
    \c__letgut_headsep_dim
}{
  \dim_const:Nn \c__letgutbanner_headsep_dim
  { 0.82cm }
  % \dim_const:Nn \c__letgutbanner_headsep_dim
  % { 0.9cm }
}
\dim_if_exist:NTF \c__letgut_marginparwidth_dim {
  \dim_const:NV \c__letgutbanner_marginparwidth_dim
  \c__letgut_marginparwidth_dim
}{
  \dim_const:Nn \c__letgutbanner_marginparwidth_dim
  { 3.74cm }
}
\dim_if_exist:NTF \c__letgut_banner_thickness_dim {
  \dim_const:NV \c__letgutbanner_banner_thickness_dim
  \c__letgut_banner_thickness_dim
}{
  \dim_const:Nn \c__letgutbanner_banner_thickness_dim
  { 4cm }
}
\dim_if_exist:NTF \c__letgut_banner_height_dim {
  \dim_const:NV \c__letgutbanner_banner_height_dim
    \c__letgut_banner_height_dim
}{
  \dim_const:Nn \c__letgutbanner_banner_height_dim  {
    \c__letgutbanner_textheight_dim
    +
    3cm
  }
}
\dim_const:Nn \c__letgutbanner_banner_padding_dim  { .25cm }
\dim_const:Nn \c__letgutbanner_banner_width_dim  {
  \c__letgutbanner_textwidth_dim
  +
  (
  \c__letgutbanner_banner_thickness_dim
  +
  \c__letgutbanner_lmargin_dim
  )/2
}
\dim_const:Nn
\c__letgutbanner_banner_vertical_contents_width_dim {
  \c__letgutbanner_banner_thickness_dim
  -
  2\c__letgutbanner_banner_padding_dim
}
\dim_const:Nn
\c__letgutbanner_banner_horizontal_contents_width_dim {
  \c__letgutbanner_textwidth_dim
  - (
  \c__letgutbanner_banner_thickness_dim
  -
  \c__letgutbanner_lmargin_dim
  )/2
  -
  \c__letgutbanner_banner_padding_dim
}
\box_new:N \g__letgutbanner_L_box
\box_new:N \g__letgutbanner_E_box
\box_new:N \g__letgutbanner_T_box
\box_new:N \g__letgutbanner_R_box
\box_new:N \g__letgutbanner_La_box
\box_new:N \g__letgutbanner_GUTenberg_box
\box_new:N \g__letgutbanner_largest_LETR_box
\box_new:N \g__letgutbanner_g_box
\fp_const:Nn \c__letgutbanner_leading_minimum_percent_fp { 0.15 }
\fp_const:Nn \c__letgutbanner_leading_La_factor_fp { 1.5 }
\geometry{
  asymmetric,
  textheight    = \c__letgutbanner_textheight_dim,
  textwidth     = \c__letgutbanner_textwidth_dim,
  lmargin       = \c__letgutbanner_lmargin_dim,
  tmargin       = \c__letgutbanner_tmargin_dim,
  head          = \c__letgutbanner_head_dim,
  headsep       = \c__letgutbanner_headsep_dim,
  marginparwidth= \c__letgutbanner_marginparwidth_dim,
  % showframe,
  % verbose,
}
\hbox_gset:Nn \g__letgutbanner_L_box { \textbf{L} }
\hbox_gset:Nn \g__letgutbanner_E_box { \textbf{E} }
\hbox_gset:Nn \g__letgutbanner_T_box { \textbf{T} }
\hbox_gset:Nn \g__letgutbanner_R_box { \textbf{R} }
\hbox_gset:Nn \g__letgutbanner_La_box { \textbf{\textit{La}} }
\hbox_gset:Nn \g__letgutbanner_GUTenberg_box {
  \textbf{\textit{GUTenberg}}
}
\hbox_gset:Nn \g__letgutbanner_g_box { \textbf{g} }
\dim_const:Nn \c__letgutbanner_L_width_dim {
  \box_wd:N \g__letgutbanner_L_box
}
\dim_const:Nn \c__letgutbanner_E_width_dim {
  \box_wd:N \g__letgutbanner_E_box
}
\dim_const:Nn \c__letgutbanner_T_width_dim {
  \box_wd:N \g__letgutbanner_T_box
}
\dim_const:Nn \c__letgutbanner_R_width_dim {
  \box_wd:N \g__letgutbanner_R_box
}
\dim_gset:Nn \g_tmpa_dim {
  \fp_eval:n {
    max (
    \c__letgutbanner_L_width_dim,
    \c__letgutbanner_E_width_dim,
    \c__letgutbanner_T_width_dim,
    \c__letgutbanner_R_width_dim,
    )
  }pt
}
\box_gset_eq:NN \g__letgutbanner_largest_LETR_box \dim_case:nnF
{ \g_tmpa_dim }
{
  { \c__letgutbanner_L_width_dim } { \g__letgutbanner_L_box }
  { \c__letgutbanner_E_width_dim } { \g__letgutbanner_E_box }
  { \c__letgutbanner_T_width_dim } { \g__letgutbanner_T_box }
  { \c__letgutbanner_R_width_dim } { \g__letgutbanner_R_box }
}
{ No~ idea! }
\box_gresize_to_wd:Nn \g__letgutbanner_GUTenberg_box {
  \c__letgutbanner_banner_horizontal_contents_width_dim
}
\dim_const:Nn \c__letgutbanner_GUTenberg_height_dim {
  \box_ht:N \g__letgutbanner_GUTenberg_box
}
\dim_const:Nn \c__letgutbanner_GUTenberg_depth_dim  {
  \box_dp:N \g__letgutbanner_GUTenberg_box
}
\dim_const:Nn \c__letgutbanner_GUTenberg_yoffset_dim {
  (
  \c__letgutbanner_banner_thickness_dim
  -
  \c__letgutbanner_GUTenberg_height_dim
  +
  \c__letgutbanner_GUTenberg_depth_dim
  )/2
}
\dim_gset:Nn
\g__letgutbanner_banner_vertical_contents_width_dim
\c__letgutbanner_banner_vertical_contents_width_dim
\dim_do_until:nNnn {
  \g__letgutbanner_between_letters_vertical_space_dim
}
>
{
  \fp_use:N\c__letgutbanner_leading_minimum_percent_fp
  \g__letgutbanner_largest_LETR_box_height_dim
}{
\box_gresize_to_wd:Nn \g__letgutbanner_largest_LETR_box {
  \g__letgutbanner_banner_vertical_contents_width_dim
}
\dim_gset:Nn \g__letgutbanner_largest_LETR_box_height_dim {
  \box_ht:N \g__letgutbanner_largest_LETR_box
}
\box_gresize_to_ht:Nn \g__letgutbanner_L_box {
  \g__letgutbanner_largest_LETR_box_height_dim
}
\box_gresize_to_ht:Nn \g__letgutbanner_E_box {
  \g__letgutbanner_largest_LETR_box_height_dim
}
\box_gresize_to_ht:Nn \g__letgutbanner_T_box {
  \g__letgutbanner_largest_LETR_box_height_dim
}
\box_gresize_to_ht:Nn \g__letgutbanner_R_box {
  \g__letgutbanner_largest_LETR_box_height_dim
}
\box_gresize_to_wd:Nn \g__letgutbanner_La_box {
  \g__letgutbanner_banner_vertical_contents_width_dim
}
\dim_gset:Nn \g__letgutbanner_La_height_dim {
  \box_ht:N \g__letgutbanner_La_box
}
\dim_gset:Nn \g__letgutbanner_La_depth_dim  {
  \box_dp:N \g__letgutbanner_La_box
}
\dim_gset:Nn \g__letgutbanner_La_yoffset_dim {
  \c__letgutbanner_banner_height_dim
  -
  \c__letgutbanner_GUTenberg_yoffset_dim
  -
  \g__letgutbanner_La_height_dim
  +
  \g__letgutbanner_La_depth_dim
}
\dim_gset:Nn \g__letgutbanner_area_height_dim {
  \g__letgutbanner_La_yoffset_dim
  -
  \g__letgutbanner_La_depth_dim
  -
  \c__letgutbanner_GUTenberg_yoffset_dim
}
\dim_set:Nn \l_tmpa_dim {
  (
  \g__letgutbanner_area_height_dim
  -
  6\g__letgutbanner_largest_LETR_box_height_dim
  )/13
}
\dim_gset:Nn \g__letgutbanner_between_letters_vertical_space_dim {
  2\l_tmpa_dim
}
\dim_gsub:Nn \g__letgutbanner_banner_vertical_contents_width_dim {
  1pt
  }
}
\dim_gset:Nn \g__letgutbanner_banner_padding_dim {
  (
  \c__letgutbanner_banner_thickness_dim
  -
  \g__letgutbanner_banner_vertical_contents_width_dim
  )/2
}
\dim_const:Nn \c__letgutbanner_first_letter_yoffset_dim {
  \g__letgutbanner_La_yoffset_dim
  -
  \g__letgutbanner_largest_LETR_box_height_dim
  -
  \fp_use:N \c__letgutbanner_leading_La_factor_fp
  \g__letgutbanner_between_letters_vertical_space_dim
}
\dim_gset:Nn \g__letgutbanner_between_letters_yoffset_dim {
  \g__letgutbanner_between_letters_vertical_space_dim
  +
  \g__letgutbanner_largest_LETR_box_height_dim
}
\box_gresize_to_wd:Nn \g__letgutbanner_g_box {
  \c__letgutbanner_textwidth_dim
}
\dim_gset:Nn \g__letgutbanner_first_page_shrink_dim {
  \c__letgutbanner_tmargin_dim
  +
  \c__letgutbanner_textheight_dim
  +
  \c__letgutbanner_banner_thickness_dim
  -
  .5\paperheight
  -
  .5\c__letgutbanner_banner_height_dim
  +
  .5\baselineskip
}
\AddToHookNext{shipout/background}{
\BeginAccSupp{ActualText={}}
\put(
.5\c__letgutbanner_lmargin_dim-.5\c__letgutbanner_banner_thickness_dim
,
-.5\paperheight-.5\c__letgutbanner_banner_height_dim
){
  \put(0,0){
    \rule{
      \c__letgutbanner_banner_width_dim
    }{
      \c__letgutbanner_banner_thickness_dim
    }
  }
  \put(0,0){
    \rule{
      \c__letgutbanner_banner_thickness_dim
    }{
      \c__letgutbanner_banner_height_dim
    }
  }
% \color_fill:nV {rgb}{ \g__letgutbanner_pagecolor_clist }
  \color[rgb]{ \g__letgutbanner_pagecolor_clist }
  \put(
  \g__letgutbanner_banner_padding_dim
  ,
  \g__letgutbanner_La_yoffset_dim
  ){
    \box_use:N \g__letgutbanner_La_box
  }
  \put(
  \g__letgutbanner_banner_padding_dim
  ,
  \c__letgutbanner_first_letter_yoffset_dim
  -0\g__letgutbanner_between_letters_yoffset_dim
  ){
    \box_use:N \g__letgutbanner_L_box
  }
  \put(
  \g__letgutbanner_banner_padding_dim
  ,
  \c__letgutbanner_first_letter_yoffset_dim
  -1\g__letgutbanner_between_letters_yoffset_dim
  ){
    \box_use:N \g__letgutbanner_E_box
  }
  \put(
  \g__letgutbanner_banner_padding_dim
  ,
  \c__letgutbanner_first_letter_yoffset_dim
  -2\g__letgutbanner_between_letters_yoffset_dim
  ){
    \box_use:N \g__letgutbanner_T_box
  }
  \put(
  \g__letgutbanner_banner_padding_dim
  ,
  \c__letgutbanner_first_letter_yoffset_dim
  -3\g__letgutbanner_between_letters_yoffset_dim
  ){
    \box_use:N \g__letgutbanner_T_box
  }
  \put(
  \g__letgutbanner_banner_padding_dim
  ,
  \c__letgutbanner_first_letter_yoffset_dim
  -4\g__letgutbanner_between_letters_yoffset_dim
  ){
    \box_use:N \g__letgutbanner_R_box
  }
  \put(
  \g__letgutbanner_banner_padding_dim
  ,
  \c__letgutbanner_first_letter_yoffset_dim
  -5\g__letgutbanner_between_letters_yoffset_dim
  ){
    \box_use:N \g__letgutbanner_E_box
  }
  \put(
  \c__letgutbanner_banner_thickness_dim
  ,
  \c__letgutbanner_GUTenberg_yoffset_dim
  ){
    \box_use:N \g__letgutbanner_GUTenberg_box
  }
  % \color_fill:n {black!10}
  \color{ black!10 }
  \put(
  .5\c__letgutbanner_lmargin_dim+.5\c__letgutbanner_banner_thickness_dim
  ,
  .5\paperheight
  +
  .5\c__letgutbanner_banner_height_dim
  -
  \c__letgutbanner_tmargin_dim
  ){
    \box_move_down:nn {.5\c__letgutbanner_textheight_dim}
    {\box_use:N \g__letgutbanner_g_box}
  }
}
\EndAccSupp{}
}
}
\@ifclassloaded{letgut}{
}{
  \AddToHook{begindocument/end}{%
    \enlargethispage{
      - \g__letgutbanner_first_page_shrink_dim
    }
    \thispagestyle{empty}
  }
}
