Debian Codegraph @

texmf-dist/doc/latex/colorblind/colorblind_doc.tex

raw
1 %%
2 %% ----------------------------------------------------------------
3 %% Copyright (C) 2023-2026 by Simon Pfahler <simon.pfahler at ur dot de>
4 %% ----------------------------------------------------------------
5 %%
6 %! TeX program = lualatex
7 \DocumentMetadata{lang = en-us}
8 \documentclass{scrartcl}
9 \usepackage[left=4.5cm,right=3cm,top=3cm,bottom=3cm, marginpar=4cm]{geometry}
10 \setlength{\parindent}{0pt}
11 \setlength{\parskip}{1ex}
12
13 \usepackage{xcolor}
14 \usepackage{soul}
15
16 \usepackage{tikz}
17 \usetikzlibrary{positioning, shapes, fit, arrows.meta, decorations.pathmorphing, math}
18 \pgfdeclarelayer{bg}
19 \pgfsetlayers{bg,main}
20
21 \usepackage{pgfplots, pgfplotstable}
22 \pgfplotsset{compat=1.18}
23
24 %%%% from https://tex.stackexchange.com/questions/355713/pgfplots-show-error-marker-in-legend
25 \pgfplotsset{error bar legend/.style={%
26 /pgfplots/legend image code/.prefix code={%
27 \pgfkeysgetvalue{/pgfplots/error bars/error mark}{\pgfplotserrorbarsmark}%
28 \draw[%
29 /pgfplots/every error bar,
30 mark=\pgfplotserrorbarsmark,
31 /pgfplots/error bars/error mark options,
32 sharp plot,
33 ##1
34 ] plot coordinates {(0.3cm, -0.15cm) (0.3cm, 0.15cm)};%
35 }
36 }
37 }
38 %%%%
39
40 \pgfplotsset{custom area legend/.style={%
41 /pgfplots/legend image code/.prefix code={%
42 \fill[##1, draw=white] plot coordinates {(0cm, -0.1cm) (0.6cm,-0.1cm) (0.6cm, 0.1cm) (0cm, 0.1cm)};%
43 }
44 }
45 }
46
47 \def\w{420pt}
48
49 \usepackage{hyperref}
50 \hypersetup{
51 pdftitle={Easy colorblind-safe typesetting: the colorblind package},
52 pdfauthor={Simon Pfahler},
53 }
54 \usepackage{cleveref}
55
56 \usepackage{csquotes}
57 \usepackage[backend=biber, style=numeric-comp, seconds=true, sorting=none, subentry=true, doi=false, alldates=iso]{biblatex}
58 \renewcommand*{\entrysetpunct}{\\[5pt]}
59 \addbibresource{bib.bib}
60
61 \usepackage[keep-defaults, Tol, OkabeIto, pgf]{colorblind}
62
63 \newcommand\colorblind{\textbf{colorblind} }
64 \newcommand\hlc[2][T-Q-PH4]{{%
65 \colorlet{foo}{#1}%
66 \sethlcolor{foo}\hl{#2}}%
67 }
68
69 \reversemarginpar
70 \newcommand\marg[1]{\leavevmode\marginpar{\raggedleft #1}}
71 \newcommand\tbs{\textbackslash}
72 \newcommand\cs[1]{\texttt{\tbs#1}}
73
74 \title{Easy colorblind-safe typesetting:\\ the \colorblind package}
75 \author{Simon Pfahler}
76 \date{\today\\Version 1.2.1}
77
78
79 \begin{document}
80
81 \maketitle
82
83 \begin{abstract}
84 In colorblind-safe documents, the contents are presented in a way that the same information is conveyed to readers regardless of a potential color vision deficiency.
85 This package provides some useful tools for colorblind-safe typesetting in \LaTeX.
86 It provides color schemes for a wide range of applications.
87 The most commonly used schemes are qualitative schemes, providing easily distinguishable colors for use in graphics, but also for text coloring or highlighting.
88 Additionally, diverging and sequential schemes are provided, which can be used for encoding quantitative information using colors.
89 This package incorporates colorblind-safeness into the writing process, making it both less cumbersome and less error-prone.
90 \end{abstract}
91
92 \tableofcontents
93 \clearpage
94
95 \section{Introduction}
96 \subsection{For the impatient}
97 Writing good colorblind-safe documents can be a tricky task.
98 It is a good starting point to realize that the default \LaTeX\ colors like \hlc[red]{red} or \hlc[blue]{blue} should be avoided.
99 This is why for the impatient, simply loading this package without specifying any options (i.e.\ \cs{usepackage\{colorblind\}}) redefines the default colors to more sensible alternatives.
100 \footnote{Where no suitable redefinition was possible for a builtin named color, the definition is changed to black.}
101
102 \begin{figure}[ht]
103 \centering
104 \begin{tikzpicture}
105 \node[inner sep=1, fill=red] at (-1.2*0.7cm,2.3*0.7cm) {R};
106 \node[inner sep=1, fill=green] at (-1.2*0.7cm, 1.8*0.7cm) {G};
107 \node[inner sep=1, fill=blue] at (-1.2*0.7cm,1.3*0.7cm) {B};
108
109 \node at (1*1cm-1cm,2.3*0.7cm) {68};
110 \node at (1*1cm-1cm,1.8*0.7cm) {119};
111 \node at (1*1cm-1cm,1.3*0.7cm) {170};
112 \draw[fill=T-Q-B1] (1*1cm-1cm,0) circle (0.7cm);
113 \node[rotate=25, anchor=north east] at (1*1cm-1cm,-1*0.7cm) {\vphantom{bp}blue};
114
115 \node at (2*1cm-1cm,2.3*0.7cm) {102};
116 \node at (2*1cm-1cm,1.8*0.7cm) {204};
117 \node at (2*1cm-1cm,1.3*0.7cm) {238};
118 \draw[fill=T-Q-B2] (2*1cm-1cm,0) circle (0.7cm);
119 \node[rotate=25, anchor=north east] at (2*1cm-1cm,-1*0.7cm) {\vphantom{bp}cyan};
120
121 \node at (3*1cm-1cm,2.3*0.7cm) {34};
122 \node at (3*1cm-1cm,1.8*0.7cm) {136};
123 \node at (3*1cm-1cm,1.3*0.7cm) {51};
124 \draw[fill=T-Q-B3] (3*1cm-1cm,0) circle (0.7cm);
125 \node[rotate=25, anchor=north east] at (3*1cm-1cm,-1*0.7cm) {\vphantom{bp}green};
126
127 \node at (4*1cm-1cm,2.3*0.7cm) {204};
128 \node at (4*1cm-1cm,1.8*0.7cm) {187};
129 \node at (4*1cm-1cm,1.3*0.7cm) {68};
130 \draw[fill=T-Q-B4] (4*1cm-1cm,0) circle (0.7cm);
131 \node[rotate=25, anchor=north east] at (4*1cm-1cm,-1*0.7cm) {\vphantom{bp}yellow};
132
133 \node at (5*1cm-1cm,2.3*0.7cm) {238};
134 \node at (5*1cm-1cm,1.8*0.7cm) {102};
135 \node at (5*1cm-1cm,1.3*0.7cm) {119};
136 \draw[fill=T-Q-B5] (5*1cm-1cm,0) circle (0.7cm);
137 \node[rotate=25, anchor=north east] at (5*1cm-1cm,-1*0.7cm) {\vphantom{bp}red};
138
139 \node at (6*1cm-1cm,2.3*0.7cm) {170};
140 \node at (6*1cm-1cm,1.8*0.7cm) {51};
141 \node at (6*1cm-1cm,1.3*0.7cm) {119};
142 \draw[fill=T-Q-B6] (6*1cm-1cm,0) circle (0.7cm);
143 \node[rotate=25, anchor=north east] at (6*1cm-1cm,-1*0.7cm) {\vphantom{bp}violet};
144
145 \node at (7*1cm-1cm,2.3*0.7cm) {187};
146 \node at (7*1cm-1cm,1.8*0.7cm) {187};
147 \node at (7*1cm-1cm,1.3*0.7cm) {187};
148 \draw[fill=T-Q-B0] (7*1cm-1cm,0) circle (0.7cm);
149 \node[rotate=25, anchor=north east] at (7*1cm-1cm,-1*0.7cm) {\vphantom{bp}gray};
150
151 \end{tikzpicture}
152 \caption{Redefinitions of the default \LaTeX\ colors.}
153 \end{figure}
154
155 It should be noted that this is a very brute-force way of trying to achieve colorblind-safeness.
156 If you care about this topic (which you should), the rest of this document provides details on how colorblind-safeness is best achieved in different scenarios.
157
158 \subsection{Package options}
159 \marg{\texttt{Tol}\\\texttt{OkabeIto}}%
160 The \colorblind package provides the color schemes by Paul Tol~\cite{Tol} and the Okabe Ito color palette~\cite{Okabe_2002}.
161 By default, no schemes are loaded.
162 Providing one of the options \texttt{Tol} or \texttt{OkabeIto} loads all corresponding schemes.
163
164 \marg{\texttt{pgf}}%
165 If the option \texttt{pgf} is provided, continuous colormaps are defined for use with \texttt{pgfplots} (or \texttt{TikZ}).
166 Also, the command \cs{drawSchemeC} for drawing continuous color schemes is only defined when the option is provided and continuous color schemes are available (through providing the \texttt{Tol} option).
167 Continuous versions of color schemes are only available when the colors are allowed to be interpolated, see below for details.
168
169 \marg{\texttt{no-tikz}}%
170 The package uses \texttt{TikZ} to draw the discrete versions of color schemes.
171 Providing the option \texttt{no-tikz} disables this, the command \cs{drawScheme} is not defined in this case.
172
173 \marg{\texttt{keep-defaults}}%
174 The package redefines the default colors like \hlc[T-Q-PH5]{red} or \hlc[T-Q-PH1]{blue} to be colorblind-safe. By specifying this option, the defaults are not changed.
175
176 \subsection{Overview}
177 As an example for how to use the colors, we look at the \emph{bright qualitative} color scheme by Tol.
178 \cref{fig:T-Q-Bexample} shows the colors in the scheme.
179
180 \begin{figure}[ht]
181 \centering
182 \drawScheme{T-Q-B}
183 \caption{Bright qualitative color scheme by Tol.}
184 \label{fig:T-Q-Bexample}
185 \end{figure}
186
187 All colors in this model start with \texttt{T-Q-B}, indicating that it is a scheme by \textbf{T}ol, that it is a \textbf{q}ualitative scheme, and that it is the \textbf{b}right scheme.
188 The colors in the scheme are specified by a number following the scheme name, in this case ranging from \texttt{T-Q-B1} to \texttt{T-Q-B6} for the non-grey colors.
189 The additional color \texttt{T-Q-B0} provides a color that can be used, e.g., to indicate bad data.
190
191 There are two reasons why color names are not based on natural color names (e.g., ``\hlc[T-Q-PH1]{blue}''):
192 \begin{enumerate}
193 \item Certain colors (\hlc[T-Q-PH3]{green}, \hlc[T-Q-PH5]{red}) are often used by people with full color vision to convey certain meanings (\hlc[T-Q-PH3]{good}, \hlc[T-Q-PH5]{bad}).
194 This meaning is difficult for people with color vision deficiencies to pick up.
195 By not using natural color names, it is easier to write colorblind-safe documents that do not make use of said connotations.
196 \item Natural color names can be cumbersome, e.g., when slight variations of a color are used. It is annoying having to look up if a color is called, e.g., \hlc[T-Q-PH1]{blue} or \hlc[T-Q-PH2]{cyan}.
197 \end{enumerate}
198
199 These colors are used the same way as any other colors. To change the text color to \texttt{T-Q-B1} for example, use \cs{color\{T-Q-B1\}}.
200
201 \section{Guidelines}\label{sec:guidelines}
202 In this section, we provide some general guidelines for colorblind-safe design.
203
204 Color vision deficiencies apper in many different variations and grades of severity, up to monochromacy, where different colors can only be distinguished via their perceived brightness.
205 This means that while the color schemes provided by this package are easier to distinguish for the most common color vision deficiencies, information encoded only in color can never be truely colorblind safe.
206 This leads us to the most important rule in colorblind-safe design:
207 \begin{center}
208 \setlength{\fboxrule}{1pt}
209 \textbf{Rule 1}:
210 \fbox{\parbox{0.65\columnwidth}{
211 Always provide information in more ways than just color.
212 }}
213 \end{center}
214
215 If this rule is satisfied in a document, it is by construction guaranteed to be colorblind-safe.
216 However, this does not mean that it is \emph{convenient} for people with color vision deficiencies to extract the information.
217 In order to achieve the best possible result, a few more rules should be considered when using color.
218 \begin{center}
219 \setlength{\fboxrule}{1pt}
220 \textbf{Rule 2}:
221 \fbox{\parbox{0.65\columnwidth}{
222 Stick to a color scheme.
223 \begin{itemize}
224 \item[(\textbf{a})] Do not mix colors within a scheme.
225 \item[(\textbf{b})] Do not use shades of colors.
226 \end{itemize}
227 }}
228 \end{center}
229
230 Colors within colorblind-safe color schemes are designed to be eaily distinguishable for people with the most common color vision deficiencies, so we should only use colors from one color scheme in any given visual unit.
231 In extension, even colors from the same scheme should not be mixed, since this makes it harder to distinguish them.
232 Even if the result of the mixing is easily distinguishable for people with normal color vision, the same might not be true under certain color vision deficiencies.
233 For the same reaseon, shades of colors (i.e.\ mixings with black or white) should be avoided, because the brightness of colors is also used to make sure the colors are distinguishable.
234
235 \begin{center}
236 \setlength{\fboxrule}{1pt}
237 \textbf{Rule 3}:
238 \fbox{\parbox{0.65\columnwidth}{
239 Do not use color for information and aesthetics simultaneously.
240 }}
241 \end{center}
242
243 Color is often also used for aesthetic reasons, e.g., on a scientific poster.
244 This is usually unproblematic, as the color does not convey information in this case.
245 However, if color is used to convey information in a visual unit, avoid using additional color for aesthetic purposes, as this makes it more difficult to extract the information encoded in the color.
246
247 \begin{center}
248 \setlength{\fboxrule}{1pt}
249 \textbf{Rule 4}:
250 \fbox{\parbox{0.65\columnwidth}{
251 Do not use rainbow color schemes.
252 }}
253 \end{center}
254
255 Due to the many different colors in a rainbow color scheme, they are inevitably difficult to distinguish for people with color vision deficiencies.
256 Therefore, it is best to avoid them.
257 If a rainbow color scheme has to be used at all cost, Paul Tol (and thus also the \texttt{colorblind} package) provides both a discrete as well as a continuous version~\cite{Tol}, which are optimized to be as distinguishable as possible.
258
259 By following these four simple rules, we can ensure that the information encoded in a document is presented in a colorblind-safe way, and that it is reasonably convenient for people affected by color vision deficiencies to extract the information.
260 As a side node, following these rules leads to documents that do not suffer from information loss when printed in black and white, which is usually also desirable.
261
262 \section{Provided color schemes}\label{sec:colors}
263 The color schemes provided are split into three groups:
264 \begin{itemize}
265 \item Qualitative schemes:\newline
266 These schemes are used to convey qualitative information, such as different data sources, countries or manufacturers.
267 They should usually be used for coloring text or distinguishing different lines/bars in a plot.
268 \item Diverging color schemes:\newline
269 When quantitative data ranges between two extremes, and the middle is being considered ``neutral'', a diverging color scheme should be used.
270 Examples for this kind of data might be test grades, temperatures or pH values.
271 \item Sequential color schemes:\newline
272 For quantitative data without an important midpoint, sequential color schemes should be preferred over diverging ones.
273 This is especially true for quantites that start from $0$.
274 They can be used to denote for example velocities, concentrations or pressures.
275 \end{itemize}
276
277 For each type of schemes, this package provides a range of options.
278 \Cref{sec:Tol_schemes} shows the schemes designed by Paul Tol~\cite{Tol}, which include qualitative, diverging and sequential schemes (see \cref{sec:T-Q,sec:T-D,sec:T-S}).
279 For some of the qualitative schemes, an order in which the colors should be used when not all of them are needed is provided in~\cite{Tol}.
280 In \cref{sec:OkabeIto}, the Okabe Ito color scheme~\cite{Okabe_2002} is provided, which is probably the most famous qualitative colorblind-safe color scheme due to it being mentioned in various articles in high-ranking journals.
281
282 All of the schemes are colorblind-safe, and some are optimized for printout or designed for a particular purpose.
283 This is denoted under the scheme name.\clearpage
284
285 \subsection{Paul Tol's color schemes}\label{sec:Tol_schemes}
286
287 \subsubsection{Qualitative color schemes}\label{sec:T-Q}
288 \begin{minipage}{0.5\textwidth}
289 \centering
290 \scalebox{0.7}{\drawScheme{T-Q-B}}\\
291 \textbf{B}right\\
292 \phantom{pb}
293 \end{minipage}\hfill%
294 \begin{minipage}{0.5\textwidth}
295 \centering
296 \scalebox{0.7}{\drawScheme{T-Q-V}}\\
297 \textbf{V}ibrant
298 \end{minipage}
299
300 \begin{minipage}{0.5\textwidth}
301 \centering
302 \scalebox{0.7}{\drawScheme{T-Q-HC}}\\
303 \textbf{H}igh-\textbf{C}ontrast\\
304 works for black and white printout
305 \end{minipage}\hfill%
306 \begin{minipage}{0.5\textwidth}
307 \centering
308 \scalebox{0.7}{\drawScheme{T-Q-MC}}\\
309 \textbf{M}edium-\textbf{C}ontrast\\
310 works for black and white printout
311 \end{minipage}
312
313 \begin{center}
314 \scalebox{0.7}{\drawScheme{T-Q-M}}\\
315 \textbf{M}uted
316 \end{center}
317
318 \begin{minipage}{0.5\textwidth}
319 \centering
320 \scalebox{0.7}{\drawScheme{T-Q-PH}}\\
321 \textbf{P}ale \textbf{H}ighlight\\
322 specifically for text background
323 \end{minipage}\hfill%
324 \begin{minipage}{0.5\textwidth}
325 \centering
326 \scalebox{0.7}{\drawScheme{T-Q-DT}}\\
327 \textbf{D}ark \textbf{T}ext\\
328 specifically for text color
329 \end{minipage}
330
331 \begin{center}
332 \scalebox{0.7}{\drawScheme{T-Q-L}}\\
333 \textbf{L}ight\\
334 less distinguishable than other schemes,\\ mostly meant for filling in labelled cells
335 \end{center}\clearpage
336
337 \subsubsection{Diverging color schemes}\label{sec:T-D}
338 For diverging schemes, when a continuous scheme is needed, the colors are allowed to be linearly interpolated.
339 When using the option \texttt{pgf}, the interpolations are available as colormaps with the names of their color scheme.
340
341 \begin{center}
342 \scalebox{0.7}{\drawScheme{T-D-S}}\\
343 \drawSchemeC[0.6\textwidth]{T-D-S}\\
344 \textbf{S}unset
345 \end{center}
346
347 \begin{center}
348 \scalebox{0.7}{\drawScheme{T-D-N}}\\
349 \drawSchemeC[0.9\textwidth]{T-D-N}\\
350 \textbf{N}ightfall
351 \end{center}
352
353 \begin{center}
354 \scalebox{0.7}{\drawScheme{T-D-BR}}\\
355 \drawSchemeC[0.5\textwidth]{T-D-BR}\\
356 \textbf{B}u\textbf{R}d
357 \end{center}
358
359 \begin{center}
360 \scalebox{0.7}{\drawScheme{T-D-PG}}\\
361 \drawSchemeC[0.5\textwidth]{T-D-PG}\\
362 \textbf{P}R\textbf{G}n
363 \end{center}\clearpage
364
365 \subsubsection{Sequential color schemes}\label{sec:T-S}
366 For most sequential schemes, a continuous scheme can be obtained again by linearly interpolating the colors.
367 The only exception to this is the \emph{discrete rainbow} scheme, which has an explicitly continuos variation, the \emph{smooth rainbow} scheme.
368 When using the option \texttt{pgf}, the interpolations are available as colormaps with the names of their color scheme.
369
370 When the discrete scheme is not shown, this is because there are too many colors in it.
371
372 \begin{center}
373 \scalebox{0.7}{\drawScheme{T-S-YOB}}\\
374 \drawSchemeC[0.5\textwidth]{T-S-YOB}\\
375 \textbf{Y}l\textbf{O}r\textbf{B}r
376 \end{center}
377
378 \begin{center}
379 \drawSchemeC[0.9\textwidth]{T-S-IR}\\
380 \textbf{Ir}idescent
381 \end{center}
382
383 \begin{center}
384 \scalebox{0.7}{\drawScheme{T-S-IN}}\\
385 \drawSchemeC[0.6\textwidth]{T-S-IN}\\
386 \textbf{In}candescent\\
387 not print-friendly
388 \end{center}
389
390 \begin{center}
391 \scalebox{0.7}{\drawScheme{T-S-DR}}\\
392 \textbf{D}iscrete \textbf{R}ainbow\\
393 Do not interpolate!
394 \end{center}
395
396 \begin{center}
397 \drawSchemeC[\textwidth]{T-S-SR}\\
398 \textbf{S}mooth \textbf{R}ainbow\\
399 \end{center}\clearpage
400
401 \subsection{Okabe Ito qualitative color scheme}\label{sec:OkabeIto}
402 This is the qualitative color scheme commonly known as the \emph{Okabe Ito} color palette~\cite{Okabe_2002}.
403
404 \begin{center}
405 \scalebox{0.7}{\drawScheme{OI}}\\
406 \textbf{O}kabe \textbf{I}to
407 \end{center}
408
409 \section{Notes on color models}
410 To digitally represent a color, we need to choose a color model, e.g.\ \texttt{rgb} or \texttt{cmyk}.
411 The colors provided by this package were originally defined in RGB-based color models like \texttt{rgb} or \texttt{html}.
412 Therefore, \texttt{RGB} definitions are used when no color model is specified explicitly.
413 In the vast majority of use cases, no such color model should be specified.
414 The reason for this is that modern devices like printers and screens have their own built-in conversion tables between color models, which provide better conversion than some generic formula can.
415 For example when sending a document to a printer, all colors (even colors already specified in \texttt{cymk}) are converted to this device's specific \texttt{cmyk} color model and ink is put on the paper according to these device-specific numbers.
416 Manually converting \texttt{rgb} to \texttt{cmyk} beforehand is therefore not beneficial, as a conversion always has to be performed anyways.
417
418 Due to technical reasons in very rare use-cases, definitions in \texttt{cmyk} are necessary and are also provided.
419 It is strongly discouraged that you use the \texttt{cmyk} color model, unless you have a very good reason why you need it.
420 The only good reason I came across so far is that you send your document to someone else for printing and that person refuses to print your document unless you specify your colors in the \texttt{cmyk} color model\footnote{This may sound unreasonable, but precisely this happened with the printing house of a very well-known \LaTeX\ book.}.
421 In particular and as mentioned above, \texttt{cmyk} should not be used just because you want to print a document.
422 Let the printer handle conversion in that case.
423
424 \section{Provided commands}
425 \marg{\cs{drawScheme\{...\}}}%
426 The discrete visualizations of color schemes given in this documentation are created with the command \cs{drawScheme\{...\}}.
427 The name of the color scheme should be provided to the command, e.g.\ \cs{drawScheme\{T-Q-B\}} to print the \emph{qualitative bright} scheme by Tol.
428 Note that this command is not available when the package option \texttt{no-tikz} is used.
429
430 \marg{\cs{drawSchemeC\{...\}}}%
431 The continuous visualizations of color schemes given in this documentation are created with the command \cs{drawSchemeC\{...\}}.
432 The name of the color scheme should be provided to the command, e.g.\ \cs{drawSchemeC\{T-D-S\}} to print the \emph{diverging sunset} scheme by Tol.
433 Note that this command only works for color schemes that are allowed to be interpolated, and that the command is only available when the package option \texttt{pgf} is used.
434
435 \clearpage
436 \printbibliography
437
438 \end{document}