R/colour.R

Defines functions xcolorPackage xcolorSpecial

Documented in xcolorPackage

xcolorPreamble <- "\\usepackage{xcolor}"

xcolorSpecial <- function(specialString, state) {
    ## Ignore any other specials
    if (grepl("^color push ", specialString)) {
        token <- strsplit(specialString, " ")[[1]]
        colourspace <- token[3]
        if (colourspace == "gray") {
            colourspec <- as.numeric(token[4])
            colour <- gray(colourspec)
        } else if (colourspace == "rgb") {
            colourspec <- as.numeric(token[4:6])
            colour <- rgb(colourspec[1], colourspec[2], colourspec[3])
        } else {
            warning("Unsupported colourspace - colour not set")
            colour <- NA
        }            
        TeXset("colour", c(colour, TeXget("colour", state)), state)
    }
    if (grepl("^color pop", specialString)) {
        TeXset("colour", TeXget("colour", state)[-1], state)
    }
}

xcolorPackage <- function() {
    LaTeXpackage(name="xcolor",
                 preamble=xcolorPreamble,
                 special=xcolorSpecial)
}

Try the xdvir package in your browser

Any scripts or data that you put into this service are public.

xdvir documentation built on Aug. 8, 2025, 7:12 p.m.