Debian Codegraph @

texmf-dist/doc/metapost/mpcolornames/mpcolornames.tex

raw
1 %%% file mpcolornames.tex
2 %%% Copyright 2009, 2011 Stephan Hennig
3 %
4 % This work may be distributed and/or modified under the conditions of
5 % the LaTeX Project Public License, either version 1.3 of this license
6 % or (at your option) any later version. The latest version of this
7 % license is in http://www.latex-project.org/lppl.txt
8 %
9 \RequirePackage{cmap}
10 \documentclass[DIV=9, captions=tableheading]{scrartcl}
11 \usepackage[T1]{fontenc}
12 \usepackage[charter]{mathdesign}
13 \usepackage{berasans}
14 \usepackage{textcomp}
15 \renewcommand*{\ttdefault}{fvs}
16 \setkomafont{disposition}{\normalfont\bfseries}
17 \usepackage{caption}
18 \captionsetup[table]{position=top}
19 \usepackage{amsmath}
20 % \usepackage{amssymb}
21 \usepackage[x11names]{xcolor}
22 \colorlet{framecol}{black!50}
23 \usepackage{listings}
24 \lstloadlanguages{MetaPost, [LaTeX]TeX}
25 \lstdefinelanguage[ext]{MetaPost}[]{MetaPost}{
26 morekeywords={verbatimtex},
27 morekeywords=[2]{blackpart, cmykcolor, colormodel, colorpart,
28 cyanpart, greypart, magentapart, rgbcolor, yellowpart},
29 morekeywords=[3]{withcmykcolor, withgreyscale, withoutcolor,
30 withpostscript, withprescript, withrgbcolor},
31 morekeywords=[5]{defaultcolormodel, mpprocset, outputformat,
32 outputtemplate},
33 morekeywords=[6]{mpversion},
34 % morecomment=[s][basicstyle]{\%}{&},
35 deletekeywords=[4]{z}
36 }
37 \colorlet{mpcolor}{RoyalBlue4}
38 \colorlet{latexcolor}{IndianRed4}
39 \colorlet{textcolor}{black}
40 \lstset{
41 columns=fullflexible, breaklines=true, breakatwhitespace=true,
42 escapechar=|,
43 aboveskip=10pt, belowskip=10pt,
44 frame=tb, framerule=2pt, framesep=6pt,
45 framexleftmargin=10pt, framexrightmargin=10pt,
46 xleftmargin=20pt, xrightmargin=20pt,
47 }
48 \lstdefinestyle{MP}{
49 language=[ext]MetaPost,
50 basicstyle=\normalfont\ttfamily,%\color{mpcolor},
51 keywordstyle=\bfseries,
52 commentstyle=\itshape,
53 rulecolor=\color{mpcolor!40},
54 }
55 \lstdefinestyle{LaTeX}{
56 language=[LaTeX]TeX,
57 basicstyle=\normalfont\sffamily,%\color{latexcolor},
58 keywordstyle={}, commentstyle=\itshape,
59 rulecolor=\color{latexcolor!40},
60 }
61 \lstdefinestyle{text}{
62 basicstyle=\normalfont\sffamily,%\color{textcolor},
63 keywordstyle={}, commentstyle={},
64 rulecolor=\color{textcolor!40},
65 }
66 \lstdefinestyle{textnof}{
67 style=text,
68 frame=none
69 }
70 \lstMakeShortInline[style=MP,
71 basicstyle=\normalfont\ttfamily\color{mpcolor}, keywordstyle={},
72 commentstyle={}]|
73
74 \usepackage{array}
75 \usepackage{booktabs}
76 \usepackage{longtable}
77 \usepackage{multicol}
78 \usepackage{graphicx}
79 \setcounter{topnumber}{2}
80 \setcounter{bottomnumber}{0}
81 \usepackage[USenglish]{babel}
82 \usepackage{hyperref}
83 \hypersetup{
84 pdfstartview={XYZ null null null},% Zoom factor is determined by viewer.
85 pdfpagemode=UseNone,
86 colorlinks=true,
87 linkcolor=DarkOrange2,
88 urlcolor=Chocolate4,
89 citecolor=DeepPink2
90 }
91
92 \newcommand*{\cmd}[1]{\texttt{#1}}
93 \newcommand*{\name}[1]{\textsf{\mdseries\emph{#1}}}
94 \newcommand*{\pkg}{\name{mpcolornames}}
95 \newcommand{\user}[1]{\emph{#1}}
96 \newcommand*{\macro}[1]{%
97 \marginpar{%
98 \hspace*{-\marginparsep}%
99 \hspace*{-\textwidth}%
100 \hspace*{-\marginparsep}%
101 \hspace*{-\marginparwidth}%
102 \makebox[\marginparwidth][r]{%
103 \color{mpcolor}%
104 \texttt{#1}%
105 }%
106 }%
107 }
108
109 \urlstyle{same}% See url.sty.
110 \newcommand*{\colorproof}[2][]{%
111 \includegraphics{proof-spec-#1-#2.mps}%
112 \hspace{5pt}%
113 \nolinkurl{#2}%
114 }
115
116 \typearea{last}
117
118 \begin{document}
119 \title{The \pkg\ package\thanks{This document describes \pkg\ v0.20,
120 last revised 2011/07/14.}}
121 \author{Stephan Hennig\thanks{[email protected]}}
122 \maketitle
123
124 \begin{abstract}
125 The MetaPost format \cmd{plain.mp} provides only five built-in color
126 names (variables), all defined in the RGB model: |red|, |green| and
127 |blue| for the primary colors and |black| and |white|
128 (\autoref{tab:spec-plain-mp}). The \pkg\ package makes more than 500
129 color names from different color sets in different color models
130 available to MetaPost. Color sets include X11, SVG, DVIPS and
131 \name{xcolor} specifications.
132 \end{abstract}
133
134 \setcounter{secnumdepth}{3}
135 \setcounter{tocdepth}{3}
136 \begin{multicols}{2}
137 \tableofcontents
138 \end{multicols}
139
140
141 \section{Color model constants}
142 \label{sec:color-model-constants}
143 Before discussing color names, lets have a look at some other constants
144 that are provided by the \pkg\ package. MetaPost supports the CMYK and
145 grey scale color models since version~1.000. At that time a new
146 internal variable |defaultcolormodel| was introduced, whose value
147 determines the color model of the black color used for drawing and
148 filling in absence of a |withcolor| statement---either explicit or via
149 |drawoptions|---and if the output format supports more than one color
150 model (cf. section~9 of the MetaPost manual). Note, |defaultcolormodel|
151 never triggers a color model conversion.
152
153 Do you remember what value of variable |defaultcolormodel| corresponds
154 to the CMYK color model? And do you remember what color model
155 corresponds to a value of~3? Memoizing these numbers, which you need to
156 know only once in a while, isn't easy and in code they are less
157 descriptive than names. For that reason, the \pkg\ package declares a
158 few internal variables with the values shown in
159 \autoref{tab:color-model-constants} that should help switching between
160 color models.
161
162 \begin{table}
163 \centering
164 \caption{Color model constants.}
165 \label{tab:color-model-constants}
166 \begin{tabular}{lc}
167 internal variable & value\\
168 \addlinespace\toprule\addlinespace
169 |nomodel| & 1\\
170 |greyscalemodel| & 3\\
171 |rgbmodel| & 5\\
172 |cmykmodel| & 7\\
173 \end{tabular}
174 \end{table}
175
176
177 \section{Color sets}
178 \label{sec:colorsets}
179 This package provides color names from four color sets in three
180 different color models. Color definitions are taken from X11
181 (\autoref{tab:spec-x11nam-def}), SVG (\autoref{tab:spec-svgnam-def}) and
182 DVIPS (\autoref{tab:spec-dvipsnam-def}) specifications as distributed by
183 packages \name{color} and \name{xcolor}. Additionally, there is a small
184 set of colors that are defined by package \name{xcolor}
185 (\autoref{tab:spec-xcolor-sty}). All color specifications have
186 automatically been translated into MetaPost code by scripts.
187
188 Colors defined in the X11 and SVG specifications are in the RGB color
189 space, i.e., the corresponding variables are of type |rgbcolor|. Colors
190 defined in the DVIPS specification are in the CMYK color space, i.e.,
191 the corresponding variables are of type |cmykcolor|. The set of colors
192 from the \name{xcolor} package are in the CMYK, RGB and grey scale color
193 model. The corresponding variable identifiers have been augmented by a
194 prefix |cmyk_|, |rgb_| and |grey_| that indicates the color model used.
195 Variables are of type |cmykcolor|, |rgbcolor| and |numeric|, resp.
196
197 The package can be loaded by writing
198
199 \begin{lstlisting}[style=MP]
200 input mpcolornames
201 \end{lstlisting}
202 %
203 in the MetaPost source file. After that, all color names defined in the
204 above mentioned color specifications are available as (array) variables.
205 This is possible, because the sets of color names defined in the color
206 specifications are nearly disjoint. Only a few color names are defined
207 in more than one color specification.
208
209 Array variables can be indexed the usual way. As long as the index is a
210 constant number, brackets can be omitted. That way, color names, like
211 e.g., |VioletRed1| from X11 specification, can easily be used in
212 MetaPost. If the index is a not a constant, brackets are mandatory. As
213 an example, the color definitions of colors |VioletRed1| to |VioletRed4|
214 can be output like this
215
216 \lstinputlisting[style=MP, firstline=9]{expl-array-index.mp}
217 %
218 and the result would look like
219
220 \lstinputlisting[style=text, firstline=9]{expl-array-index.log}
221
222
223 \section{SVG and DVIPS color name clash}
224 \label{sec:nameclash}
225 There is a name clash between forty of the color names defined by the
226 SVG and DVIPS specifications. The problem is that both specifications
227 define colors in different color models, RGB for the SVG specification
228 and CMYK for the DVIPS specification. Additionally, the visual
229 impression of most colors with the same name varies quite drastically,
230 e.g., for the name |Lavender| (see \autoref{fig:clash-svg-dvips}). The
231 set of clashing color names is listed in \autoref{tab:clash-svg-dvips}.
232 Here is how name clashes are handled by the \pkg\ package: When loading
233 the \pkg\ package, definitions of the SVG specification are processed
234 after those of the DVIPS specification and hence, for the clashing
235 names, definitions of the SVG specification ``win.'' Note, the variable
236 type of all clashing color names is therefore |rgbcolor|.
237
238 To control the active set of clashing color definitions two user macro
239 are provided: |svgnames|\macro{svgnames} and
240 |dvipsnames|\macro{dvipsnames}. Calling any of both macros re-applies
241 all SVG or DVIPS color name declarations, overwriting all current
242 definitions of the respective set. As an example, DVIPS definitions for
243 all clashing color names can be activated in the preamble by loading the
244 \pkg\ package as follows:
245
246 \begin{lstlisting}[style=MP]
247 input mpcolornames
248 dvipsnames;
249 \end{lstlisting}
250
251 One can switch back and forth between SVG and DVIPS definitions by
252 repeatedly calling macros |dvipsnames| and |svgnames| within one figure.
253 A better alternative, however, is to call these macros within a group,
254 since both macros save the set of clashing identifiers w.\,r.\,t. the
255 current group before setting the new definitions into effect. As an
256 example, \autoref{fig:clash-svg-dvips} has been drawn with the following
257 code:
258
259 \lstinputlisting[style=MP, firstline=10]{fig-clash-svg-dvips.mp}
260
261 \begin{figure}
262 \centering
263 \includegraphics{fig-clash-svg-dvips-1.mps}
264 \caption{Color \texttt{\color{mpcolor}Lavender} with DVIPS and SVG
265 definitions within one figure.}
266 \label{fig:clash-svg-dvips}
267 \end{figure}
268
269
270 \section{Related packages}
271 \label{sec:relatedpkg}
272 Package \name{mfpic} distributes a file \cmd{dvipsnam.mp} that contains
273 the same color definitions from the DVIPS specification that this
274 package provides. For backwards compatibility, package \name{mfpic}
275 converts all colors into the RGB color model for MetaPost version that
276 don't support the CMYK color model. Be careful when using both packages
277 in parallel!
278
279 \begin{flushleft}
280 \itshape%
281 Happy \TeX ing!\par
282 Stephan Hennig
283 \end{flushleft}
284
285
286 \appendix
287 \section{Proof tables}
288 \label{sec:prooftables}
289 The following proof tables are sorted by color model.
290
291
292 \clearpage
293 % Enlarge width of typearea.
294 \areaset{1.2\textwidth}{\textheight}
295 \setlength{\columnsep}{3pt}
296
297 \subsection{Color names for multiple color models}
298 \label{sec:multinames}
299
300 %%% names from xcolor.sty
301 \newlength{\tabcolwidth}
302 \begingroup
303 \renewcommand*{\colorproof}[2][]{%
304 \includegraphics{proof-spec-#1-rgb_#2.mps}%
305 \hspace{5pt}%
306 \nolinkurl{rgb_#2}%
307 & \includegraphics{proof-spec-#1-cmyk_#2.mps}%
308 \hspace{5pt}%
309 \nolinkurl{cmyk_#2}%
310 & \includegraphics{proof-spec-#1-grey_#2.mps}%
311 \hspace{5pt}%
312 \nolinkurl{grey_#2}%
313 }
314 \input{tab-spec-xcolor-sty}
315 \endgroup
316
317 \clearpage
318 \subsection{RGB color names}
319 \label{sec:rgbnames}
320
321 %%% names from plain.mp
322 \input{tab-spec-plain-mp}
323
324 %%% names from x11nam.def
325 \input{tab-spec-x11nam-def}
326
327 %%% names from svgnam.def
328 \input{tab-spec-svgnam-def}
329
330 \clearpage
331 \subsection{CMYK color names}
332 \label{sec:cmyknames}
333
334 %%% names from dvipsnam.def
335 \input{tab-spec-dvipsnam-def}
336
337
338 \clearpage
339 \section{Color name clashes}
340 \label{sec:nameclashes}
341
342 % svgnam.def and dvipsnam.def name clash
343 \begingroup
344 \renewcommand*{\colorproof}[2][]{%
345 \includegraphics{proof-spec-svgnam-def-#2.mps}%
346 \includegraphics{proof-spec-dvipsnam-def-#2.mps}%
347 \hspace{5pt}%
348 \nolinkurl{#2}%
349 }
350 \input{tab-clash-svg-dvips}
351 \endgroup
352
353 \end{document}
354
355 %%% Local Variables:
356 %%% mode: latex
357 %%% TeX-PDF-mode: t
358 %%% TeX-master: t
359 %%% End: