Debian Codegraph @

texmf-dist/source/latex/graphics/color.dtx

raw
1 %
2 % \iffalse
3 %
4 %% color.dtx Copyright (C) 1994--1999 David Carlisle
5 %% Copyright (C) 2005-2025 LaTeX Project
6 %% The LaTeX Project and any individual authors listed elsewhere
7 %% in this file.
8 %%
9 %% This file is part of the Standard LaTeX `Graphics Bundle'.
10 %% It may be distributed under the terms of the LaTeX Project Public
11 %% License, as described in lppl.txt in the base LaTeX distribution.
12 %% Either version 1.3c or, at your option, any later version.
13 %%
14 %% This file has the LPPL maintenance status "maintained".
15 %%
16 %<*dtx>
17 \ProvidesFile{color.dtx}
18 %</dtx>
19 %<package>\NeedsTeXFormat{LaTeX2e}[1995/12/01]
20 %<package>\ProvidesPackage{color}
21 %<driver> \ProvidesFile{color.drv}
22 % \fi
23 % \ProvidesFile{color.dtx}
24 [2025/01/14 v1.3e Standard LaTeX Color (DPC)]
25 %
26 % \iffalse
27 %<*driver>
28 \documentclass{ltxdoc}
29 \newenvironment{option}[1]{\expandafter\macro\expandafter{%
30 \csname ds@#1\endcsname}}{\endmacro}
31 \begin{document}
32 \DocInput{color.dtx}
33 \end{document}
34 %</driver>
35 % \fi
36 %
37 % \GetFileInfo{color.dtx}
38 %
39 % \title{The \textsf{color} package\thanks{This file
40 % has version number \fileversion, last
41 % revised \filedate.}}
42 % \author{D. P. Carlisle}
43 % \date{\filedate}
44 % \MaintainedByLaTeXTeam{graphics}
45 % \maketitle
46 %
47 %
48 %
49 % \title{The implementation of the \LaTeX\ Colour interface.}
50 %
51 % \section{Introduction}
52 % This package implements \LaTeX\ support for colour, for those
53 % \texttt{dvi} drivers that can produce coloured text.
54 %
55 % The user level documentation of this package is contained in the
56 % document \emph{Packages in the `graphics' bundle} in the file
57 % \texttt{grfguide.tex}.
58 %
59 % \MaybeStop{}
60 %
61 %
62 % \section{Options}
63 %
64 % \changes{v0.2a}{1994/04/13}
65 % {TEMP KLUDGE for Feb 94 release of 2e:
66 % Add extra groups}
67 % \changes{v0.2d}{1994/05/13}
68 % {All support for Feb 1994 release removed (so used optional arg
69 % of \cs{NeedsTeXFormat}).}
70 % \changes{v1.0}{1996/05/29}
71 % {Version 1 at last}
72 %
73 % \begin{macrocode}
74 %<*package>
75 % \end{macrocode}
76 %
77 % First we save the catcodes of some characters, and set them to
78 % fixed values whilst this file is being read.
79 % \changes{v0.3b}{1994/09/14}
80 % {Save and restore catcodes}
81 % \changes{v1.3a}{2021/09/27}
82 % {Use \cs{@backslashchar} in preference to \cs{string} gh/659}
83 % \changes{v1.3c}{2021/12/07}
84 % {Remove stray spaces after change to \cs{@backslashchar} xcolor/gh/10}
85 %
86 % \begin{macrocode}
87 \edef\Gin@codes{%
88 \catcode`\noexpand\^^A\the\catcode`\^^A\relax
89 \catcode`\noexpand\"\the\catcode`\"\relax
90 \catcode`\noexpand\*\the\catcode`\*\relax
91 \catcode`\noexpand\!\the\catcode`\!\relax
92 \catcode`\noexpand\:\the\catcode`\:\relax}
93 \catcode`\^^A=\catcode`\%
94 \catcode`\"=12
95 \catcode`\*=11
96 \catcode`\!=12
97 \catcode`\:=12
98 % \end{macrocode}
99 %
100 % \begin{macro}{\Gin@driver}
101 % Initialize the macro to hold the driver file name.
102 % \begin{macrocode}
103 \providecommand\Gin@driver{}
104 % \end{macrocode}
105 % \end{macro}
106 %
107 % \begin{macro}{\c@lor@error}
108 % \changes{v1.0d}{1997/01/07}
109 % {Macro added for graphics/2350}
110 % Helper macro for error handling (redefined by the monochrome option
111 % to make errors warnings).
112 % \begin{macrocode}
113 \def\c@lor@error#1{%
114 \@latex@error{Undefined color #1}\@ehd}
115 % \end{macrocode}
116 % \end{macro}
117 %
118 % \begin{option}{monochrome}
119 % The |monochrome| option should be used \emph{in addition}
120 % to one of the standard driver options.
121 % \changes{v0.3j}{1995/06/16}
122 % {Use single hash for latex/1557}
123 % \changes{v1.0b}{1996/10/29}
124 % {Add \cs{colors@false}}
125 % \changes{v1.0d}{1997/01/07}
126 % {Add \cs{c@lor@error} for graphics/2350}
127 % \begin{macrocode}
128 \DeclareOption{monochrome}{%
129 \def\c@lor@error#1{\PackageInfo{color}{Undefined color #1}}%
130 \AtEndOfPackage{%
131 \colors@false
132 \def\set@color{%
133 \c@lor@special\m@ne
134 {color push \current@color}\aftergroup\reset@color}%
135 \def\reset@color{\c@lor@special\m@ne{color pop}}%
136 \def\set@page@color{%
137 \c@lor@special\m@ne{background \current@color}}%
138 \def\define@color#1#2{%
139 \c@lor@special\m@ne{define #1 #2}}}}
140 % \end{macrocode}
141 % \end{option}
142 %
143 % \begin{option}{debugshow}
144 % The |debugshow| option turns on debugging info (perhaps).
145 % \changes{v1.0a}{1996/09/16}
146 % {debugshow option added}
147 % \begin{macrocode}
148 \DeclareOption{debugshow}{\catcode`\^^A=9 \let\GDebug\typeout}
149 % \end{macrocode}
150 % \end{option}
151 %
152 % \begin{option}{setpagesize}
153 % \begin{option}{nosetpagesize}
154 % The |setpagesize| option requests that the driver option sets the page size.
155 % \changes{v1.1d}{2016/06/02}
156 % {(no)setpagesize options added}
157 % (Whichever option is used, the page size is not set by this package if |\mag|
158 % has been changed from its default value.)
159 % \begin{macrocode}
160 \newif\ifGin@setpagesize\Gin@setpagesizetrue
161 \DeclareOption{setpagesize}{\Gin@setpagesizetrue}
162 \DeclareOption{nosetpagesize}{\Gin@setpagesizefalse}
163 % \end{macrocode}
164 % \end{option}
165 % \end{option}
166 %
167 % Now the options for supported drivers.
168 %
169 % \begin{option}{dvips}
170 % \begin{option}{xdvi}
171 % Tom Rokicki's dvips driver, and the X Windows previewer, xdvi, which uses
172 % (a subset of) the same |\specials|.
173 % \begin{macrocode}
174 \DeclareOption{dvips}{\def\Gin@driver{dvips.def}%
175 \def\c@lor@namefile{dvipsnam.def}}
176 \DeclareOption{xdvi}{\ExecuteOptions{dvips,monochrome}}
177 % \end{macrocode}
178 % \end{option}
179 % \end{option}
180 %
181 % \begin{option}{dvipdf}
182 % \changes{v1.0c}{1996/10/31}
183 % {dvipdf added}
184 % Sergey Lesenko's dvipdf driver.
185 % \begin{macrocode}
186 \DeclareOption{dvipdf}{\def\Gin@driver{dvipdf.def}}
187 % \end{macrocode}
188 % \end{option}
189 %
190 % \begin{option}{dvipdfm}
191 % \changes{v1.0h}{1999/01/13}
192 % {dvipdfm added}
193 % \changes{v1.3b}{2021/10/11}
194 % {make dvipdfm an alias for dvipdfmx}
195 % Mark Wick's dvipdfm driver (now merged with xdvipdfmx).
196 % \begin{macrocode}
197 \DeclareOption{dvipdfm}{\def\Gin@driver{dvipdfmx.def}}
198 % \end{macrocode}
199 % \end{option}
200 %
201 % \begin{option}{dvipdfmx}
202 % \changes{v1.0j}{2005/11/14}
203 % {dvipdfmx added}
204 % The driver for the dvipdfmx project.
205 % \begin{macrocode}
206 \DeclareOption{dvipdfmx}{\def\Gin@driver{dvipdfmx.def}}
207 % \end{macrocode}
208 % \end{option}
209 %
210 % \begin{option}{pdftex}
211 % \changes{v1.0e}{1997/06/07}
212 % {pdftex added}
213 % Han The Thanh's \TeX\ variant.
214 % \begin{macrocode}
215 \DeclareOption{pdftex}{\def\Gin@driver{pdftex.def}}
216 % \end{macrocode}
217 % \end{option}
218 %
219 % \begin{option}{luatex}
220 % \changes{v1.1b}{2016/01/03}
221 % {luatex added}
222 % Lua\TeX\ \TeX\ variant.
223 % \begin{macrocode}
224 \DeclareOption{luatex}{\def\Gin@driver{luatex.def}}
225 % \end{macrocode}
226 % \end{option}
227 %
228 % \begin{option}{luatex}
229 % \changes{v1.1c}{2016/05/09}
230 % {dvisvgm added}
231 % dvisvgm driver.
232 % \begin{macrocode}
233 \DeclareOption{dvisvgm}{\def\Gin@driver{dvisvgm.def}}
234 % \end{macrocode}
235 % \end{option}
236 %
237 % \begin{option}{xetex}
238 % \changes{v1.0j}{2005/11/14}
239 % {xetex added}
240 % Jonathan Kew's \TeX\ variant.
241 % \begin{macrocode}
242 \DeclareOption{xetex}{\def\Gin@driver{xetex.def}}
243 % \end{macrocode}
244 % \end{option}
245 %
246 % \begin{option}{dvipsone}
247 % \begin{option}{dviwindo}
248 % \changes{v0.3k}{1995/09/07}
249 % {Merge dviwindo and dvipsone options}
250 % The drivers of the Y\&Y \TeX\ system.
251 % (Which use the same |\specials|.)
252 % \begin{macrocode}
253 \DeclareOption{dvipsone}{\def\Gin@driver{dvipsone.def}}
254 \DeclareOption{dviwindo}{\ExecuteOptions{dvipsone}}
255 % \end{macrocode}
256 % \end{option}
257 % \end{option}
258 %
259 % \begin{option}{emtex}
260 % \begin{option}{dviwin}
261 % Freely available drivers for PCs.
262 % \begin{macrocode}
263 \DeclareOption{emtex}{\def\Gin@driver{emtex.def}}
264 \DeclareOption{dviwin}{\def\Gin@driver{dviwin.def}}
265 % \end{macrocode}
266 % \end{option}
267 % \end{option}
268 %
269 % \begin{option}{oztex}
270 % \changes{v1.0f}{1997/09/09}
271 % {Merge dvips and oztex options}
272 % The Oz\TeX\ system for a Macintosh.
273 % Since release 3 of Oz\TeX, merge with dvips back end.
274 % \begin{macrocode}
275 \DeclareOption{oztex}{\ExecuteOptions{dvips}}
276 % \end{macrocode}
277 % \end{option}
278 %
279 % \begin{option}{textures}
280 % Blue sky's Textures system on a Macintosh.
281 % \begin{macrocode}
282 \DeclareOption{textures}{\def\Gin@driver{textures.def}}
283 % \end{macrocode}
284 % \end{option}
285 %
286 % \begin{option}{pctexps}
287 % \begin{option}{pctexwin}
288 % \begin{option}{pctexhp}
289 % \begin{option}{pctex32}
290 % \changes{v1.0b}{1996/10/29}
291 % {pctex32 option added}
292 % The drivers for PTI's \TeX\ system on PCs.
293 % \begin{macrocode}
294 \DeclareOption{pctexps}{\def\Gin@driver{pctexps.def}}
295 \DeclareOption{pctexwin}{\def\Gin@driver{pctexwin.def}}
296 \DeclareOption{pctexhp}{\def\Gin@driver{pctexhp.def}}
297 \DeclareOption{pctex32}{\def\Gin@driver{pctex32.def}}
298 % \end{macrocode}
299 % \end{option}
300 % \end{option}
301 % \end{option}
302 % \end{option}
303 %
304 % \begin{option}{truetex}
305 % \begin{option}{tcidvi}
306 % \changes{v1.0b}{1996/10/29}
307 % {truetex and tcidvi options added}
308 % The drivers of the Kinch \TeX\ system on PCs, and its
309 % version with extra |\special| handling dll's as shipped with
310 % TCI's Scientific Word.
311 % \begin{macrocode}
312 \DeclareOption{truetex}{\def\Gin@driver{truetex.def}}
313 \DeclareOption{tcidvi}{\def\Gin@driver{tcidvi.def}}
314 % \end{macrocode}
315 % \end{option}
316 % \end{option}
317 %
318 % \begin{option}{vtex}
319 % \changes{v1.0g}{1998/05/27}
320 % {vtex option added}
321 % V\TeX\ driver.
322 % \begin{macrocode}
323 \DeclareOption{vtex}{\def\Gin@driver{vtex.def}}
324 % \end{macrocode}
325 % \end{option}
326 %
327 % \begin{option}{dvi2ps}
328 % \begin{option}{dvialw}
329 % \begin{option}{dvilaser}
330 % \begin{option}{dvitops}
331 % \begin{option}{psprint}
332 % \begin{option}{pubps}
333 % \begin{option}{ln}
334 % \changes{v1.0b}{1996/10/29}
335 % {old driver options depreciated}
336 % Old, probably obsolete, drivers commented out. See the section
337 % on `Driver support' in grfguide to see how to re-enable these
338 % options in |color.cfg| if you need them.
339 % \begin{macrocode}
340 %\DeclareOption{dvi2ps}{\def\Gin@driver{dvi2ps.def}}
341 %\DeclareOption{dvialw}{\def\Gin@driver{dvialw.def}}
342 %\DeclareOption{dvilaser}{\def\Gin@driver{dvilaser.def}}
343 %\DeclareOption{dvitops}{\def\Gin@driver{dvitops.def}}
344 %\DeclareOption{psprint}{\def\Gin@driver{psprint.def}}
345 %\DeclareOption{pubps}{\def\Gin@driver{pubps.def}}
346 %\DeclareOption{ln}{\def\Gin@driver{ln.def}}
347 % \end{macrocode}
348 % \end{option}
349 % \end{option}
350 % \end{option}
351 % \end{option}
352 % \end{option}
353 % \end{option}
354 % \end{option}
355 %
356 %
357 % \begin{option}{dvipsnames}
358 % \begin{option}{nodvipsnames}
359 % By default the named colour model has no pre-declared names.
360 % The |dvipsnames| option predeclares all the names in the colour
361 % prologue of dvips. The |dvips| option automatically implies
362 % |dvipsnames| unless this choice is overruled with the |nodvipsnames|
363 % option. For other drivers, eg |textures|, you may use this option to
364 % explicitly request that these names be declared.
365 % \begin{macrocode}
366 \DeclareOption{dvipsnames}{\def\c@lor@namefile{dvipsnam.def}}
367 \DeclareOption{nodvipsnames}{\let\c@lor@namefile\relax}
368 % \end{macrocode}
369 % \end{option}
370 % \end{option}
371 %
372 % \begin{option}{usenames}
373 % The |usenames| option modifies the behaviour of |\DefineNamedColor|
374 % so that it declares the same name as a ``user's colour'' for use in
375 % a |\color| command, as well as a name in the |named| colour model.
376 % The normal behaviour is just to declare the name in the named colour
377 % model.
378 % \begin{macrocode}
379 \let\c@lor@usename\@gobble
380 % \end{macrocode}
381 %
382 % \begin{macrocode}
383 \DeclareOption{usenames}{%
384 \def\c@lor@usename#1{%
385 \expandafter\color@named\csname\@backslashchar color@#1\endcsname{#1}}}
386 % \end{macrocode}
387 % \end{option}
388 %
389 % \section{Using Colours}
390 %
391 % \subsection{Declarative form}
392 %
393 % \begin{macro}{\color}
394 % |\color{|\emph{declared-colour}|}| switches to the colour
395 % \emph{declared-colour}, which must previously have been defined
396 % using |\definecolor|. This colour will stay in effect until the end of
397 % the current \TeX\ group.
398 %
399 % |\color[|\emph{model}|]{|\emph{colour-specification}|}| is similar
400 % to the above, but uses a colour not declared by |\definecolor|. The
401 % allowed \emph{model}'s vary depending on the driver. The syntax of
402 % the \emph{colour-specification} argument depends on the model.
403 %
404 % \changes{v0.3a}{1994/07/20}
405 % {Make \cs{color} robust}
406 % \begin{macrocode}
407 \DeclareRobustCommand\color{%
408 \@ifnextchar[\@undeclaredcolor\@declaredcolor}
409 % \end{macrocode}
410 % \end{macro}
411 %
412 % \begin{macro}{\@undeclaredcolor}
413 % \changes{v0.2c}{1994/05/09}
414 % {Improve error messages}
415 % \changes{v0.3a}{1994/07/20}
416 % {New internal implementation of colour commands}
417 % Call the driver-dependent command |\color@|\meta{model} to define
418 % |\current@color|, then call |\set@color| to change the current colour
419 % accordingly.
420 % \begin{macrocode}
421 \def\@undeclaredcolor[#1]#2{%
422 \@ifundefined{color@#1}%
423 {\c@lor@error{model `#1'}}%
424 {\csname color@#1\endcsname\current@color{#2}%
425 \set@color}%
426 \ignorespaces}
427 % \end{macrocode}
428 % \end{macro}
429 %
430 % \begin{macro}{\@declaredcolor}%
431 % \changes{v0.1c}{1994/04/01}
432 % {Add \cs{ignorespaces}}
433 % \changes{v0.1e}{1994/05/14}
434 % {Minor change to error message}
435 % \changes{v0.3a}{1994/07/20}
436 % {New internal implementation of colour commands}
437 % |\let| |\current@color| to the internal representation of the colour
438 % if the colour has been declared, otherwise generate an error.
439 % Finally call |\set@color| to effect the colour change.
440 % \begin{macrocode}
441 \def\@declaredcolor#1{%
442 \@ifundefined{\@backslashchar color@#1}%
443 {\c@lor@error{`#1'}}%
444 {\expandafter\let\expandafter\current@color
445 \csname\@backslashchar color@#1\endcsname
446 \set@color}%
447 \ignorespaces}
448 % \end{macrocode}
449 % \end{macro}
450 %
451 % \subsection{Command (Argument) Form}
452 %
453 % \begin{macro}{\textcolor}
454 % |\textcolor{|\emph{declared-colour}|}{|\emph{text}|}| and
455 % |\textcolor[|\emph{model}|]{|\emph{colour-spec}|}{|\emph{text}|}|
456 % are just alternative syntax for |\color|, in
457 % which the groups are added implicitly. Thus \emph{text} appears in the
458 % specified colour, but then the colour reverts to its previous value.
459 % The naming is by analogy with |\textrm| (as opposed to |\rm| and
460 % |\rmfamily|) although it is slightly a misnomer as the command also
461 % works in math-mode. In contrast to |\textrm|, the command gobbles spaces
462 % at the begin of its argument, so |Hello\textcolor{red}{ World}| will
463 % output Hello\textcolor{red}{ World}.
464 %
465 % Since December 95, in fact this command has one other difference
466 % from |\color|. It calls |\leavevmode| to ensure the start of
467 % horizontal mode. Specifically this means that a construction
468 % such as
469 %\begin{verbatim}
470 % xxx\parbox[t]{1cm}{\textcolor{red}{a}.....
471 %\end{verbatim}
472 % now works as expected, with the |xxx| and the red |a| lining up
473 % correctly.
474 % \changes{v0.3a}{1994/07/20}
475 % {Stop command being \cs{long}, and make robust.}
476 % \changes{v1.2a}{2019/11/23}
477 % {Add \cs{protected} gh/208}
478 % \begin{macrocode}
479 \protected\def\textcolor#1#{\@textcolor{#1}}
480 \def\@textcolor#1#2#3{\protect\leavevmode{\color#1{#2}#3}}
481 % \end{macrocode}
482 % \end{macro}
483 %
484 % \subsection{Background (Page) Colour}
485 %
486 % \begin{macro}{\pagecolor}
487 % |\pagecolor|, which has the same argument forms as |\color|, specifies
488 % the background colour for the current, and all following, pages. It is
489 % a global declaration which does not respect \TeX\ groups.
490 %
491 % \changes{v0.1c}{1994/04/01}
492 % {end the group even if the colour command generates an error}
493 % \changes{v0.3c}{1994/09/19}
494 % {Use \cs{color} to parse arguments}
495 % \changes{v1.2a}{2019/11/23}
496 % {Add \cs{protected} gh/208}
497 % \begin{macrocode}
498 \protected\def\pagecolor{%
499 \begingroup
500 \let\ignorespaces\endgroup
501 \let\set@color\set@page@color
502 \color}
503 % \end{macrocode}
504 % \end{macro}
505 %
506 % \begin{macro}{\nopagecolor}
507 % |\nopagecolor| (suggested by Heiko Oberdiek) removes any currently specified page colour
508 % returning to the default transparent background. It is not yet supported by all driver options
509 % and so generates a warning if there is no definition in the driver file.
510 %
511 % \changes{v1.1a}{2014/04/23}
512 % {add \cs{nopagecolor} graphics/3873}
513 % \changes{v1.2a}{2019/11/23}
514 % {Add \cs{protected} gh/208}
515 % \begin{macrocode}
516 \protected\def\nopagecolor{%
517 \@ifundefined{no@page@color}{%
518 \PackageInfo{color}{\@backslashchar nopagecolor\space is not supported}%
519 }{%
520 \no@page@color
521 }%
522 }
523 % \end{macrocode}
524 % \end{macro}
525 %
526 %
527 % \section{Defining Colours}
528 %
529 % \begin{macro}{\definecolor}
530 % |\definecolor{|\emph{name}|}{|\emph{model}|}{|\emph{colour-spec}|}|
531 % defines the color \emph{name}, which may then be used in subsequent
532 % |\color| or |\textcolor| commands to refer to a colour specified by
533 % \emph{colour-spec} in the colour model \emph{model}.
534 %
535 % |\definecolor| associates the \emph{name} to a colour in
536 % \emph{model}. So |\color{|\emph{name}|}| would check \emph{name}
537 % then issue a |\special| for the colour model \emph{model}.
538 %
539 % |\definecolor| just calls an internal macro that defines the colour
540 % for a particular model. This macro must have been defined by the
541 % driver file that supports the requested \emph{model}.
542 %
543 % \changes{v0.1b}{1994/03/15}
544 % {change name from \cs{newcolor} to \cs{definecolor}}
545 % \changes{v0.1e}{1994/05/14}
546 % {Minor change to error message}
547 % \changes{v0.3a}{1994/07/20}
548 % {New internal implementation of colour commands}
549 % \changes{v0.3f}{1994/10/04}
550 % {Give info about redefinitions}
551 % \changes{v1.2a}{2019/11/23}
552 % {Add \cs{protected} gh/208}
553 % \begin{macrocode}
554 \protected\def\definecolor#1#2#3{%
555 \@ifundefined{color@#2}%
556 {\c@lor@error{model `#2'}}%
557 {\@ifundefined{\@backslashchar color@#1}{}%
558 {\PackageInfo{color}{Redefining color #1}}%
559 \csname color@#2\expandafter\endcsname
560 \csname\@backslashchar color@#1\endcsname{#3}}}
561 % \end{macrocode}
562 % \end{macro}
563 %
564 %
565 % \begin{macro}{\DefineNamedColor}
566 % \changes{v0.3d}{1994/09/29}
567 % {Macro added}
568 % \changes{v0.3e}{1994/10/03}
569 % {usenames option added}
570 % \changes{v0.3f}{1994/10/04}
571 % {Give info about redefinitions}
572 % \changes{v1.2b}{2020/02/24}
573 % {corrected test, see https://www.latex-project.org/cgi-bin/ltxbugs2html?pr=graphics/3635}
574 %
575 % Driver files may opt to define a `named' colour model.
576 % Placing colour names rather than numeric specifications into the dvi
577 % file has certain advantages, in that post processing software can
578 % tune the colour specifications to the particular technology being
579 % used, and more easily make colour separations for that colour.
580 % The disadvantage is that the driver must `know' the colour
581 % names.
582 %
583 % The `color1' drivers (dvips) currently ignore the specification of
584 % the colour and, once a name is defined, just put the colour name in
585 % the dvi file. For dvips, the header file \texttt{color.pro} is used to
586 % give the cmyk equivalents of the names.
587 %
588 % The `color2' drivers (textures) use a special postscript operator
589 % that takes both the name and the cmyk equivalent, so if the names are
590 % not being used, `fall back' definitions in the cmyk model are available.
591 % These drivers also allow a numeric value to affect the `density'
592 % of the colour to use.
593 %
594 % Drivers based on `color3' do not support named colours at the dvi
595 % level, but to ease document portability, the named model is still
596 % defined, but the |\special|'s just put the colour specifications, not
597 % the names, into the dvi file.
598 %
599 % Normally after a colour, say |JungleGreen|, has been declared with:\\
600 % |\DefineNamedColor{named}{JungleGreen}{cmyk}{1,2,3,4}|\\
601 % it is available in the `named' colour model, for
602 % instance by\\
603 % |\color[named]{JungleGreen}|\\
604 % A user may give a more convenient name, using\\
605 % |\definecolor{mygreen}{named}{JungleGreen}|\\
606 % If however you are happy with the original names, and want to use
607 % them directly, as in |\color{JungleGreen}| without specifying
608 % |[named]| all the time, just give the package option |usenames|, which
609 % will redefine |\DefineNamedColor|, so that the colour name is declared
610 % as a user-colour as well as a name in the `named' model.
611 % \changes{v1.2a}{2019/11/23}
612 % {Add \cs{protected} gh/208}
613 % \begin{macrocode}
614 \protected\def\DefineNamedColor#1#2#3#4{%
615 \@ifundefined{define@color@#1}%
616 {\c@lor@error{model `#1'}}%
617 {\@ifundefined{color@#3}%
618 {\c@lor@error{model `#3'}}%
619 {\@ifundefined{col@#2}{}%
620 {\PackageInfo{color}{Redefining color #2 in named color model}}%
621 \csname color@#3\endcsname\@tempa{#4}%
622 \csname define@color@#1\endcsname{#2}\@tempa
623 \c@lor@usename{#2}}}}
624 \@onlypreamble\DefineNamedColor
625 % \end{macrocode}
626 % \end{macro}
627 %
628 % \section{Colour Switch}
629 %
630 % \begin{macro}{\ifcolors@}
631 % This boolean can be tested by higher level macros that may want to
632 % alter their behaviour if a monochrome driver is being used.
633 % \begin{macrocode}
634 \newif\ifcolors@
635 \colors@true
636 % \end{macrocode}
637 % \end{macro}
638 %
639 % \section{Whatsit\ldots}
640 %
641 % \begin{macro}{\c@lor@special}
642 % Some drivers can not support all the features of this package. They
643 % should always put a \meta{whatsit} in the current list though. The
644 % following macro has most of the features of |\special|, but does not
645 % put anything into the |dvi| file. It does write to the log file or the
646 % terminal (depending on the value of |#1|).
647 % \begin{macrocode}
648 \def\c@lor@special#1#2{%
649 \edef\@tempa{\write#1{#2}}\@tempa}
650 % \end{macrocode}
651 % \end{macro}
652 %
653 % \section{Processing Options}
654 %
655 % A local configuration file may declare more options.
656 % It should also make one driver option the default, by calling
657 % |\ExecuteOptions| with the appropriate option.
658 % \begin{macrocode}
659 \InputIfFileExists{color.cfg}{}{}
660 % \end{macrocode}
661 %
662 % After the options are processed, load the appropriate driver file.
663 % If a site wants a default driver (eg |dvips|) it just needs to put
664 % |\ExecuteOptions{dvips}| in a |color.cfg| file.
665 % \changes{v0.3b}{1994/09/14}
666 % {New style of loading driver files}
667 % \begin{macrocode}
668 \ProcessOptions
669 % \end{macrocode}
670 %
671 % \begin{macrocode}
672 \if!\Gin@driver!
673 \PackageError{color}
674 {No driver specified}
675 {You should make a default driver option in a file \MessageBreak
676 color.cfg\MessageBreak
677 eg: \protect\ExecuteOptions{dvips}%
678 }
679 \else
680 \PackageInfo{color}{Driver file: \Gin@driver}
681 \@ifundefined{ver@\Gin@driver}{\input{\Gin@driver}}{}
682 \fi
683 % \end{macrocode}
684 %
685 % \begin{macrocode}
686 \@ifundefined{c@lor@namefile}{}{\input{\c@lor@namefile}}
687 % \end{macrocode}
688 %
689 % \section{Default Colour}
690 %
691 % \begin{macro}{\normalcolor}
692 % Early versions of this package redefined |\reset@font| to reset the
693 % color as well. Current versions do not do this (since there are too many
694 % |\reset@font| commands hidden in strange places) and so they define a
695 % separate command, |\normalcolor|, to reset the colour to the colour in
696 % effect at the start of the document.
697 %
698 % |\normalcolor| is defined (to |\relax|) in the \LaTeX\ kernel, so it
699 % is safe to use this in macros that may possibly be used in
700 % conjunction with colour. It will have no effect until the |color|
701 % package is also loaded.
702 % \changes{v0.2b}{1994/04/18}
703 % {Only reset the colour with \cmd{\reset@font} not
704 % \cmd{\normalfont}}
705 % \changes{v0.2d}{1994/05/13}
706 % {Stop changing \cs{reset@font}. Use the new \cs{normalfont}
707 % instead.}
708 % \changes{v1.2a}{2019/11/23}
709 % {Add \cs{protected} gh/208}
710 % \begin{macrocode}
711 \protected\def\normalcolor{\let\current@color\default@color\set@color}
712 % \end{macrocode}
713 % \end{macro}
714 %
715 % \begin{macro}{\default@color}
716 % Internal macro to store the `default' colour used by |\normalcolor|.
717 % \begin{macrocode}
718 \AtBeginDocument{\let\default@color\current@color}
719 % \end{macrocode}
720 % \end{macro}
721 %
722 % |\current@color| contains an internal representation of the colour
723 % at this point in the document. (This can only be an approximation to
724 % the truth as the `macro layer' of \TeX\ does not know where the output
725 % routine is going to re-insert floats. This is why drivers must
726 % maintain their own stack of colours in order to fully support these
727 % commands.)
728 %
729 % For dvips, the |\current@color| is something like `|Black|' or
730 % `|rgb 0 1 0|', but other packages should not rely on any particular
731 % format for this macro.
732 %
733 % The driver file \emph{must} initialise |\current@color| to a
734 % specification for Black. This initialisation can not occur here, as
735 % the possible colour models (and thus the syntax for `black')
736 % are not known at this point.
737 %
738 % \section{Higher Level Commands}
739 %
740 % With the basic colour primitives specified above we may define a few
741 % higher level commands for coloured boxes etc. This is still quite a low
742 % level and presumably packages and classes making use of colour will
743 % define more appropriate document-level commands.
744 %
745 % \subsection{Colour Block}
746 %
747 % \begin{macro}{\color@block}
748 % |\color@block{|\emph{width}|}{|\emph{height}|}{|\emph{depth}|}|\\
749 % Should take up no space for \TeX, but produce a block in the current
750 % colour of the specified size. It is mainly used for producing box
751 % backgrounds.
752 %
753 % The definition here works by selecting a colour, and then drawing a
754 % \TeX\ rule (unless |\ifcolors@false|). This allows the `driver
755 % independent' colour specials to be used. However it is defined using
756 % |\providecommand|, so that this file will not over-write any other
757 % definition of this command. A graphics package may want to define it
758 % using a special to produce (for example) a PostScript line. Producing
759 % the line in the |\special| has the advantage that on a preview that
760 % does not understand |\special|s, the line is automatically omitted,
761 % without needing to modify the source of the document (for instance by
762 % adding the |monochrome| option).
763 %
764 % \begin{macrocode}
765 \def\color@block#1#2#3{%
766 {\set@color\rlap{\ifcolors@\vrule\@width#1\@height#2\@depth#3\fi}}}
767 % \end{macrocode}
768 % \end{macro}
769 %
770 % \subsection{Coloured Boxes}
771 %
772 % \begin{macro}{\colorbox}
773 % |\colorbox| takes the same argument forms as |\textcolor|, but the
774 % colour specifies the \emph{background} colour of the box.
775 % \changes{v0.3b}{1994/09/14}
776 % {New implementation}
777 % \changes{v1.2a}{2019/11/23}
778 % {Add \cs{protected} gh/208}
779 % \begin{macrocode}
780 \protected\def\colorbox#1#{\color@box{#1}}
781 % \end{macrocode}
782 % \end{macro}
783 %
784 % \changes{v0.3i}{1995/04/27}
785 % {Move \cs{leavevmode} for graphics/1521}
786 % \begin{macro}{\color@box}
787 % \begin{macrocode}
788 \def\color@box#1#2{\color@b@x\relax{\color#1{#2}}}
789 % \end{macrocode}
790 % \end{macro}
791 %
792 % \begin{macro}{\fcolorbox}
793 % |\fcolorbox| has an extra \emph{colour-spec} argument, and puts a
794 % frame of the first colour around a box with a background specified by
795 % the second colour. If an optional argument is given, it specifies the
796 % colour model for both colours.
797 % \changes{v0.3b}{1994/09/14}
798 % {New implementation}
799 % \changes{v1.2a}{2019/11/23}
800 % {Add \cs{protected} gh/208}
801 % \begin{macro}{\fcolorbox}
802 % \begin{macrocode}
803 \protected\def\fcolorbox#1#{\color@fbox{#1}}
804 % \end{macrocode}
805 %
806 % \begin{macrocode}
807 \def\color@fbox#1#2#3{%
808 \color@b@x{\fboxsep\z@\color#1{#2}\fbox}{\color#1{#3}}}
809 % \end{macrocode}
810 % \end{macro}
811 % \end{macro}
812 %
813
814 % \begin{macro}{\color@b@x}
815 % Internal macro for |\colorbox| and |\fcolorbox|.
816 % \changes{v0.3b}{1994/09/14}
817 % {Macro added.}
818 % \changes{v0.3i}{1995/04/27}
819 % {Add \cs{leavevmode} for graphics/1521}
820 % \begin{macrocode}
821 \long\def\color@b@x#1#2#3{%
822 \leavevmode
823 \setbox\z@\hbox{\kern\fboxsep{\set@color#3}\kern\fboxsep}%
824 \dimen@\ht\z@\advance\dimen@\fboxsep\ht\z@\dimen@
825 \dimen@\dp\z@\advance\dimen@\fboxsep\dp\z@\dimen@
826 {#1{#2\color@block{\wd\z@}{\ht\z@}{\dp\z@}%
827 \box\z@}}}
828 % \end{macrocode}
829 % \end{macro}
830 %
831 % \subsection{Providing \cs{mathcolor}}
832 %
833 % This is shared coded between different packages, so external.
834 %
835 % \begin{macrocode}
836 \input{mathcolor.ltx}
837 % \end{macrocode}
838 %
839 % \section{Extra Groups}
840 % Turning on extra groups in the standard \LaTeX\ commands, so that
841 % colour commands are scoped correctly.
842 %
843 % Like |\normalcolor|, the following five commands are defined in the
844 % kernel, with empty definitions (|\relax|). This means that they can
845 % be used to make macros in packages `colour safe'. The commands
846 % will not have any effect unless a user also uses this colour
847 % package, when the `active definitions' here will take effect and
848 % keep colour commands correctly scoped.
849 %
850 % \begin{macro}{\color@setgroup}
851 % This is to be used in contexts (eg `lrbox') where text is to be
852 % saved and used after some other, unknown, text that may contain
853 % colour commands. A matching |\color@endgroup| should be used at the
854 % end of the text.
855 % \changes{v0.2d}{1994/05/13}
856 % {Macro added}
857 % \begin{macrocode}
858 \def\color@setgroup{\begingroup\set@color}
859 % \end{macrocode}
860 % \end{macro}
861 %
862 % \begin{macro}{\color@begingroup}
863 % This is to be used at the start of contexts that may contain colour
864 % commands, but where it is not necessary to save the current colour.
865 % Examples of this are in the box commands of |ltboxes.dtx| where
866 % user-supplied text is saved internally in a box between
867 % |\color@begingroup|, |\color@endgroup|, but the box is used before
868 % any other colour commands could intervene. A matching
869 % |\color@endgroup| should be used at the end of the text.
870 % \changes{v0.2d}{1994/05/13}
871 % {New definition, was previously like \cs{color@setgroup}}
872 % \begin{macrocode}
873 \let\color@begingroup\begingroup
874 % \end{macrocode}
875 % \end{macro}
876 %
877 % \begin{macro}{\color@endgroup}
878 % To be used to close the `group' started by one of the above two
879 % commands. The |\endgraf| in its definition is required in the case
880 % of groups of text in vertical `par' mode, but doesn't do any harm in
881 % horizontal `LR' contexts.
882 % The |\@endpefalse| is required for the newer \texttt{@endpe}
883 % handling, again it is harmless if an older kernel is used
884 % (because there it was a local assignment).
885 % \changes{v0.2d}{1994/05/13}
886 % {New definition, was previously just \cs{endgroup}}
887 % \changes{v1.3e}{2024/06/23}
888 % {Support new \texttt{@endpe} mechanism}
889 % \begin{macrocode}
890 \def\color@endgroup{\endgraf\@endpefalse\endgroup}
891 % \end{macrocode}
892 % \end{macro}
893 %
894 % \begin{macro}{\color@hbox}
895 % To be used to open a `coloured hbox'
896 % \changes{v0.3g}{1994/11/08}
897 % {Macro added}
898 % \begin{macrocode}
899 \def\color@hbox{\hbox\bgroup\color@begingroup}
900 % \end{macrocode}
901 % \end{macro}
902 %
903 % \begin{macro}{\color@vbox}
904 % To be used to open a `coloured vbox'
905 % \changes{v0.3h}{1994/11/22}
906 % {Macro added}
907 % \begin{macrocode}
908 \def\color@vbox{\vbox\bgroup\color@begingroup}
909 % \end{macrocode}
910 % \end{macro}
911 %
912 % \begin{macro}{\color@endbox}
913 % To be used to close a `coloured hbox'
914 % \changes{v0.3g}{1994/11/08}
915 % {Macro added}
916 % \begin{macrocode}
917 \def\color@endbox{\color@endgroup\egroup}
918 % \end{macrocode}
919 % \end{macro}
920 %
921 %
922 % \changes{v0.2d}{1994/05/13}
923 % {tabbing support removed (now in kernel)}
924 %
925 % \changes{v0.3l}{1995/12/07}
926 % {\cs{underbar} removed (now in kernel)}
927 %
928 % \changes{v0.3h}{1994/11/22}
929 % {marginpar, phantom and smash now supported in kernel}
930 %
931 % \changes{v0.3l}{1995/12/07}
932 % {\cs{showhyphens} removed (now in kernel)}
933 %
934 %
935 % \section{Predefining Colours}
936 %
937 % As long as the driver file has defined sufficient colour models, we
938 % define a few colours, just to get people started.
939 %
940 % \begin{macro}{black}
941 % \begin{macro}{white}
942 % Black and white `colours'.
943 % \begin{macrocode}
944 \ifx\color@gray\@undefined
945 \ifx\color@rgb\@undefined
946 \else
947 \definecolor{black}{rgb}{0,0,0}
948 \definecolor{white}{rgb}{1,1,1}
949 \fi
950 \else
951 \definecolor{black}{gray}{0}
952 \definecolor{white}{gray}{1}
953 \fi
954 % \end{macrocode}
955 % \end{macro}
956 % \end{macro}
957 %
958 % \begin{macro}{red}
959 % \begin{macro}{green}
960 % \begin{macro}{blue}
961 % Additive primaries.
962 % \begin{macrocode}
963 \ifx\color@rgb\@undefined\else
964 \definecolor{red}{rgb}{1,0,0}
965 \definecolor{green}{rgb}{0,1,0}
966 \definecolor{blue}{rgb}{0,0,1}
967 \fi
968 % \end{macrocode}
969 % \end{macro}
970 % \end{macro}
971 % \end{macro}
972 %
973 % \begin{macro}{cyan}
974 % \begin{macro}{magenta}
975 % \begin{macro}{yellow}
976 % Subtractive primaries.
977 % \begin{macrocode}
978 \ifx\color@cmyk\@undefined\else
979 \definecolor{cyan}{cmyk}{1,0,0,0}
980 \definecolor{magenta}{cmyk}{0,1,0,0}
981 \definecolor{yellow}{cmyk}{0,0,1,0}
982 \fi
983 % \end{macrocode}
984 %
985 % \begin{macrocode}
986 %</package>
987 % \end{macrocode}
988 % \end{macro}
989 % \end{macro}
990 % \end{macro}
991 %
992 %
993 % \section{And Finally}
994 %
995 % Restore Catcodes
996 % \begin{macrocode}
997 \Gin@codes
998 \let\Gin@codes\relax
999 % \end{macrocode}
1000 %
1001 % \Finale
1002 %