summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/doc/metapost/mpcolornames/mpcolornames.tex
blob: 68fe0fe8f26ee0ed41370ec67ec2af92bc322c61 (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
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
%%% file mpcolornames.tex
%%% Copyright 2009, 2011 Stephan Hennig
%
% This work may be distributed and/or modified under the conditions of
% the LaTeX Project Public License, either version 1.3 of this license
% or (at your option) any later version.  The latest version of this
% license is in http://www.latex-project.org/lppl.txt
%
\RequirePackage{cmap}
\documentclass[DIV=9, captions=tableheading]{scrartcl}
\usepackage[T1]{fontenc}
\usepackage[charter]{mathdesign}
\usepackage{berasans}
\usepackage{textcomp}
\renewcommand*{\ttdefault}{fvs}
\setkomafont{disposition}{\normalfont\bfseries}
\usepackage{caption}
\captionsetup[table]{position=top}
\usepackage{amsmath}
% \usepackage{amssymb}
\usepackage[x11names]{xcolor}
\colorlet{framecol}{black!50}
\usepackage{listings}
\lstloadlanguages{MetaPost, [LaTeX]TeX}
\lstdefinelanguage[ext]{MetaPost}[]{MetaPost}{
  morekeywords={verbatimtex},
  morekeywords=[2]{blackpart, cmykcolor, colormodel, colorpart,
    cyanpart, greypart, magentapart, rgbcolor, yellowpart},
  morekeywords=[3]{withcmykcolor, withgreyscale, withoutcolor,
    withpostscript, withprescript, withrgbcolor},
  morekeywords=[5]{defaultcolormodel, mpprocset, outputformat,
    outputtemplate},
  morekeywords=[6]{mpversion},
%  morecomment=[s][basicstyle]{\%}{&},
  deletekeywords=[4]{z}
}
\colorlet{mpcolor}{RoyalBlue4}
\colorlet{latexcolor}{IndianRed4}
\colorlet{textcolor}{black}
\lstset{
  columns=fullflexible, breaklines=true, breakatwhitespace=true,
  escapechar=|,
  aboveskip=10pt, belowskip=10pt,
  frame=tb, framerule=2pt, framesep=6pt,
  framexleftmargin=10pt, framexrightmargin=10pt,
  xleftmargin=20pt, xrightmargin=20pt,
}
\lstdefinestyle{MP}{
  language=[ext]MetaPost,
  basicstyle=\normalfont\ttfamily,%\color{mpcolor},
  keywordstyle=\bfseries,
  commentstyle=\itshape,
  rulecolor=\color{mpcolor!40},
}
\lstdefinestyle{LaTeX}{
  language=[LaTeX]TeX,
  basicstyle=\normalfont\sffamily,%\color{latexcolor},
  keywordstyle={}, commentstyle=\itshape,
  rulecolor=\color{latexcolor!40},
}
\lstdefinestyle{text}{
  basicstyle=\normalfont\sffamily,%\color{textcolor},
  keywordstyle={}, commentstyle={},
  rulecolor=\color{textcolor!40},
}
\lstdefinestyle{textnof}{
  style=text,
  frame=none
}
\lstMakeShortInline[style=MP,
basicstyle=\normalfont\ttfamily\color{mpcolor}, keywordstyle={},
commentstyle={}]|

\usepackage{array}
\usepackage{booktabs}
\usepackage{longtable}
\usepackage{multicol}
\usepackage{graphicx}
\setcounter{topnumber}{2}
\setcounter{bottomnumber}{0}
\usepackage[USenglish]{babel}
\usepackage{hyperref}
\hypersetup{
  pdfstartview={XYZ null null null},% Zoom factor is determined by viewer.
  pdfpagemode=UseNone,
  colorlinks=true,
  linkcolor=DarkOrange2,
  urlcolor=Chocolate4,
  citecolor=DeepPink2
}

\newcommand*{\cmd}[1]{\texttt{#1}}
\newcommand*{\name}[1]{\textsf{\mdseries\emph{#1}}}
\newcommand*{\pkg}{\name{mpcolornames}}
\newcommand{\user}[1]{\emph{#1}}
\newcommand*{\macro}[1]{%
  \marginpar{%
    \hspace*{-\marginparsep}%
    \hspace*{-\textwidth}%
    \hspace*{-\marginparsep}%
    \hspace*{-\marginparwidth}%
    \makebox[\marginparwidth][r]{%
      \color{mpcolor}%
      \texttt{#1}%
    }%
  }%
}

\urlstyle{same}% See url.sty.
\newcommand*{\colorproof}[2][]{%
  \includegraphics{proof-spec-#1-#2.mps}%
  \hspace{5pt}%
  \nolinkurl{#2}%
}

\typearea{last}

\begin{document}
\title{The \pkg\ package\thanks{This document describes \pkg\ v0.20,
    last revised 2011/07/14.}}
\author{Stephan Hennig\thanks{stephanhennig@arcor.de}}
\maketitle

\begin{abstract}
  The MetaPost format \cmd{plain.mp} provides only five built-in color
  names (variables), all defined in the RGB model: |red|, |green| and
  |blue| for the primary colors and |black| and |white|
  (\autoref{tab:spec-plain-mp}).  The \pkg\ package makes more than 500
  color names from different color sets in different color models
  available to MetaPost.  Color sets include X11, SVG, DVIPS and
  \name{xcolor} specifications.
\end{abstract}

\setcounter{secnumdepth}{3}
\setcounter{tocdepth}{3}
\begin{multicols}{2}
\tableofcontents
\end{multicols}


\section{Color model constants}
\label{sec:color-model-constants}
Before discussing color names, lets have a look at some other constants
that are provided by the \pkg\ package.  MetaPost supports the CMYK and
grey scale color models since version~1.000.  At that time a new
internal variable |defaultcolormodel| was introduced, whose value
determines the color model of the black color used for drawing and
filling in absence of a |withcolor| statement---either explicit or via
|drawoptions|---and if the output format supports more than one color
model (cf. section~9 of the MetaPost manual).  Note, |defaultcolormodel|
never triggers a color model conversion.

Do you remember what value of variable |defaultcolormodel| corresponds
to the CMYK color model?  And do you remember what color model
corresponds to a value of~3?  Memoizing these numbers, which you need to
know only once in a while, isn't easy and in code they are less
descriptive than names.  For that reason, the \pkg\ package declares a
few internal variables with the values shown in
\autoref{tab:color-model-constants} that should help switching between
color models.

\begin{table}
  \centering
  \caption{Color model constants.}
  \label{tab:color-model-constants}
  \begin{tabular}{lc}
    internal variable & value\\
    \addlinespace\toprule\addlinespace
    |nomodel| & 1\\
    |greyscalemodel| & 3\\
    |rgbmodel| & 5\\
    |cmykmodel| & 7\\
  \end{tabular}
\end{table}


\section{Color sets}
\label{sec:colorsets}
This package provides color names from four color sets in three
different color models.  Color definitions are taken from X11
(\autoref{tab:spec-x11nam-def}), SVG (\autoref{tab:spec-svgnam-def}) and
DVIPS (\autoref{tab:spec-dvipsnam-def}) specifications as distributed by
packages \name{color} and \name{xcolor}.  Additionally, there is a small
set of colors that are defined by package \name{xcolor}
(\autoref{tab:spec-xcolor-sty}).  All color specifications have
automatically been translated into MetaPost code by scripts.

Colors defined in the X11 and SVG specifications are in the RGB color
space, i.e., the corresponding variables are of type |rgbcolor|.  Colors
defined in the DVIPS specification are in the CMYK color space, i.e.,
the corresponding variables are of type |cmykcolor|.  The set of colors
from the \name{xcolor} package are in the CMYK, RGB and grey scale color
model.  The corresponding variable identifiers have been augmented by a
prefix |cmyk_|, |rgb_| and |grey_| that indicates the color model used.
Variables are of type |cmykcolor|, |rgbcolor| and |numeric|, resp.

The package can be loaded by writing

\begin{lstlisting}[style=MP]
input mpcolornames
\end{lstlisting}
%
in the MetaPost source file.  After that, all color names defined in the
above mentioned color specifications are available as (array) variables.
This is possible, because the sets of color names defined in the color
specifications are nearly disjoint.  Only a few color names are defined
in more than one color specification.

Array variables can be indexed the usual way.  As long as the index is a
constant number, brackets can be omitted.  That way, color names, like
e.g., |VioletRed1| from X11 specification, can easily be used in
MetaPost.  If the index is a not a constant, brackets are mandatory.  As
an example, the color definitions of colors |VioletRed1| to |VioletRed4|
can be output like this

\lstinputlisting[style=MP, firstline=9]{expl-array-index.mp}
%
and the result would look like

\lstinputlisting[style=text, firstline=9]{expl-array-index.log}


\section{SVG and DVIPS color name clash}
\label{sec:nameclash}
There is a name clash between forty of the color names defined by the
SVG and DVIPS specifications.  The problem is that both specifications
define colors in different color models, RGB for the SVG specification
and CMYK for the DVIPS specification.  Additionally, the visual
impression of most colors with the same name varies quite drastically,
e.g., for the name |Lavender| (see \autoref{fig:clash-svg-dvips}).  The
set of clashing color names is listed in \autoref{tab:clash-svg-dvips}.
Here is how name clashes are handled by the \pkg\ package: When loading
the \pkg\ package, definitions of the SVG specification are processed
after those of the DVIPS specification and hence, for the clashing
names, definitions of the SVG specification ``win.''  Note, the variable
type of all clashing color names is therefore |rgbcolor|.

To control the active set of clashing color definitions two user macro
are provided: |svgnames|\macro{svgnames} and
|dvipsnames|\macro{dvipsnames}.  Calling any of both macros re-applies
all SVG or DVIPS color name declarations, overwriting all current
definitions of the respective set.  As an example, DVIPS definitions for
all clashing color names can be activated in the preamble by loading the
\pkg\ package as follows:

\begin{lstlisting}[style=MP]
input mpcolornames
dvipsnames;
\end{lstlisting}

One can switch back and forth between SVG and DVIPS definitions by
repeatedly calling macros |dvipsnames| and |svgnames| within one figure.
A better alternative, however, is to call these macros within a group,
since both macros save the set of clashing identifiers w.\,r.\,t. the
current group before setting the new definitions into effect.  As an
example, \autoref{fig:clash-svg-dvips} has been drawn with the following
code:

\lstinputlisting[style=MP, firstline=10]{fig-clash-svg-dvips.mp}

\begin{figure}
  \centering
  \includegraphics{fig-clash-svg-dvips-1.mps}
  \caption{Color \texttt{\color{mpcolor}Lavender} with DVIPS and SVG
    definitions within one figure.}
  \label{fig:clash-svg-dvips}
\end{figure}


\section{Related packages}
\label{sec:relatedpkg}
Package \name{mfpic} distributes a file \cmd{dvipsnam.mp} that contains
the same color definitions from the DVIPS specification that this
package provides.  For backwards compatibility, package \name{mfpic}
converts all colors into the RGB color model for MetaPost version that
don't support the CMYK color model.  Be careful when using both packages
in parallel!

\begin{flushleft}
  \itshape%
  Happy \TeX ing!\par
  Stephan Hennig
\end{flushleft}


\appendix
\section{Proof tables}
\label{sec:prooftables}
The following proof tables are sorted by color model.


\clearpage
% Enlarge width of typearea.
\areaset{1.2\textwidth}{\textheight}
\setlength{\columnsep}{3pt}

\subsection{Color names for multiple color models}
\label{sec:multinames}

%%% names from xcolor.sty
\newlength{\tabcolwidth}
\begingroup
\renewcommand*{\colorproof}[2][]{%
  \includegraphics{proof-spec-#1-rgb_#2.mps}%
  \hspace{5pt}%
  \nolinkurl{rgb_#2}%
  & \includegraphics{proof-spec-#1-cmyk_#2.mps}%
  \hspace{5pt}%
  \nolinkurl{cmyk_#2}%
  & \includegraphics{proof-spec-#1-grey_#2.mps}%
  \hspace{5pt}%
  \nolinkurl{grey_#2}%
}
\input{tab-spec-xcolor-sty}
\endgroup

\clearpage
\subsection{RGB color names}
\label{sec:rgbnames}

%%% names from plain.mp
\input{tab-spec-plain-mp}

%%% names from x11nam.def
\input{tab-spec-x11nam-def}

%%% names from svgnam.def
\input{tab-spec-svgnam-def}

\clearpage
\subsection{CMYK color names}
\label{sec:cmyknames}

%%% names from dvipsnam.def
\input{tab-spec-dvipsnam-def}


\clearpage
\section{Color name clashes}
\label{sec:nameclashes}

% svgnam.def and dvipsnam.def name clash
\begingroup
\renewcommand*{\colorproof}[2][]{%
  \includegraphics{proof-spec-svgnam-def-#2.mps}%
  \includegraphics{proof-spec-dvipsnam-def-#2.mps}%
  \hspace{5pt}%
  \nolinkurl{#2}%
}
\input{tab-clash-svg-dvips}
\endgroup

\end{document}

%%% Local Variables: 
%%% mode: latex
%%% TeX-PDF-mode: t
%%% TeX-master: t
%%% End: