%%
%% This is file `pagecolor.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% pagecolor.dtx  (with options: `package')
%% 
%% This is a generated file.
%% 
%% Project: pagecolor
%% Version: 2022-11-27 v1.2a
%% 
%% Copyright (C) 2011 - 2022 by
%%     H.-Martin Muench <Martin dot Muench at Uni-Bonn dot de>
%% 
%% 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. This version of this license is in
%%    https://www.latex-project.org/lppl/lppl-1-3c.txt
%% and the latest version of this license is in
%%    https://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.
%% 
%% This work has the LPPL maintenance status "maintained".
%% 
%% The Current Maintainer of this work is H.-Martin Muench.
%% 
%% This work consists of the main source file pagecolor.dtx,
%% the README, and the derived files
%%    pagecolor.sty, pagecolor.pdf,
%%    pagecolor.ins, pagecolor.drv,
%%    pagecolor-example.tex, pagecolor-example.pdf.
%% 
%% In memoriam
%%  Claudia Simone Barth + 1996-01-30
%%  Tommy Muench         + 2014-01-02
%%  Hans-Klaus Muench    + 2014-08-24
%% 
\NeedsTeXFormat{LaTeX2e}[2021-11-15]
\ProvidesPackage{pagecolor}[2022-11-27 1.2a
            Provides thepagecolor (HMM)]
%% Provides the \thepagecolor, \thepagecolornone, \newpagecolor{...},
%% \restorepagecolor, \backgroundpagecolor, \newbackgroundpagecolor{...},
%% and \restorebackgroundpagecolor commands and a replacement for the
%% \nopagecolor command, if this is not available.
\RequirePackage{hardwrap}[2011/02/12]% v0.2
\GenerateLogMacros{package}{pagecolor}

\RequirePackage{kvoptions}[2020-10-07]% v3.14
%% \RequirePackage{ either color or xcolor }:
\IfPackageLoadedTF{xcolor}{% xcolor loaded
   \RequirePackage{xcolor}[2021/10/31]% v2.13
 }{% xcolor not loaded
   \IfPackageLoadedTF{color}{%
      \RequirePackage{color}[2021/12/07]% v1.3c
    }{\pagecolor@warning@noline{%
        The pagecolor package must be loaded after either %
        package color or after package xcolor (at your %
        option). Neither package was loaded before package %
        pagecolor. Loading of package xcolor will now be %
        tried automatically. \\%
        When the pagecolor package is used with option %
        pagecolor using a color requiring e.g. x11names %
        option for xcolor package, this will not work!%
       }
     }
   \RequirePackage{xcolor}[2021/10/31]% v2.13
  }

\SetupKeyvalOptions{family=pagecolor,prefix=pagecolor@}
\DeclareStringOption[none]{pagecolor}%   \pagecolor@pagecolor
\DeclareStringOption[none]{nopagecolor}% \pagecolor@nopagecolor
\ProcessKeyvalOptions*

\ifdefined\nopagecolor\relax
\else
  \pagecolor@info@noline{\string\nopagecolor\ is undefined!}
  \def\pagecolortmpb{none}
  \edef\pagecolortmpa{\pagecolor@nopagecolor}
  \ifx\pagecolortmpa\pagecolortmpb
    \pagecolor@warning@noline{%
      Option nopagecolor=none requested but \string\nopagecolor\ %
      unknown: \\%
      By option nopagecolor the "color" to be used with %
      \string\nopagecolor\ %
      is set. The current value is "none" (maybe by default), %
      but command \string\nopagecolor\ is undefined. %
      Therefore the color cannot be "none". %
      Please change the option accordingly! - %
      As first aid nopagecolor is now set to white.%
     }
    \setkeys{pagecolor}{nopagecolor=white}
  \fi
  \edef\pagecolortmpa{\pagecolor@pagecolor}
  \ifx\pagecolortmpa\pagecolortmpb\relax
    \pagecolor@warning@noline{%
      Option pagecolor=none (maybe by default) used, %
      but \string\nopagecolor\ is unknown. %
      Please use another option value; %
      \pagecolor@nopagecolor\ will be used now.%
     }
    \setkeys{pagecolor}{pagecolor={\pagecolor@nopagecolor}}
  \fi
  \newcommand{\nopagecolor}{\pagecolor{\pagecolor@nopagecolor}}
\fi

\let\origpagecolor\pagecolor

\renewcommand{\pagecolor}[1]{\@bsphack%
  \edef\pagecolortmpa{#1}%
  \def\pagecolortmpb{none}%
  \ifx\pagecolortmpa\pagecolortmpb\relax%
    \ifdefined\nopagecolor\relax%
      \nopagecolor%
    \else%
      \pagecolor@warning{%
        pagecolor=none requested but \string\nopagecolor\ %
        unknown: \\%
        \string\pagecolor{none} was used, but the command %
        \string\nopagecolor\ is undefined. %
        Please use another color. \\%
        pagecolor=\pagecolor@nopagecolor\ \\%
        will be used now.%
       }%
      \xdef\thepagecolor{\pagecolor@nopagecolor}%
      \xdef\thepagecolornone{\pagecolor@nopagecolor}%
        % although it should be "none"
      \origpagecolor{\pagecolor@nopagecolor}%
    \fi%
  \else%
    \xdef\thepagecolor{#1}%
    \xdef\thepagecolornone{#1}%
    \origpagecolor{\thepagecolornone}%
  \fi%
  \@esphack%
}

\let\orignopagecolor\nopagecolor\relax

\gdef\pagecolor@cl{0}
\IfPackageLoadedTF{crop}{% crop loaded
  \gdef\pagecolor@cl{1}
  \pagecolor@info{\string\nopagecolor\space did not work with the crop package %
    2017/11/19 v1.10. Using \\%
    \pagecolor@nopagecolor\ \\%
    as nopagecolor now.%
    }
  \def\pagecolortmpb{none}
  \edef\pagecolortmpa{\pagecolor@nopagecolor}
  \ifx\pagecolortmpa\pagecolortmpb\relax
    \pagecolor@warning@noline{%
      Option nopagecolor=none requested but this does not work with the %
      crop package. By option nopagecolor the "color" to be used with %
      \string\nopagecolor\ is set. The current value is "none" (maybe by %
      default), but the crop package broke \string\nopagecolor . %
      Therefore the color cannot be "none". %
      Please change the option accordingly! %
      As first aid nopagecolor is now set to white.%
     }
    \setkeys{pagecolor}{nopagecolor=white}
  \fi
  \renewcommand{\nopagecolor}{\pagecolor{\pagecolor@nopagecolor}}
 }{% crop not loaded
   \ifdefined\nopagecolor\relax
     \gdef\pagecolortmpa{none}
   \else
     \gdef\pagecolortmpa{\pagecolor@nopagecolor}
   \fi
   \renewcommand{\nopagecolor}{%
     \xdef\thepagecolor{white}%
     \xdef\thepagecolornone{\pagecolortmpa}%
     \orignopagecolor%
     }
  }

\pagecolor{\pagecolor@pagecolor}

\newcommand{\newpagecolor}[1]{%
\xdef\pagecolortmpc{\thepagecolornone}%
\pagecolor{#1}%
}

\newcommand{\restorepagecolor}{\pagecolor{\pagecolortmpc}}

\gdef\pagecolortmpc{\thepagecolor}

\newcommand{\backgroundpagecolor}[1]{%
  \IfPackageLoadedTF{crop}{%
    \xdef\pagecolortmpd{\thepagecolor}%
    \pagecolor{#1}%
    \xdef\pagecolortmpe{\CROP@pagecolor}%
    \pagecolor{\pagecolortmpd}%
    \xdef\CROP@stockcolor{\pagecolortmpe}%
    }{\pagecolor@info{\string\backgroundpagecolor\ does not do %
           anything when the crop package has not been loaded.}%
    }%
  }

\newcommand{\newbackgroundpagecolor}[1]{%
  \IfPackageLoadedTF{crop}{%
    \xdef\pagecolortmpf{\CROP@stockcolor}%
    \backgroundpagecolor{#1}%
    }{\pagecolor@info{\string\newbackgroundpagecolor\ does not do %
              anything when the crop package has not been loaded.}%
     }%
  }

\newcommand{\restorebackgroundpagecolor}{%
  \IfPackageLoadedTF{crop}{\xdef\CROP@stockcolor{\pagecolortmpf}}{%
    \pagecolor@info{\string\newbackgroundpagecolor\ does not do %
             anything when the crop package has not been loaded.}}%
  }

\AddToHook{begindocument/end}{%
  \def\pagecolortmpb{0}%
  \ifx\pagecolor@cl\pagecolortmpb\relax%
    % crop not loaded before pagecolor, but maybe afterwards:
    \IfPackageLoadedTF{crop}{% crop indeed loaded afterwards.
      \gdef\pagecolor@cl{1}%
      \pagecolor@info{\string\nopagecolor\space did not work with the crop package %
        2017/11/19 v1.10. Using \\%
        \pagecolor@nopagecolor\ \\%
        as nopagecolor now.%
        }%
      \def\pagecolortmpb{none}%
      \edef\pagecolortmpa{\pagecolor@nopagecolor}%
      \ifx\pagecolortmpa\pagecolortmpb\relax%
        \pagecolor@warning@noline{%
          Option nopagecolor=none requested but this does not work with %
          the crop package. By option nopagecolor the "color" to be used %
          with \string\nopagecolor\ is set. The current value is "none" %
          (maybe by default), but the crop package broke %
          \string\nopagecolor . Therefore the color cannot be "none". %
          Please change the option accordingly! %
          As first aid nopagecolor is now set to white.%
         }%
        \setkeys{pagecolor}{nopagecolor=white}%
      \fi%
      \renewcommand{\nopagecolor}{\pagecolor{\pagecolor@nopagecolor}}%
     }{% crop neither loaded afterwards.
      }%
  \fi%
  }

\endinput
%%
%% End of file `pagecolor.sty'.
