R/define_colors.R

Defines functions define_colors define_color

define_color <- function(name, color) {
  rgb <- grDevices::col2rgb(color)[, 1] / 255
  paste0(
    "$$\\require{color}\\definecolor{",
    name,
    "}{rgb}{",
    rgb[1],
    ", ",
    rgb[2],
    ", ",
    rgb[3],
    "}$$"
  )
}

define_colors <- function(colors) {
  c(
    "<div style = \"position:fixed; visibility: hidden\">",
    purrr::imap_chr(colors, ~define_color(.y, .x)),
    "</div>"
  )
}
EmilHvitfeldt/xaringancolor documentation built on June 10, 2025, 5:07 a.m.