Skip to content

Instantly share code, notes, and snippets.

@koncina
Created September 16, 2016 06:35
Show Gist options
  • Save koncina/c205af6bd80d7f59c3557345e8121195 to your computer and use it in GitHub Desktop.
Save koncina/c205af6bd80d7f59c3557345e8121195 to your computer and use it in GitHub Desktop.
Color text for Pdf or Html output
# From http://stackoverflow.com/a/37122306
txtcol <- function(x, color) {
outputFormat = knitr::opts_knit$get("rmarkdown.pandoc.to")
if (outputFormat == 'latex')
paste("\\textcolor{", color, "}{", x, "}", sep = "")
else if (outputFormat == 'html')
paste("<font color='", color, "'>", x, "</font>", sep = "")
else
x
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment