Sei sulla pagina 1di 11

The xspotcolor package

Stephan Lehmke
mailto:Stephan.Lehmke@QuinScape.de
www.docscape.de
? from ?
Abstract
The spotcolor package provides an implementation of spot colors for
PDF files generated with LATEX. While it gets the PDF technology completely right, the user interface does not work with the packages xcolor
and thus TikZ which are in widespread use particularly for colorful LATEX
documents.
This package provides some patches and integration between spotcolor
and the xcolor and tikz packages which allow spot colors to be used like
all other colors in a LATEX document, in text as well as in images created
with the TikZ package.

Contents
1 Introduction

2 Requirements
2.1 Required Packages . . . . . . . . . . . . . . . . . . . . . . . . . . .

2
2

3 Usage
3.1 Package Options . . . . . . . . . . . .
3.2 Declaring Colors . . . . . . . . . . . .
3.2.1 Declaring a Color Space . . . .
3.2.2 Defining a Spot Color . . . . .
3.2.3 Defining a Tint of a Spot Color
3.3 Using Spot Colors in a Document . . .
3.4 Example of Use . . . . . . . . . . . . .

3
3
3
4
4
5
5
7

.
.
.
.
.
.
.

.
.
.
.
.
.
.

.
.
.
.
.
.
.

.
.
.
.
.
.
.

.
.
.
.
.
.
.

.
.
.
.
.
.
.

.
.
.
.
.
.
.

.
.
.
.
.
.
.

.
.
.
.
.
.
.

.
.
.
.
.
.
.

.
.
.
.
.
.
.

.
.
.
.
.
.
.

.
.
.
.
.
.
.

.
.
.
.
.
.
.

.
.
.
.
.
.
.

.
.
.
.
.
.
.

4 Limitations

5 Possible Extensions

6 Implementation
6.1 Initialization and Package Options . . . . . . . . . . . . . . . . . .
6.2 Patches . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
6.3 Predefined Colors . . . . . . . . . . . . . . . . . . . . . . . . . . . .

9
9
10
11

7 Change History

11

8 Index

11

Introduction

Spot color is a term from printing technology referring to any color which has
its own ink. So basically, in the usual CMYK printing process, Cyan, Magenta,
Yellow, and Black are spot colors.
The purpose of the spotcolor package is to provide support for additional
spot colors. Adding a spot color means that an additional type of ink (and hence,
printing plate and run) needs to be added to the printing process. Sometimes
this is used to extend the usual CMYK colors (by silver or gold, for instance, or
by a specific corporate color which cannot be produced adequately by CMYK),
but more often, a two-color (or three-color) process is desired (combining black
and one or two specific colors) to save printing costs. Any spot color can come in
any number of tints. In a sense, thats a mixture of the original color with white,
making it lighter. Like the gray color model which is based on black and allows
all different shades of gray right until white.
The spotcolor package contains all the neccessary definitions for adding and
maintaining spot colors in a PDF document produced with LATEX and pdftex, but
unfortunately it is not very well integrated with the standards of color management in LATEX, which basically means the xcolor package, plus tikz for making
diagrams. This makes it hard to actually use spot colors provided by spotcolor
in LATEX documents.
This package provides some patches and small extensions to the mentioned
packages which make them more seamlessly integrated, so that spot colors can be
used just like any other colors in a LATEX document.
The package was implemented in the course of answering the questions Using
Pantone/spot colors and TikZ together and Spotcolor bleeds into the surrounding on the Q&A site TEX Stack Exchange. Report bugs at the TEX-SX Launchpad
site. There is also a chatroom dedicated to the TEX-SX packages.

2
2.1

Requirements
Required Packages

The xspotcolor package automatically loads the following further packages:


etoolbox, spotcolor, xcolor.
If youre using the tikz package, you should load it after xspotcolor.

Usage

As this package doesnt add much to the packages it integrates, most aspects of
usage are covered much better in the documentation of the parent packages, in
particular spotcolor, which you should also consult.
In the following usage documentation, a unified view is presented which is
created by combining the interface of the original spotcolor package with LATEXs
standard color management.
Note
If you are considering to put spot colors in your document, then quite probably
you know more about spot colors than I do. Im just the guy who can read TEX
code and did some testing and fixing on the package interfaces. So if you find any
errors or inconsistencies in the following documentation, feel free to ignore it, file
a bug report or contact me by email to get it fixed.

3.1

Package Options

The xspotcolor package offers just one specific package option:


autodefine When this option is given, the command \AddSpotColor will automatically also define a LATEX color. See sections 3.2.2 and 3.2.3.
Besides that, the options of the spotcolor package are recognized. These are
in particular the options hks and pantone to preload color definitions (see the
spotcolor documentation).
Note
I do not recommend using the options hks and pantone. Using them will practically declare that all defined colors of the respective color space can be used on a
page (although probably very few are actually used). On testing, I have experienced errors in Acrobat Professional trying to do a color separation from such a
PDF.
In reality, only very few (probably only one or two) spot colors will actually
be used in one document. To be safe, you should declare only those colors you are
using (see section 3.2).

3.2

Declaring Colors

To use spot colors in a document, you need to do three things:


1. Declare a color space.
2. Define a spot color within this color space.
3. Afterwards, you can either use the spot color directly or define a color in
LATEXs usual sense as a tint of a spot color.
3

3.2.1

Declaring a Color Space

Concerning the handling of spot colors in a PDF file, a color space is an object
declaring which spot colors can be used on a specific page. If you wish to use
different sets of spot colors on different pages of the document, you can organise
them in different spaces and switch between pages.
But any page containing a spot color must have a color space containig that
color, and every page can have at most one color space.
For practical purposes, it is probably easiest to have one color space per document, put all the relevant spot colors in there and select it once and for all at the
beginning of the document.
A color space is declared by
\NewSpotColorSpace{hspace i}
where hspace i is an arbitrary string which is used by other commands to refer to
that space. As it will go literal in the PDF code, it should only contain safe
characters (to be sure, better only use letters and numerals).
Note
All matters concerning spot colors should be discussed beforehand with your
printer. How many and which spot colors are used has enormous implications
for the printing process. Especially switching color spaces mid-document is probably highly complicated as pages have to be organised and printed in sheets (of
usually 16 or 32 pages) and spot colors have to be consistent for one sheet. The
concequences of a misunderstanding between you and the print shop about the
use of spot colors can be really vile, so make sure there is complete agreement and
send them test files early!
As mentioned in section 3.1, I do not recommend packing for instance all
Pantone colors into one Pantone color space as color separation tools could choke
on too many different spot colors on one page, even if only a few are used.
3.2.2

Defining a Spot Color

A spot color is defined by


\AddSpotColor{hspace i}{hname i}{hPDF name i}{hCMYK Spec i}
where hspace i is the name of a defined color space, hname i is the name of the spot
color to be defined, hPDF name i is the color name which is put in the PDF file and
hCMYK Spec i is the CMYK replacement for situations where the spot color is not
available.
hname i is used to refer to the spot color when defining a LATEX color based on it,
while hPDF name i is the name which will appear in the color separation dialogue of
the application used to postprocess the PDF file. As hPDF name i is written literal
into the PDF file, it cant contain any spaces. The spotcolor package provides a

macro \SpotSpace to denote a space character in a hPDF name i. See the example
in section 3.4.
The CMYK color specified by hCMYK Spec i is used in all situations (for instance, on screen or for digital printing) where the original spot color is not available.
The original spotcolor package provides two files spotcolorpantone.tex
and spotcolorhks.tex with spot color definitions for Pantone and HKS palettes,
respectively. As mentioned above, I do not recommend to input these files, thereby
preloading a full palette. For practical purposes, it is enough to copy the definitions
of those colors which are to be actually used into the document.
If the package option autodefine is given, then \AddSpotColor of the spot
color named hname i will automatically also define a LATEX color of that name,
denoting the 100% tint of that spot color.
The example in section 3.4 also demonstrates that hPDF name i is just a string
which is displayed in the color separation dialog. The PDF processing application
does not auto-compare this name with a given palette. More likely, some human
operator will read this text and go to the store room to fetch a can of ink.
This makes it all the more important to check beforehand with the
print shop that you agree on spot colors, and get proofs!
3.2.3

Defining a Tint of a Spot Color

When a spot color is defined by \AddSpotColor, this is comparable to a


monochrome color model like gray: From a single spot color (in that case black),
a lot of specific colors can be derived as tints.
Analogously, a specific color is defined as a tint of an already defined spot color
by
\definecolor{hcolor i}{spotcolor}{hname i,htint i}
where hcolor i is the name of the new LATEX color to be defined, hname i is the
name of an already defined spot color, and htint i is a value between 0 and 1
giving the tint. 0 means white, 1 is the full spot color.
If the package option autodefine is given, then \AddSpotColor of the spot
color named hname i will automatically also define a LATEX color of that name,
denoting the 100% tint of that spot color. So in that case, it is not neccessary
to use \definecolor for the tint 1.0, you can just use the name of the spot color.
The color hcolor i can then be used as any other color in LATEX (after the
corresponding spot color space has been selected with \SetPageColorSpace; see
section 3.3). See the example in section 3.4.

3.3

Using Spot Colors in a Document

After everything is defined, spot colors need to be set up for use in the document
with
\SetPageColorSpace{hspace i}
5

where hspace i is the name of a defined color space. This configuration is valid
from the current page to the end of the document, or until it is overriden by
another call to \SetPageColorSpace.
After issuing \SetPageColorSpace, spot colors, respectively defined colors
based on spot colors in this space can be used just like other colors, that is,
with commands like \color, \pagecolor, \colorbox, or as color specifications in
TikZ drawings. See the example in section 3.4.
If you have defined a spot color hname i and dont want to define a LATEX color
based on it, then you can (as usual) directly use (a tint of) this color by issuing
\color[spotcolor]{hname i,htint i}
or, for instance, to print a piece of htext i in a specific tint,
\textcolor[spotcolor]{hname i,htint i}{htext i}
The spotcolor package provides another macro for switching to a spot color:
\SpotColor{hname i}{htint i}
which is identical with \color[spotcolor]{hname i,htint i}.
Notes
1. As mentioned above, configuring different pages with different color spaces
by using \SetPageColorSpace several times in a document is possible, but
might be problematic for the printing process and should be discussed with
the print shop to avoid unpleasant surprises. In all cases, one page can have
at most one color space.
For practical purposes, it is probably easiest to have one color space per
document, put all the relevant spot colors in there and select it once and for
all at the beginning of the document.
2. The original version of \SpotColor provided by the spotcolor package has
a bug which will make the color spill out of a grouped context. This package
adds a patch to make \SpotColor behave like \color in this respect.
3. Note that everything mentioned in this documentation applies to the original
spotcolor package as well if you dont use xcolor or tikz. In particular,
if you load the packages spotcolor and color, then everything will work
as described here.
You should only avoid using \SpotColor as it is broken in the original
spotcolor package.
4. It should also be mentioned that advanced color features provided by xcolor,
like mixing colors, are not available with spot colors.

3.4

Example of Use

The following example (file xspotcolorxmpl.tex) demonstrates setting up and


using spot colors in a LATEX document. Figure 1 shows the resulting PDF in the
color separation view of Acrobat Professional (sorry for the German locale).
\documentclass[a5paper,12pt]{article}
% Load the package plus TikZ to do some examples.
\usepackage{xspotcolor}
\usepackage{tikz}
\usetikzlibrary{lindenmayersystems}
% We define a single spot color space for the whole document.
\NewSpotColorSpace{Document}
% This definition was copied from the file spotcolorpantone.tex.
\AddSpotColor{Document}{PANTONE3035PC}{PANTONE\SpotSpace 3035\SpotSpace PC}{1 0
0.05 0.72}
% Some arbitrary spot color definitions just to demonstrate how it works.
\AddSpotColor{Document}{SunYellow}{Sunny\SpotSpace Yellow}{0 0.09 0.97 0}
\AddSpotColor{Document}{SnotGreen}{Snot\SpotSpace Green}{0.26 0 0.30 0.12}
\AddSpotColor{Document}{FrogGreen}{Frog\SpotSpace Green}{0.78 0 0.59 0.34}
% Now we define several LaTeX colors as tints of the spot colors.
\definecolor{mypagecolor}{spotcolor}{SnotGreen,0.3}
\definecolor{bgcolor}{spotcolor}{SunYellow,0.6}
\definecolor{treegreen}{spotcolor}{FrogGreen,0.9}
\definecolor{PANTONE3035PC}{spotcolor}{PANTONE3035PC,1.0}
\definecolor{PANTONE3035PC-80}{spotcolor}{PANTONE3035PC,.8}
% Redefine emphasis.
\DeclareRobustCommand\em{\color{PANTONE3035PC-80}}

\pagestyle{empty}
\begin{document}
% As all spot colors for this document are in a single color space,
% this is needed only once.
\SetPageColorSpace{Document}
% Demonstration of different uses of spot colors.
\pagecolor{mypagecolor}
The \emph{Pantone color} can be used in text by the ordinary commands
for color switching.
\textcolor[spotcolor]{PANTONE3035PC,.4}{Different tints of the same color can be
used.}
\bigskip
\noindent

Figure 1: Example PDF in color separation dialog.

TikZ Picture:
\bigskip
% The following code is taken from a question by Stefan Kottwitz on
% tex.stackexchange.com.
\noindent
\colorbox{bgcolor}
{%
\begin{tikzpicture}
\draw [color=treegreen, l-system={rule set={S -> [+++G][---G]TS,
G -> +H[-G]L, H -> -G[+H]L, T -> TL, L -> [-FFF][+FFF]F}, step=4pt,
angle=18,
axiom=+++++SLFFF, order=11}] lindenmayer system -- cycle;
\end{tikzpicture}
}
\end{document}

Limitations

The main limitation is that currently the integration of spot colors with the xcolor
package is superficial at best. The current patch ensures that simple definitions
and use cases for spot colors work, but the xcolor package is brim full of case
distinctions based on a predefined set of color models which I havent even looked
at.
I tested mixing colors like this \color{hsome spot color i!50!white}, which
threw an error, as expected. There is another way to get a tint of a spot color,
and I dont even know if mixing spot colors with other colors is supported in any
way by the PDF specification, but there may be other features of xcolor which
make sense which could be supported.

Possible Extensions

As mentioned above, a tighter integration into xcolor could be a good idea, to at


least give a meaningful error message for cases that dont work.
There are also certainly possible uses of spot colors within TikZ which are
currently not covered, for instance making color gradients from tints of one spot
color.

Implementation

6.1

Initialization and Package Options

We load the required packages and setup options. The options of spotcolor are
implemented here to make sure the preloading of the color definitions happens
after potential redefinition of \AddSpotColor (see below).
1

\RequirePackage{etoolbox}

2
3

\RequirePackage{spotcolor}
\RequirePackage{xcolor}

We also set up a switch to check the autodefine option.


4
5

\newif\ifautodefine@xspc
\DeclareOption{autodefine}{\autodefine@xspctrue}

The options hks to preload hks color values into HKS colorspace and pantone to
preload pantone color values into PANTONE colorspace are duplicated here so that
preloading does not happen prematurely.
6
7

\DeclareOption{hks}{\hkstrue}
\DeclareOption{pantone}{\pantonetrue}

8
9

\ProcessOptions\relax

6.2

Patches

First, a patch to spotcolors command \SpotColor so that it will apply colors


color grouping magic to make spot colors behave well in groups (and boxes).
10

\apptocmd\SpotColor{\aftergroup\reset@color}{}{}

If the autodefine option was given, extend \AddSpotColor to define a LATEX


color of the same name.
\ifautodefine@xspc
\apptocmd\AddSpotColor{\definecolor{#2}{spotcolor}{#2,1.0}}{}{}
13 \fi
11
12

This makes spotcolor a defined color model for xcolor.


14

\XC@sdef\XC@mod@spotcolor{spotcolor}

Now, a patch to (xcolors version of) \definecolor. I practically wrapped the


original command in a case distinction filtering out colors with model spotcolor.
A tighter integration would surely be better, but I cant fathom all the stuff thats
going on in the original command.
\def\@@pdfspotcolordef@xspc#1,#2\@@{/#1 cs /#1 CS #2 sc #2 SC}
\let\o@XC@definec@lor@xspc\XC@definec@lor
17 \def\XC@definec@lor[#1]#2[#3]#4#5%
18 {%
19
\expandafter\ifx\csname XC@mod@#4\endcsname\XC@mod@spotcolor
20
\expandafter\xdef\csname\string\color @#2\endcsname
21
{\noexpand\xcolor@{}{\@@pdfspotcolordef@xspc#5\@@}{spotcolor}{#5}}%
22
\else
23
\o@XC@definec@lor@xspc[#1]{#2}[#3]{#4}{#5}%
24
\fi
25 }%
15
16

The following declares pgf-specific handlers for spot colors, to be used by TikZ.

\def\pgfsys@color@spotcolor@stroke#1#2{\pgfsysprotocol@literal{/#1 CS}\pgfsysprotocol@literal{#2
\def\pgfsys@color@spotcolor@fill#1#2{\pgfsysprotocol@literal{/#1 cs}\pgfsysprotocol@literal{#2 s
28 \def\pgfsys@color@spotcolor#1#2{\pgfsys@color@spotcolor@stroke{#1}{#2}\pgfsys@color@spotcolor@fi
26
27

10

6.3

Predefined Colors

If the package option hks or pantone have been given, then load the corresponding
color tables now that \AddSpotColor has had the possibility to be patched.
29
30

\ifhks\input{spotcolorhks}\fi
\ifpantone\input{spotcolorpantone}\fi

Change History

1.0

1.1
General: Converted to DTX file . . 1

General: Added autodefine option 10

Index

Numbers written in italic refer to the page where the corresponding entry is described; numbers underlined refer to the code line of the definition; numbers in
roman refer to the code lines where the entry is used.
Symbols
\@@pdfspotcolordef@xspc
. . . . . . . . . 15, 21
A
\AddSpotColor . . . . .
\aftergroup . . . . . . .
\apptocmd . . . . . . 10,
autodefine
(package option)
. . . . . . . . 3, 5,
\autodefine@xspctrue

12
10
12

10
5

C
\color . . . . . . . . . . . 20
color (package) . . . . . 6
D
\DeclareOption . . 5, 6, 7
\definecolor . . . . . . 12
E
etoolbox (package) . . . 2
H
hks (package option) .
. . . . . . . 3, 10, 11
\hkstrue . . . . . . . . . . 6

I
\ifautodefine@xspc 4,
\ifhks . . . . . . . . . . .
\ifpantone . . . . . . .
\input . . . . . . . . . 29,

11
29
30
30

N
\newif . . . . . . . . . . . . 4

\pgfsys@color@spotcolor@fill
. . . . . . . . . 27, 28
\pgfsys@color@spotcolor@stroke
. . . . . . . . . 26, 28
\pgfsysprotocol@literal
. . . . . . . . . 26, 27
\ProcessOptions . . . . 9

O
\o@XC@definec@lor@xspc
. . . . . . . . . 16, 23

R
\RequirePackage . 1, 2, 3
\reset@color . . . . . . 10

P
package options:
autodefine . . 3, 5, 10
hks . . . . . . . 3, 10, 11
pantone . . . 3, 10, 11
packages:
color . . . . . . . . . . 6
etoolbox . . . . . . . 2
spotcolor . . 24, 6, 9
tikz . . . . . . . . . 2, 6
xcolor . . . . . . . 2, 6
xspotcolor . . . . 2, 3
pantone (package option)
. . . . . . . 3, 10, 11
\pantonetrue . . . . . . . 7
\pgfsys@color@spotcolor
. . . . . . . . . . . . 28

S
\SpotColor . . . . . . . 10
spotcolor (package) .
. . . . . . . 24, 6, 9

11

T
tikz (package) . . . .

2, 6

X
\XC@definec@lor . 16, 17
\XC@mod@spotcolor 14, 19
\XC@sdef . . . . . . . . . 14
xcolor (package) . . 2, 6
\xcolor@ . . . . . . . . . 21
xspotcolor (package)
. . . . . . . . . . . 2, 3

Potrebbero piacerti anche