Debian Codegraph @

texmf-dist/doc/latex/colorspace/colorspace.tex

raw
1 %
2 % Copyright (C) 2015-2019 Javier Bezos http://www.texnia.com
3 %
4 % This file may be distributed and/or modified under the conditions of
5 % the MIT License. A version can be found at the end of this file.
6 %
7 % Repository: https://github.com/jbezos/colorspace
8 %
9
10 \documentclass[a4paper]{ltxguide}
11
12 \title{\textsf{colorspace}\\\large Version 1.3}
13
14 \author{Javier Bezos\\\texttt{http://www.texnia.com}}
15
16 \date{2019-03-25}
17
18 \raggedright
19 \parskip=.8ex
20 \advance\oddsidemargin-.7cm
21 \advance\textwidth2cm
22 \addtolength{\textheight}{3.5cm}
23 \addtolength{\topmargin}{-2cm}
24
25 \newif\ifcolorspace
26 \newif\iftikz
27
28 \usepackage{graphicx,bera}
29
30 \IfFileExists{colorspace.sty}{%
31 \usepackage[illuminant=d65]{colorspace}%
32 \definespotcolor{foo}{BarTone 555 GN}{.8,.2,.5,.3}%
33 \definespotcolor{foob}{BarTone 666 GN}[rgb]{.8, .2, .4}%
34 \definespotcolor{foolab}{BarTone 888 LB}[alt=lab]%
35 {50, -30, -40/1, .20, .15, .07}%
36 %
37 \definecolorspace{fooshaded}{mixed}{foo,black}%
38 \definecolorspace{labshaded}{mixed}{foolab,foob}%
39 %
40 \definecolor{sfoo}{fooshaded}{1,0}
41 \definecolor{sblack}{fooshaded}{0,1}
42 \definecolorseries{shseries}{fooshaded}{last}{sfoo!40}{sblack}
43 \colorspacetrue}{}
44
45 \IfFileExists{tikz.sty}{%
46 \catcode`|=12
47 \usepackage{tikz}%
48 \catcode`|=\active
49 \tikztrue}{}
50
51 \def\showclr#1#{\testclr{#1}}
52 \def\testclr#1#2{{\fboxsep0pt\fbox{\colorbox#1{#2}{\phantom{,MM}}}}}
53
54 \makeatletter
55 \def\@begintheorem#1#2{%
56 \list{}{}%
57 \global\advance\@listdepth\m@ne
58 \item[{\sffamily\bfseries\color{foob}\MakeUppercase{#1}}]}%
59 \makeatother
60 \newtheorem{warning}{Warning}
61 \newtheorem{note}{Note}
62 \newtheorem{example}{Example}
63
64 \begin{document}
65
66 {\fontsize{48}{48}\selectfont colorspace\par}
67 {\LARGE Spot colors, mixed inks and more\par}
68 \vspace*{1ex}
69 Version 1.3 (2019-03-25)\par
70 Javier Bezos (\texttt{http://www.texnia.com})
71
72 \vspace*{6ex}
73
74 The aim of this package is, as its name implies, to provide tools for
75 PDF color spaces. It requires \textsf{xcolor}, which is loaded if it
76 has not been before. It seems to work with \textsf{tikz}.
77
78 Currently it supports what I think are the most common tools:
79 \begin{itemize}
80 \item Spot colors, with a clean user interface, and including tints
81 (with the |!| notation).
82 \item CIE LAB spot colors.
83 \item Proper switching of color spaces.
84 \item Mixed spot and process colors (up to 4), like shades (ie, a spot
85 color with black). Also CIE LAB if a CMYK equivalent is provided.
86 \item ICC based (or ``tagged'') default CMYK, RGB and Gray spaces.
87 \item Overprinting (across pages, using the color stack).
88 \end{itemize}
89 Currently only \textsf{pdftex} and \textsf{luatex} are
90 supported. Support for \textsf{xetex} is on the `to do' list, but due
91 to the limitations of this engine this task is somewhat challenging
92 and I'm not sure all features will be implemented.
93
94 Other functions related to the PDF color spaces (indexed, calibrated,
95 Lab spaces) are not yet suported, but they are under study. Calibrated
96 colors, although not directly supported, can be defined with an ICC
97 profile created with
98 LPROF\footnote{\texttt{http://lprof.sourceforge.net/}} and then
99 assigned to a default space as described below.
100
101 They apply to text and line art only, not external images. For the
102 latter, \textsf{graphicx} provides a plea of (undocumented)
103 transformations: \texttt{interpolate}, \texttt{decodearray},
104 \texttt{maskarray}, \texttt{intent}, \texttt{ocobjnum}, and
105 \texttt{ocobjref}. For transparency, see \textsf{transparent}, by
106 Heiko Oberdiek.
107
108 This package is still evolving, but the basic behaviour described here
109 will be preserved in future versions. However, some functions from
110 \textsf{xcolor} might not work yet (for example
111 \verb|\selectcolormodel| and the corresponding package options |cmyk|
112 and the like).
113
114 Declarations are global and should go in the preamble.
115
116 This package is built on the previous attempts to provide spot colors
117 and other additional features by Jens Elstner, Stephan Lehmke and Siep
118 Kroonenberg (with some inspiration from \textsf{ConTeXt}, too).
119
120 \section{CMYK spot colors}
121
122 Spot colors are defined with a single macro:
123
124 \begin{decl}
125 |\definespotcolor{<latex-name>}{<PDF-name>}{<CMYK-equivalent>}|
126 \end{decl}
127
128 Here |<latex-name>| is the \LaTeX{} name, as used in \verb|\color| and
129 the like, |<PDF-name>| is the PDF name (usually taken from a swatch
130 book; multiple spaces are collapsed into one) as shown by PDF viewers,
131 and the four numbers are the CMYK equivalent. \LaTeX{} knows nothing
132 about the PDF name, which is just a string to be written to the
133 generated file, while the PDF knows nothing about the \LaTeX{} name.
134
135 To mix inks, see below.
136
137 \begin{example}
138 Write, for example:
139 \begin{verbatim}
140 \definespotcolor{foo}{BarTone 555 GN}{.8,.2,.5,.3}
141 \end{verbatim}
142 This creates the color \showclr{foo}, which is used in \LaTeX{} as
143 |\color{foo}|. If you preflight the PDF file you will see a color
144 named `BarTone 555 GN' besides cyan, magenta, yellow and black.
145
146 You can use tints as usual in \textsf{xcolor}, like:
147 \begin{verbatim}
148 \color{foo!50}
149 \colorlet{foo50}{foo!50}
150 \end{verbatim}
151 \ifcolorspace
152 which would produce \showclr{foo!50}, and
153 \fi
154 even set tints from other tints.
155 \end{example}
156
157 \begin{note}
158 The special PDF names \verb|All| (for all plates) and \verb|None|
159 work as expected:
160 \begin{verbatim}
161 \definespotcolor{registration}{All}{1,1,1,1}
162 \end{verbatim}
163 \end{note}
164
165 \begin{note}
166 Remember as far PDF is concerned a spot color is a color space on
167 its own.
168 \end{note}
169
170 \begin{note}
171 This package does not provide a list of Pantone, TrueMatch, HKS,
172 Folcoltone, Toyo, etc., colors. Currently you can find quite easily
173 CMYK equivalents on the web, and after all they are intended to be
174 used with a ``physical'' swatch book (and not, as often done, by
175 picking a color from a ``virtual'' palette just because it looks
176 nice on screen).
177 \end{note}
178
179 \begin{decl}
180 |\definespotcolor{<latex-name>}{<PDF-name>}[<model>]{<equivalent>}|
181 \end{decl}
182
183 Internally, only CMYK is used for the equivalent color, but with this
184 variant you can define the latter with another name space, which is
185 then converted.
186 \begin{example} The following definition is based on RGB:
187 \begin{verbatim}
188 \definespotcolor{foob}{BarTone 666 GN}[rgb]{.8, .2, .4}
189 \end{verbatim}
190 which yields \showclr{foob}. Here \textsf{xcolor} just
191 converts this value to CMYK, which is still the space used
192 internally.
193 \end{example}
194
195 \begin{warning}
196 This conversion relies on the \textsf{xcolor} numerical methods,
197 which do not take into account any color profile and therefore
198 should be avoided in production if the alternate space is going to
199 be actually used. It is provided just for convenience in drafting or
200 in contexts where accuracy is not essential.
201 \end{warning}
202
203 \section{CIE LAB spot colors}
204
205 Instead of targeting the CMYK space, spot colors may be defined using
206 the CIE LAB (also known as L*a*b*, or even just Lab) space. Unlike the
207 default CMYK space, which is by default device dependend, the Lab
208 space is device independent. To define a Lab spot color, you must
209 first set the illuminant with the package option |illuminant|, which
210 takes a value:
211 \begin{verbatim}
212 \usepackage[illuminant=d65]{colorspace}
213 \end{verbatim}
214 Values are \texttt{a}, \texttt{c}, \texttt{e}, \texttt{d50},
215 \texttt{d55}, \texttt{d65}, \texttt{d75}.
216
217 The command to define a color is:
218 \begin{decl}
219 |\definespotcolor{<latex-name>}{<PDF-name>}[alt=lab]{<Lab-values>}|
220 \end{decl}
221 Note the optional argument with the string |alt=lab| (which cannot be
222 combined with a model). The three |<Lab-values>| have ranges
223 \textit{L}* $=$ $0$\ldots$100$, \textit{a}* $=$ $-$128$\ldots$127,
224 \textit{b}* $=$ $-$128{\ldots}127, respectively.
225
226 \begin{example}
227 With
228 \begin{verbatim}
229 \definespotcolor{foolab}{BarTone 888 LB}[alt=lab]{50, -30, -40}
230 \end{verbatim}
231 the result is \showclr{foolab}. An example of tint is
232 \verb|\color{foolab!30}| (\showclr{foolab!30}).
233 \end{example}
234
235 \begin{warning}
236 The package does not warn if the color falls outside the gamut of
237 the CMYK space or if the color is not visible. To put it in
238 other words, you should not just write some arbitrary values to see
239 what happens.
240 \end{warning}
241
242 \begin{warning}
243 This model is not available in \textsf{xcolor}. If you need some
244 transformation, you must resort to an external tool like
245 \textsf{transicc} (or \textsf{icctrans}) included in Little
246 CMS\footnote{\texttt{http://www.littlecms.com/1/downloads.htm}}.
247 \end{warning}
248
249 \begin{warning}
250 There is no default illuminant -- it must be set if Lab colors are
251 defined.
252 \end{warning}
253
254 \begin{note}
255 The observer is currently only 2$^\circ$ (1931).
256 \end{note}
257
258 The Lab space allows to define colors accurately, but there is a price
259 to pay -- mixing Lab colors is not in general possible except after
260 converting them somehow to CMYK or RGB.\footnote{There are no simple
261 rules to carry out those transformations, which, I think, explains why
262 \textsf{xcolor} does not support Lab at all}. Since currently mixing
263 colors in this package is based on CMYK, you must provide an alternate
264 value as shown, if mixed inks are required\footnote{Internally, and
265 in PDF jargon, Lab is the ``alternate space'' and ``tints transforms''
266 are based on CMYK}:
267 \begin{verbatim}
268 \definespotcolor{foolab}{BarTone 888 LB}[alt=lab]{50, -30, -40/1, .20, .15, .07}
269 \end{verbatim}
270
271 \section{Mixing spot colors}
272
273 To mix spot colors you must first declare a color space (or model)
274 including them. This is done with the following macro:
275
276 \begin{decl}
277 |\definecolorspace{<latex-name>}{mixed}{<color-list>}|
278 \end{decl}
279
280 Here, |<latex-name>| is the name to be used in |\color| and the
281 like as the color model. The second argument is the string |mixed|,
282 and the last one is a list of up to 4 colors, either defined with
283 \textsf{xcolor} using the CMYK model or spot.
284
285 \begin{example}
286 A simple and typical usage would be for shades:
287 \begin{verbatim}
288 \definecolorspace{fooshaded}{mixed}{foo,black}
289 \end{verbatim}
290 Then, you can define a color in this new model named
291 \verb|fooshaded| with:
292 \begin{verbatim}
293 \definecolor{darkfoo}{fooshaded}{.6,.3}
294 \end{verbatim}
295 Or set it with:
296 \begin{verbatim}
297 \color[fooshaded]{.6,.3}
298 \end{verbatim}
299 In both cases, the mix is 60\% \verb|foo| and 30\% \verb|black|.
300 \end{example}
301
302 \begin{example}
303 If we have two spot colors named \verb|spot1| and \verb|spot2|, and
304 we want in addition yellow:
305 \begin{verbatim}
306 \definecolorspace{mix12y}{mixed}{spot1,spot2,yellow}
307 \end{verbatim}
308 To define a new color based on this space:
309 \begin{verbatim}
310 \definecolor{mix12y}{mix12y}{.5,.4,.6}
311 \end{verbatim}
312 And to set it:
313 \begin{verbatim}
314 \color[mix12y]{.5,.4,.6}
315 \end{verbatim}
316 \end{example}
317
318 \begin{example}
319 Here is a duotone mixing the \verb|foob| and \verb|foolab| colors defined above:
320 \begin{verbatim}
321 \definecolorspace{labshaded}{mixed}{foolab,foob}
322 \end{verbatim}
323 The colors corresponding to:
324 \begin{verbatim}
325 \color[labshaded]{1,0} \color[labshaded]{.8,.2}
326 \color[labshaded]{.6,.4} \color[labshaded]{.4,.6}
327 \color[labshaded]{.2,.8} \color[labshaded]{0,1}
328 \end{verbatim}
329 are \showclr[labshaded]{1,0} \showclr[labshaded]{.8,.2}
330 \showclr[labshaded]{.6,.4} \showclr[labshaded]{.4,.6}
331 \showclr[labshaded]{.2,.8} \showclr[labshaded]{0,1}
332 \end{example}
333
334 \begin{warning}
335 Due to internal limitations of \textsf{xcolor}, no more than four
336 colors are allowed.
337 \end{warning}
338
339 \begin{note}
340 The alternate color space in the PDF file is that of the spot colors
341 (which means currently it is CMYK).
342 \end{note}
343
344 \begin{note}
345 There is an easy trick to mix colors with \verb|!| and
346 \verb|color,num| -- just define an ortogonal set of colors based on
347 the new color model:
348 \begin{verbatim}
349 \definecolor{xspot1}{mix12y}{1,0,0}
350 \definecolor{xspot2}{mix12y}{0,1,0}
351 \definecolor{xyellow}{mix12y}{0,0,1}
352 \end{verbatim}
353 and then you can say:
354 \begin{verbatim}
355 \color{xspot1!30!xspot2!40!xyellow}
356 \color{mix12y:xspot1,3;xspot2,2;xyellow,1}
357 \end{verbatim}
358 Of course, it is just a trick and a better and direct interface is
359 under study (none of those provided by \textsf{xcolor} fits well
360 with the new |mixed| models).
361 \end{note}
362
363 \begin{warning}
364 Mixing colors in \verb|\color|, \verb|\definecolor| and the like
365 from diferent spaces can lead to unexpected results (currently no
366 checking is done).
367 \end{warning}
368
369 Color series (see the \textsf{xcolor} documentation) are also
370 partially supported. For example:
371 \begin{verbatim}
372 \definecolorseries{test}{mix12y}{grad}[mix12y]{.95,.85,.55}{3,11,17}
373 \definecolorseries{test}{mix12y}{last}{xyellow!50}{xspotA}
374 \end{verbatim}
375
376 \ifcolorspace
377 \begin{example}
378 Here is a example with some of the described techniques, based on
379 the |fooshaded| space defined above (figure 1 shows the |foo|
380 plate):
381
382 \begin{verbatim}
383 \definecolor{sfoo}{fooshaded}{1,0}
384 \definecolor{sblack}{fooshaded}{0,1}
385 \definecolorseries{shseries}{fooshaded}{last}{sfoo!40}{sblack}
386 \def\testclr#1{{\fboxsep0pt\fbox{\colorbox{#1}{\phantom{XX}}}}}
387 \resetcolorseries[8]{shseries}
388 \begin{tabular}{cccccccc}
389 0 \testclr{shseries!!+} &
390 1 \testclr{shseries!!+} &
391 2 \testclr{shseries!!+} &
392 3 \testclr{shseries!!+} &
393 4 \testclr{shseries!!+} &
394 5 \testclr{shseries!!+} &
395 6 \testclr{shseries!!+} &
396 7 \testclr{shseries!!+}
397 \end{tabular}
398 \end{verbatim}
399
400 \begingroup
401 \def\testclr#1{{\fboxsep0pt\fbox{\colorbox{#1}{\phantom{XX}}}}}
402 \resetcolorseries[8]{shseries}
403 \begin{tabular}{cccccccc}
404 0 \testclr{shseries!!+} &
405 1 \testclr{shseries!!+} &
406 2 \testclr{shseries!!+} &
407 3 \testclr{shseries!!+} &
408 4 \testclr{shseries!!+} &
409 5 \testclr{shseries!!+} &
410 6 \testclr{shseries!!+} &
411 7 \testclr{shseries!!+}
412 \end{tabular}
413 \endgroup
414 \end{example}
415 \fi
416
417 \begin{figure}
418 \fbox{\includegraphics[width=\linewidth]{colorspaceshade.png}}
419 \caption{Plate for the \texttt{foo} spot color as shown by Adobe
420 Acrobat. Note both \texttt{foob} and \texttt{foolab},
421 defined in this document, are listed, too.}
422 \end{figure}
423
424 \section{Page color spaces}
425
426 Each PDF page must know which colors will be used (other than the
427 predefined CMYK, RGB and Gray). By default, \textsf{colorspace} turns
428 on for every page all newly defined colors, and that will be fine in
429 most cases. However, you may want to set explicitly the list (for
430 covers or plates). Use this feature with care, because (1) the
431 asynchronous nature of \TeX{} (remember it affects the whole current
432 page), and (2) each distinct color list creates a PDF resource.
433
434 \begin{decl}
435 |\pagecolorspace{<color-list>}|\\
436 |\resetpagecolorspace|
437 \end{decl}
438
439 To change the color space for a page and the subsequent ones, you can
440 set something like:
441 \begin{verbatim}
442 \pagecolorspace{name1,name2,name3}
443 \end{verbatim}
444 (It can be empty.) To return to the default color space, which
445 contains all the defined spot colors, use \verb|\resetpagecolorspace|.
446
447 \section{ICC based spaces}
448
449 \begin{decl}
450 |\definecolorspace*{<latex-name>}{iccbased}{<icc-file>}|
451 \end{decl}
452 The starred version \verb|\definecolorspace*| does not define a new
453 color model, but sets the behaviour of the three basic color spaces
454 (CMYK, RGB and Gray). When belonging to the same space, the last
455 definition for that space takes precedence and it is considered the
456 default one. It cannot be used to define new colors or set
457 them. Currently, only a type is supported -- \verb|iccbased|. For
458 example,
459 \begin{verbatim}
460 \definecolorspace*{sRGB}{iccbased}{sRGB Profile.icc}
461 \end{verbatim}
462
463 The space it applies to is read from the ICC profile.
464
465 The name can be used in \verb|\pagecolorspace|. Alternatively, there
466 are 3 reserved names: \verb|*rgb|, \verb|*gray|, \verb|*cmyk|, which
467 stand for the last-defined, default ICC based spaces. Named ICC based
468 spaces are not set by \verb|\resetpagecolorspace|, but the starred
469 named are. On the other hand, the starred names are not set
470 automatically by |\pagecolorspace|, and you must set them explicitly
471 if you want them to be active.
472
473 \begin{note}
474 Those ICC spaces do not go to the output intent dictionary (see
475 the \textsf{pdfx} package). The latter, as the PDF reference
476 explains, supplements rather than replaces the ICC profiles in a
477 default color space.
478 \end{note}
479
480 \begin{example}
481 Given the following declarations:
482 \begin{verbatim}
483 \definecolorspace*{sRGB}{iccbased}{sRGB Profile.icc}
484 \definecolorspace*{colormatch}{ColorMatchRGB.icc}
485 \end{verbatim}
486 and remembering the RGB space is always active (like the CMYK and
487 Gray ones),
488 \begin{verbatim}
489 \pagecolorspace{}
490 \end{verbatim}
491 leaves the RGB space unprofiled;
492 \begin{verbatim}
493 \pagecolorspace{sRGB}
494 \end{verbatim}
495 sets the RGB space to sRGB; while the following are (in this
496 particular example) equivalent:
497 \begin{verbatim}
498 \pagecolorspace{colormatch}
499 \pagecolorspace{*rgb}
500 \resetpagecolorspace
501 \end{verbatim}
502
503 \end{example}
504
505 \section{Overprinting}
506
507 This is usually a pre-print task, but by setting it in the document
508 you will get a better idea of how the colors are actually overlapped
509 in soft proofing. However, remember the effect produced is
510 device-dependent, and colorant overprint decisions should be made at
511 output time (according to the PDF reference).
512
513 Very often, it is set for the whole document with the package options
514 \verb|knockout| (no overprint), and \verb|overprint|. By default, the
515 overprint mode is 1, but it can be changed with \verb|opm=0|.
516
517 Once set the overprint state for the whole document, you can use
518 something like:
519 \begin{verbatim}
520 {\overprintstate{1}text}
521 \textoverprint[1]{text}
522 \end{verbatim}
523 (or \verb|0|, or \verb|no|; default in \verb|\textoverprint| is
524 \verb|1|, except with the package option \verb|opm=0|).
525
526 Since the color stack is used, pdf\TeX{} $\ge$ 1.40 is required.
527
528 \begin{warning}
529 Some PDF viewers ignore this setting.
530 \end{warning}
531
532 \section{Version}
533
534 1.1.1. No new features. Just internal changes related to
535 \textsc{luatex} and new manual.
536
537 1.2.0. CIE LAB spot colors and |illuminant|. Manual rewritten.
538
539 1.3. Fixes several incompatibilities with \textsf{pgf}/\textsf{tikz}.
540
541 \end{document}
542
543 MIT License
544 -----------
545
546 Permission is hereby granted, free of charge, to any person obtaining a
547 copy of this software and associated documentation files (the
548 "Software"), to deal in the Software without restriction, including
549 without limitation the rights to use, copy, modify, merge, publish,
550 distribute, sublicense, and/or sell copies of the Software, and to
551 permit persons to whom the Software is furnished to do so, subject to
552 the following conditions:
553
554 The above copyright notice and this permission notice shall be included
555 in all copies or substantial portions of the Software.
556
557 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
558 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
559 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
560 IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
561 CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
562 TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
563 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.