summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/pagecolor/pagecolor.sty
blob: e38807064ef104b9e0ca3fc98fbd794df7524192 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
%%
%% 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'.