I came across this awesome gist explaining how to syntax highlight code in Keynote. The same trick works for Powerpoint. Mac only.
- Install homebrew if you don’t have it already and
brew install highlight
. highlight -O rtf myfile.ext | pbcopy
to highlight code to a formatted text converter in RTF output format, and copy the result to the system clipboard.- Paste into Keynote or Powerpoint.
If I’ve got some code in a file called
eset_pca.R
:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Performs principal components analysis on an ExpressionSet | |
eset_pca <- function (eset) { | |
mypca <- prcomp(t(na.omit(exprs(eset)))) | |
pca <- as.data.frame(mypca$x) | |
pc1var <- round(summary(mypca)$importance[2,1]*100, digits<-1) | |
pc2var <- round(summary(mypca)$importance[2,2]*100, digits<-1) | |
pc1lab <- paste0("PC1 (",as.character(pc1var),"%)") | |
pc2lab <- paste0("PC1 (",as.character(pc2var),"%)") | |
out <- merge(pData(eset), pca, by<-"row.names") %>% | |
dplyr::rename(id<-Row.names) | |
attr(out, "pc1lab") <- pc1lab | |
attr(out, "pc2lab") <- pc2lab | |
out | |
} |
I can simply
highlight -O rtf eset_pca.R | pbcopy
and then paste it right into Keynote or Powerpoint.