The Colors of xcolor

Using the tidyverse to gather the colors defined in the LaTeX package xcolor
R
Scripts
Color
Author

Garrick Aden-Buie

Published

August 7, 2019

Keywords

rstats

Today I’m working on the final touches of a Shiny app called ShinyDAG. The goal of the app is to help users create DAGs for causal inference with a drag-and-drop interface. Way down deep underneath the hood, the DAG is rendered using TikZ and LaTeX (via the texPreview package), and the app allows the user to tweak the appearance of the DAG without having to learn TikZ.

One of the appearance changes that the user can make is to change the color of the graph’s edges or nodes, using the colors defined in the xcolor LaTeX package. Rather than provide an open-ended text box, I wanted to give the user a dropdown menu containing the available colors.

It turned out to be just a few lines of code to grab the .def files from the xcolor package page, strip out the non-color related TeX lines, and create a simple tibble of the provided colors.

Quick sidenote: the .def files are actually .def.gz (or gzipped files), but we can read these directly into R using url() inside gzcon(), which is then passed to readLines() to read the uncompressed text. I wrapped this up into a simple helper function, read_gz().

read_gz <- function(x) readLines(gzcon(url(x)))

Now we can grab those files and extract the color definitions.

library(dplyr)
library(purrr)
library(readr)
library(stringr)

read_gz <- function(x) readLines(gzcon(url(x)))

xcolor <-
  list(
    svg = "http://www.ukern.de/tex/xcolor/tex/svgnam.def.gz",
    x11 = "http://www.ukern.de/tex/xcolor/tex/x11nam.def.gz"
  ) %>%
  map(read_gz) %>%
  flatten_chr() %>%
  str_subset("^(%%|\\\\| )", negate = TRUE) %>%
  str_remove("(;%|\\})$") %>%
  paste(collapse = "\n") %>%
  read_csv(col_names = c("color", "r", "g", "b")) %>%
  arrange(color)

head(xcolor)
# A tibble: 6 × 4
  color             r     g     b
  <chr>         <dbl> <dbl> <dbl>
1 AliceBlue     0.94  0.972 1    
2 AntiqueWhite  0.98  0.92  0.844
3 AntiqueWhite1 1     0.936 0.86 
4 AntiqueWhite2 0.932 0.875 0.8  
5 AntiqueWhite3 0.804 0.752 0.69 
6 AntiqueWhite4 0.545 0.512 0.47 

A Shiny fixed-color picker

I haven’t finished incorporating this into the app yet, but this is the how the color selector will look when I do.

All of the xcolor colors

Here are all of the 468 colors in the xcolor package. (And man, it’s hard to sort colors.) If you’re interested, you can download the final list as a csv file.

Maroon
Brown4
DarkRed
Firebrick4
IndianRed4
Red4
Brown
FireBrick
Brown3
Firebrick3
IndianRed
IndianRed3
Red3
Brown2
Firebrick2
IndianRed2
Red2
Brown1
Firebrick1
IndianRed1
Red
Red1
Salmon
Tomato3
Tomato2
Tomato4
Tomato
Tomato1
Coral3
Coral4
Coral2
Coral1
Salmon2
Salmon4
Salmon3
Salmon1
OrangeRed4
OrangeRed3
OrangeRed2
OrangeRed
OrangeRed1
Coral
LightSalmon4
Sienna3
Sienna
Sienna1
Sienna2
Sienna4
Chocolate4
SaddleBrown
Chocolate
Chocolate3
Chocolate1
Chocolate2
SandyBrown
Tan4
Peru
Tan3
Tan1
Tan2
DarkOrange4
DarkOrange3
DarkOrange2
DarkOrange1
DarkOrange
Orange4
Orange3
Orange
Orange1
Orange2
DarkGoldenrod1
Goldenrod4
DarkGoldenrod3
DarkGoldenrod4
DarkGoldenrod
DarkGoldenrod2
Goldenrod1
Goldenrod2
Goldenrod
Goldenrod3
Gold
Gold1
Gold4
Gold3
Gold2
Olive
Yellow4
Yellow3
Yellow2
Yellow
Yellow1
OliveDrab
OliveDrab4
OliveDrab1
OliveDrab3
YellowGreen
OliveDrab2
DarkOliveGreen1
DarkOliveGreen3
DarkOliveGreen2
DarkOliveGreen
DarkOliveGreen4
GreenYellow
Chartreuse
Chartreuse1
Chartreuse2
Chartreuse3
Chartreuse4
LawnGreen
DarkGreen
Green
ForestGreen
Green4
Green3
LimeGreen
Green2
Green0
Green1
Lime
SeaGreen3
SeaGreen
SeaGreen4
SeaGreen2
SeaGreen1
MediumSeaGreen
SpringGreen4
SpringGreen3
SpringGreen2
SpringGreen
SpringGreen1
MediumSpringGreen
Turquoise
LightSeaGreen
MediumTurquoise
Teal
Cyan4
DarkCyan
Cyan3
Cyan2
Aqua
Cyan
Cyan1
DarkTurquoise
Turquoise2
Turquoise4
Turquoise3
Turquoise1
DeepSkyBlue3
DeepSkyBlue
DeepSkyBlue1
DeepSkyBlue2
DeepSkyBlue4
SteelBlue2
SteelBlue3
SteelBlue
SteelBlue4
SteelBlue1
DodgerBlue3
DodgerBlue
DodgerBlue1
DodgerBlue2
DodgerBlue4
CornflowerBlue
RoyalBlue1
RoyalBlue3
RoyalBlue4
RoyalBlue2
RoyalBlue
MidnightBlue
Navy
NavyBlue
Blue4
DarkBlue
Blue3
MediumBlue
Blue2
Blue
Blue1
SlateBlue3
SlateBlue1
LightSlateBlue
SlateBlue
SlateBlue2
DarkSlateBlue
MediumSlateBlue
SlateBlue4
BlueViolet
Purple1
Purple3
Purple4
Purple2
Indigo
Purple0
DarkOrchid2
DarkOrchid4
DarkOrchid
DarkOrchid1
DarkOrchid3
DarkViolet
MediumOrchid3
MediumOrchid2
MediumOrchid1
MediumOrchid
MediumOrchid4
Purple
DarkMagenta
Magenta4
Magenta3
Magenta2
Fuchsia
Magenta
Magenta1
VioletRed
Maroon4
Maroon3
Maroon2
MediumVioletRed
Maroon1
DeepPink2
DeepPink3
DeepPink
DeepPink1
DeepPink4
HotPink
HotPink4
HotPink1
HotPink2
VioletRed1
VioletRed2
VioletRed4
VioletRed3
HotPink3
Maroon0
Crimson
Black
DimGray
DimGrey
Gray
Grey
RosyBrown4
Snow4
DarkGray
DarkGrey
RosyBrown
Gray0
Grey0
Silver
RosyBrown3
Snow3
LightGray
LightGrey
Gainsboro
RosyBrown2
Snow2
LightCoral
WhiteSmoke
RosyBrown1
Snow
Snow1
White
MistyRose3
MistyRose
MistyRose1
MistyRose4
MistyRose2
DarkSalmon
LightSalmon2
LightSalmon
LightSalmon1
LightSalmon3
Seashell3
Seashell
Seashell1
Seashell4
Seashell2
PeachPuff2
PeachPuff3
PeachPuff
PeachPuff1
PeachPuff4
Linen
Bisque3
Bisque
Bisque1
AntiqueWhite1
AntiqueWhite3
Bisque2
Burlywood4
Burlywood2
BurlyWood
AntiqueWhite
Bisque4
AntiqueWhite4
Burlywood1
Tan
Burlywood3
AntiqueWhite2
BlanchedAlmond
NavajoWhite
NavajoWhite1
NavajoWhite2
NavajoWhite3
NavajoWhite4
PapayaWhip
Moccasin
Wheat1
Wheat4
OldLace
Wheat
Wheat3
Wheat2
FloralWhite
Cornsilk
Cornsilk1
Cornsilk4
Cornsilk3
Cornsilk2
LightGoldenrod1
LightGoldenrod3
LightGoldenrod4
LightGoldenrod2
LightGoldenrod
LemonChiffon2
Khaki
LemonChiffon
LemonChiffon1
LemonChiffon3
LemonChiffon4
Khaki4
PaleGoldenrod
Khaki1
Khaki3
Khaki2
DarkKhaki
Ivory4
LightYellow4
Ivory3
LightYellow3
Ivory2
LightYellow2
Beige
LightGoldenrodYellow
Ivory
Ivory1
LightYellow
LightYellow1
DarkSeaGreen4
Honeydew4
PaleGreen4
DarkSeaGreen
DarkSeaGreen3
Honeydew3
PaleGreen3
DarkSeaGreen2
Honeydew2
LightGreen
PaleGreen2
PaleGreen
DarkSeaGreen1
Honeydew
Honeydew1
PaleGreen1
MintCream
Aquamarine
Aquamarine1
Aquamarine3
MediumAquamarine
Aquamarine2
Aquamarine4
DarkSlateGray
DarkSlateGrey
Azure4
DarkSlateGray4
LightCyan4
PaleTurquoise4
Azure3
DarkSlateGray3
LightCyan3
PaleTurquoise3
Azure2
DarkSlateGray2
LightCyan2
PaleTurquoise
PaleTurquoise2
Azure
Azure1
DarkSlateGray1
LightCyan
LightCyan1
PaleTurquoise1
CadetBlue
CadetBlue2
CadetBlue4
PowderBlue
CadetBlue3
CadetBlue1
LightBlue
LightBlue4
LightBlue2
LightBlue1
LightBlue3
SkyBlue
LightSkyBlue4
LightSkyBlue2
LightSkyBlue1
LightSkyBlue3
LightSkyBlue
SkyBlue3
SkyBlue1
SkyBlue2
SkyBlue4
AliceBlue
SlateGray1
SlateGray2
SlateGray4
SlateGray3
LightSlateGray
LightSlateGrey
SlateGray
SlateGrey
LightSteelBlue4
LightSteelBlue2
LightSteelBlue
LightSteelBlue3
LightSteelBlue1
Lavender
GhostWhite
MediumPurple4
MediumPurple3
MediumPurple
MediumPurple2
MediumPurple1
Plum4
Thistle4
Plum3
Thistle3
Thistle
Plum
Plum2
Thistle2
Violet
Plum1
Thistle1
Orchid4
Orchid3
Orchid
Orchid1
Orchid2
LavenderBlush4
LavenderBlush2
LavenderBlush3
LavenderBlush
LavenderBlush1
PaleVioletRed1
PaleVioletRed2
PaleVioletRed
PaleVioletRed3
PaleVioletRed4
Pink4
Pink1
Pink3
Pink2
Pink
LightPink
LightPink2
LightPink4
LightPink3
LightPink1