%%
%% This is file `projlib-paper.sty',
%% generated with the docstrip utility.
%%
%% Copyright (C) 2021-2023 by Jinwen XU
%% 
%% This is part of the ProjLib Toolkit.
%% 
%% 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
%% 2005/12/01 or later.
%% 
\NeedsTeXFormat{LaTeX2e}[2022-06-01]
\ProvidesExplPackage
  {projlib-paper}
  {2023/07/14} {}
  {Configuration of the paper style}

\keys_define:nn { projlib-paper }
  {
    , preview-mode       .bool_set:N         = \l__projlib_paper_preview_bool
    , preview-mode       .initial:n          = { false }
    , paper-style        .tl_set:N           = \l__projlib_paper_paperstyle_tl
    , paper-style        .initial:n          = { normal }
    , paper-style        .value_required:n   = true
    , paper~style        .tl_set:N           = \l__projlib_paper_paperstyle_tl
    , paper style        .tl_set:N           = \l__projlib_paper_paperstyle_tl
    , light-yellow-paper .meta:n             = { paperstyle = lightyellow }
    , light~yellow~paper .meta:n             = { paperstyle = lightyellow }
    , light yellow-paper .meta:n             = { paperstyle = lightyellow }
    , light yellow~paper .meta:n             = { paperstyle = lightyellow }
    , light yellow paper .meta:n             = { paperstyle = lightyellow }
    , yellow-paper       .meta:n             = { paperstyle = yellow      }
    , yellow~paper       .meta:n             = { paperstyle = yellow      }
    , yellow paper       .meta:n             = { paperstyle = yellow      }
    , parchment-paper    .meta:n             = { paperstyle = parchment   }
    , parchment~paper    .meta:n             = { paperstyle = parchment   }
    , parchment paper    .meta:n             = { paperstyle = parchment   }
    , green-paper        .meta:n             = { paperstyle = green       }
    , green~paper        .meta:n             = { paperstyle = green       }
    , green paper        .meta:n             = { paperstyle = green       }
    , light-gray-paper   .meta:n             = { paperstyle = lightgray   }
    , light~gray~paper   .meta:n             = { paperstyle = lightgray   }
    , light gray-paper   .meta:n             = { paperstyle = lightgray   }
    , light gray~paper   .meta:n             = { paperstyle = lightgray   }
    , light gray paper   .meta:n             = { paperstyle = lightgray   }
    , gray-paper         .meta:n             = { paperstyle = gray        }
    , gray~paper         .meta:n             = { paperstyle = gray        }
    , gray paper         .meta:n             = { paperstyle = gray        }
    , nord-paper         .meta:n             = { paperstyle = nord        }
    , nord~paper         .meta:n             = { paperstyle = nord        }
    , nord paper         .meta:n             = { paperstyle = nord        }
    , dark-paper         .meta:n             = { paperstyle = dark        }
    , dark~paper         .meta:n             = { paperstyle = dark        }
    , dark paper         .meta:n             = { paperstyle = dark        }
    , unknown            .code:n             = {}
  }
\ProcessKeyOptions [ projlib-paper ]

\cs_new:Nn \projlib_paper_preview_disable:
  {
    \bool_set_false:c { l__projlib_paper_preview_bool }
  }

\hook_gput_code:nnn { begindocument/before } { projlib-paper }
  {
    \bool_if:NT \l__projlib_paper_preview_bool
      {
        \dim_set:Nn \paperwidth
          {
            \dim_eval:n { \textwidth * 21 / 20 }
          }
        \dim_set:Nn \paperheight
          {
            \dim_eval:n { ( \textheight + \headheight + \headsep + \footskip ) * 21 / 20 }
          }
        \dim_set:Nn \oddsidemargin
          {
            \dim_eval:n { ( \paperwidth - \textwidth ) / 2 - 1in }
          }
        \dim_set:Nn \evensidemargin
          {
            \dim_eval:n { ( \paperwidth - \textwidth ) / 2 - 1in }
          }
        \dim_set:Nn \topmargin
          {
            \dim_eval:n { ( \paperheight - \textheight - \headheight - \headsep - \footskip ) / 2 - 1in }
          }
      }
  }

\RequirePackage { xcolor }

\definecolor { paper }     { RGB } { 255, 255, 255 }
\definecolor { main-text } { RGB } {   0,   0,   0 }

\str_case_e:nn { \l__projlib_paper_paperstyle_tl }
  {
    { light yellow } { \definecolor { paper }     { RGB } { 255, 254, 245 }
                       \definecolor { main-text } { RGB } {  37,  41,  46 } }
    { light-yellow } { \definecolor { paper }     { RGB } { 255, 254, 245 }
                       \definecolor { main-text } { RGB } {  37,  41,  46 } }
    { light~yellow } { \definecolor { paper }     { RGB } { 255, 254, 245 }
                       \definecolor { main-text } { RGB } {  37,  41,  46 } }
    { yellow       } { \definecolor { paper }     { RGB } { 247, 246, 233 } }
    { parchment    } { \definecolor { paper }     { RGB } { 232, 225, 204 }
                       \definecolor { main-text } { RGB } {  94,  78,  62 } }
    { green        } { \definecolor { paper }     { RGB } { 207, 231, 207 } }
    { light gray   } { \definecolor { paper }     { RGB } { 236, 239, 244 }
                       \definecolor { main-text } { RGB } {  37,  41,  46 } }
    { light-gray   } { \definecolor { paper }     { RGB } { 236, 239, 244 }
                       \definecolor { main-text } { RGB } {  37,  41,  46 } }
    { light~gray   } { \definecolor { paper }     { RGB } { 236, 239, 244 }
                       \definecolor { main-text } { RGB } {  37,  41,  46 } }
    { gray         } { \definecolor { paper }     { RGB } { 127, 130, 136 }
                       \definecolor { main-text } { RGB } { 236, 239, 244 } }
    { nord         } { \definecolor { paper }     { RGB } {  46,  52,  64 }
                       \definecolor { main-text } { RGB } { 214, 220, 230 } }
    { dark         } { \definecolor { paper }     { RGB } {  28,  29,  33 }
                       \definecolor { main-text } { RGB } { 210, 213, 217 } }
  }

\cs_new:Nn \projlib_paper_set_page_color:n
  {
    \pagecolor { #1 }
  }
\cs_new:Nn \projlib_paper_set_text_color:n
  {
    \color { #1 }
    \cs_gset_eq:cc { default@color } { current@color }
  }

\projlib_paper_set_page_color:n { paper }
\projlib_paper_set_text_color:n { main-text }

\hook_gput_code:nnn { package/tcolorbox/after } { projlib-paper }
  {
    \tcbset { colupper = main-text, collower = main-text }
  }
\hook_gput_code:nnn { package/tikz-cd/after } { projlib-paper }
  {
    \tikzset { /tikz/commutative~diagrams/background~color = paper }
  }

\endinput
%%
%% End of file `projlib-paper.sty'.
